aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/videos.js14
-rw-r--r--server/models/video.js3
-rw-r--r--server/tests/api/multiple-pods.js29
-rw-r--r--server/tests/api/single-pod.js19
-rw-r--r--server/tests/real-world/real-world.js2
5 files changed, 55 insertions, 12 deletions
diff --git a/server/controllers/api/videos.js b/server/controllers/api/videos.js
index 55d671f5b..2c4af520e 100644
--- a/server/controllers/api/videos.js
+++ b/server/controllers/api/videos.js
@@ -259,6 +259,7 @@ function updateVideoRetryWrapper (req, res, next) {
259 259
260function updateVideo (req, res, finalCallback) { 260function updateVideo (req, res, finalCallback) {
261 const videoInstance = res.locals.video 261 const videoInstance = res.locals.video
262 const videoFieldsSave = videoInstance.toJSON()
262 const videoInfosToUpdate = req.body 263 const videoInfosToUpdate = req.body
263 264
264 waterfall([ 265 waterfall([
@@ -280,12 +281,13 @@ function updateVideo (req, res, finalCallback) {
280 }, 281 },
281 282
282 function updateVideoIntoDB (t, tagInstances, callback) { 283 function updateVideoIntoDB (t, tagInstances, callback) {
283 const options = { transaction: t } 284 const options = {
285 transaction: t
286 }
284 287
285 if (videoInfosToUpdate.name) videoInstance.set('name', videoInfosToUpdate.name) 288 if (videoInfosToUpdate.name) videoInstance.set('name', videoInfosToUpdate.name)
286 if (videoInfosToUpdate.description) videoInstance.set('description', videoInfosToUpdate.description) 289 if (videoInfosToUpdate.description) videoInstance.set('description', videoInfosToUpdate.description)
287 290
288 // Add tags association
289 videoInstance.save(options).asCallback(function (err) { 291 videoInstance.save(options).asCallback(function (err) {
290 return callback(err, t, tagInstances) 292 return callback(err, t, tagInstances)
291 }) 293 })
@@ -321,6 +323,14 @@ function updateVideo (req, res, finalCallback) {
321 // Abort transaction? 323 // Abort transaction?
322 if (t) t.rollback() 324 if (t) t.rollback()
323 325
326 // Force fields we want to update
327 // If the transaction is retried, sequelize will think the object has not changed
328 // So it will skip the SQL request, even if the last one was ROLLBACKed!
329 Object.keys(videoFieldsSave).forEach(function (key) {
330 const value = videoFieldsSave[key]
331 videoInstance.set(key, value)
332 })
333
324 return finalCallback(err) 334 return finalCallback(err)
325 } 335 }
326 336
diff --git a/server/models/video.js b/server/models/video.js
index b3060705d..ceed976b0 100644
--- a/server/models/video.js
+++ b/server/models/video.js
@@ -141,7 +141,8 @@ module.exports = function (sequelize, DataTypes) {
141} 141}
142 142
143function beforeValidate (video, options, next) { 143function beforeValidate (video, options, next) {
144 if (video.isOwned()) { 144 // Put a fake infoHash if it does not exists yet
145 if (video.isOwned() && !video.infoHash) {
145 // 40 hexa length 146 // 40 hexa length
146 video.infoHash = '0123456789abcdef0123456789abcdef01234567' 147 video.infoHash = '0123456789abcdef0123456789abcdef01234567'
147 } 148 }
diff --git a/server/tests/api/multiple-pods.js b/server/tests/api/multiple-pods.js
index 4442a7ff7..169a9f2e0 100644
--- a/server/tests/api/multiple-pods.js
+++ b/server/tests/api/multiple-pods.js
@@ -4,7 +4,8 @@ const chai = require('chai')
4const each = require('async/each') 4const each = require('async/each')
5const expect = chai.expect 5const expect = chai.expect
6const series = require('async/series') 6const series = require('async/series')
7const webtorrent = new (require('webtorrent'))() 7const WebTorrent = require('webtorrent')
8const webtorrent = new WebTorrent()
8 9
9const loginUtils = require('../utils/login') 10const loginUtils = require('../utils/login')
10const miscsUtils = require('../utils/miscs') 11const miscsUtils = require('../utils/miscs')
@@ -311,7 +312,7 @@ describe('Test multiple pods', function () {
311 expect(torrent.files.length).to.equal(1) 312 expect(torrent.files.length).to.equal(1)
312 expect(torrent.files[0].path).to.exist.and.to.not.equal('') 313 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
313 314
314 done() 315 webtorrent.remove(video.magnetUri, done)
315 }) 316 })
316 }) 317 })
317 }) 318 })
@@ -330,7 +331,7 @@ describe('Test multiple pods', function () {
330 expect(torrent.files.length).to.equal(1) 331 expect(torrent.files.length).to.equal(1)
331 expect(torrent.files[0].path).to.exist.and.to.not.equal('') 332 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
332 333
333 done() 334 webtorrent.remove(video.magnetUri, done)
334 }) 335 })
335 }) 336 })
336 }) 337 })
@@ -349,7 +350,7 @@ describe('Test multiple pods', function () {
349 expect(torrent.files.length).to.equal(1) 350 expect(torrent.files.length).to.equal(1)
350 expect(torrent.files[0].path).to.exist.and.to.not.equal('') 351 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
351 352
352 done() 353 webtorrent.remove(video.magnetUri, done)
353 }) 354 })
354 }) 355 })
355 }) 356 })
@@ -368,7 +369,7 @@ describe('Test multiple pods', function () {
368 expect(torrent.files.length).to.equal(1) 369 expect(torrent.files.length).to.equal(1)
369 expect(torrent.files[0].path).to.exist.and.to.not.equal('') 370 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
370 371
371 done() 372 webtorrent.remove(video.magnetUri, done)
372 }) 373 })
373 }) 374 })
374 }) 375 })
@@ -390,7 +391,12 @@ describe('Test multiple pods', function () {
390 }) 391 })
391 392
392 it('Should have the video 3 updated on each pod', function (done) { 393 it('Should have the video 3 updated on each pod', function (done) {
394 this.timeout(200000)
395
393 each(servers, function (server, callback) { 396 each(servers, function (server, callback) {
397 // Avoid "duplicate torrent" errors
398 const webtorrent = new WebTorrent()
399
394 videosUtils.getVideosList(server.url, function (err, res) { 400 videosUtils.getVideosList(server.url, function (err, res) {
395 if (err) throw err 401 if (err) throw err
396 402
@@ -404,7 +410,18 @@ describe('Test multiple pods', function () {
404 expect(videoUpdated.tags).to.deep.equal([ 'tagup1', 'tagup2' ]) 410 expect(videoUpdated.tags).to.deep.equal([ 'tagup1', 'tagup2' ])
405 expect(miscsUtils.dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true 411 expect(miscsUtils.dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true
406 412
407 callback() 413 videosUtils.testVideoImage(server.url, 'video_short3.webm', videoUpdated.thumbnailPath, function (err, test) {
414 if (err) throw err
415 expect(test).to.equal(true)
416
417 webtorrent.add(videoUpdated.magnetUri, function (torrent) {
418 expect(torrent.files).to.exist
419 expect(torrent.files.length).to.equal(1)
420 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
421
422 webtorrent.remove(videoUpdated.magnetUri, callback)
423 })
424 })
408 }) 425 })
409 }, done) 426 }, done)
410 }) 427 })
diff --git a/server/tests/api/single-pod.js b/server/tests/api/single-pod.js
index 29512dfc6..04b93fac7 100644
--- a/server/tests/api/single-pod.js
+++ b/server/tests/api/single-pod.js
@@ -96,7 +96,7 @@ describe('Test a single pod', function () {
96 expect(torrent.files.length).to.equal(1) 96 expect(torrent.files.length).to.equal(1)
97 expect(torrent.files[0].path).to.exist.and.to.not.equal('') 97 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
98 98
99 done() 99 webtorrent.remove(video.magnetUri, done)
100 }) 100 })
101 }) 101 })
102 }) 102 })
@@ -515,6 +515,8 @@ describe('Test a single pod', function () {
515 }) 515 })
516 516
517 it('Should have the video updated', function (done) { 517 it('Should have the video updated', function (done) {
518 this.timeout(60000)
519
518 videosUtils.getVideo(server.url, videoId, function (err, res) { 520 videosUtils.getVideo(server.url, videoId, function (err, res) {
519 if (err) throw err 521 if (err) throw err
520 522
@@ -529,7 +531,20 @@ describe('Test a single pod', function () {
529 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true 531 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
530 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true 532 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
531 533
532 done() 534 videosUtils.testVideoImage(server.url, 'video_short3.webm', video.thumbnailPath, function (err, test) {
535 if (err) throw err
536 expect(test).to.equal(true)
537
538 videoId = video.id
539
540 webtorrent.add(video.magnetUri, function (torrent) {
541 expect(torrent.files).to.exist
542 expect(torrent.files.length).to.equal(1)
543 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
544
545 done()
546 })
547 })
533 }) 548 })
534 }) 549 })
535 550
diff --git a/server/tests/real-world/real-world.js b/server/tests/real-world/real-world.js
index 896ba6cce..941e43a2e 100644
--- a/server/tests/real-world/real-world.js
+++ b/server/tests/real-world/real-world.js
@@ -38,7 +38,7 @@ const numberOfPods = 6
38// Wait requests between pods 38// Wait requests between pods
39const baseRequestInterval = integrityInterval < constants.REQUESTS_INTERVAL ? integrityInterval : constants.REQUESTS_INTERVAL 39const baseRequestInterval = integrityInterval < constants.REQUESTS_INTERVAL ? integrityInterval : constants.REQUESTS_INTERVAL
40const requestsMaxPerInterval = baseRequestInterval / actionInterval 40const requestsMaxPerInterval = baseRequestInterval / actionInterval
41const intervalsToMakeAllRequests = Math.ceil(requestsMaxPerInterval / (constants.REQUESTS_LIMIT_PER_POD * numberOfPods)) 41const intervalsToMakeAllRequests = Math.ceil(requestsMaxPerInterval / constants.REQUESTS_LIMIT_PER_POD)
42const waitForBeforeIntegrityCheck = (intervalsToMakeAllRequests * constants.REQUESTS_INTERVAL) + 1000 42const waitForBeforeIntegrityCheck = (intervalsToMakeAllRequests * constants.REQUESTS_INTERVAL) + 1000
43 43
44console.log('Create weight: %d, update weight: %d, remove weight: %d.', createWeight, updateWeight, removeWeight) 44console.log('Create weight: %d, update weight: %d, remove weight: %d.', createWeight, updateWeight, removeWeight)