From: Chocobozzz Date: Thu, 12 Jan 2017 08:47:21 +0000 (+0100) Subject: Server: fix update remote video infohash X-Git-Tag: v0.0.1-alpha~574^2~2 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=7f4e7c36373217b8e92cf227c71999a0ce9a15d9;p=oweals%2Fpeertube.git Server: fix update remote video infohash --- 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) { function updateVideo (req, res, finalCallback) { const videoInstance = res.locals.video + const videoFieldsSave = videoInstance.toJSON() const videoInfosToUpdate = req.body waterfall([ @@ -280,12 +281,13 @@ function updateVideo (req, res, finalCallback) { }, function updateVideoIntoDB (t, tagInstances, callback) { - const options = { transaction: t } + const options = { + transaction: t + } if (videoInfosToUpdate.name) videoInstance.set('name', videoInfosToUpdate.name) if (videoInfosToUpdate.description) videoInstance.set('description', videoInfosToUpdate.description) - // Add tags association videoInstance.save(options).asCallback(function (err) { return callback(err, t, tagInstances) }) @@ -321,6 +323,14 @@ function updateVideo (req, res, finalCallback) { // Abort transaction? if (t) t.rollback() + // Force fields we want to update + // If the transaction is retried, sequelize will think the object has not changed + // So it will skip the SQL request, even if the last one was ROLLBACKed! + Object.keys(videoFieldsSave).forEach(function (key) { + const value = videoFieldsSave[key] + videoInstance.set(key, value) + }) + return finalCallback(err) } 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) { } function beforeValidate (video, options, next) { - if (video.isOwned()) { + // Put a fake infoHash if it does not exists yet + if (video.isOwned() && !video.infoHash) { // 40 hexa length video.infoHash = '0123456789abcdef0123456789abcdef01234567' } 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') const each = require('async/each') const expect = chai.expect const series = require('async/series') -const webtorrent = new (require('webtorrent'))() +const WebTorrent = require('webtorrent') +const webtorrent = new WebTorrent() const loginUtils = require('../utils/login') const miscsUtils = require('../utils/miscs') @@ -311,7 +312,7 @@ describe('Test multiple pods', function () { expect(torrent.files.length).to.equal(1) expect(torrent.files[0].path).to.exist.and.to.not.equal('') - done() + webtorrent.remove(video.magnetUri, done) }) }) }) @@ -330,7 +331,7 @@ describe('Test multiple pods', function () { expect(torrent.files.length).to.equal(1) expect(torrent.files[0].path).to.exist.and.to.not.equal('') - done() + webtorrent.remove(video.magnetUri, done) }) }) }) @@ -349,7 +350,7 @@ describe('Test multiple pods', function () { expect(torrent.files.length).to.equal(1) expect(torrent.files[0].path).to.exist.and.to.not.equal('') - done() + webtorrent.remove(video.magnetUri, done) }) }) }) @@ -368,7 +369,7 @@ describe('Test multiple pods', function () { expect(torrent.files.length).to.equal(1) expect(torrent.files[0].path).to.exist.and.to.not.equal('') - done() + webtorrent.remove(video.magnetUri, done) }) }) }) @@ -390,7 +391,12 @@ describe('Test multiple pods', function () { }) it('Should have the video 3 updated on each pod', function (done) { + this.timeout(200000) + each(servers, function (server, callback) { + // Avoid "duplicate torrent" errors + const webtorrent = new WebTorrent() + videosUtils.getVideosList(server.url, function (err, res) { if (err) throw err @@ -404,7 +410,18 @@ describe('Test multiple pods', function () { expect(videoUpdated.tags).to.deep.equal([ 'tagup1', 'tagup2' ]) expect(miscsUtils.dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true - callback() + videosUtils.testVideoImage(server.url, 'video_short3.webm', videoUpdated.thumbnailPath, function (err, test) { + if (err) throw err + expect(test).to.equal(true) + + webtorrent.add(videoUpdated.magnetUri, function (torrent) { + expect(torrent.files).to.exist + expect(torrent.files.length).to.equal(1) + expect(torrent.files[0].path).to.exist.and.to.not.equal('') + + webtorrent.remove(videoUpdated.magnetUri, callback) + }) + }) }) }, done) }) 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 () { expect(torrent.files.length).to.equal(1) expect(torrent.files[0].path).to.exist.and.to.not.equal('') - done() + webtorrent.remove(video.magnetUri, done) }) }) }) @@ -515,6 +515,8 @@ describe('Test a single pod', function () { }) it('Should have the video updated', function (done) { + this.timeout(60000) + videosUtils.getVideo(server.url, videoId, function (err, res) { if (err) throw err @@ -529,7 +531,20 @@ describe('Test a single pod', function () { expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true - done() + videosUtils.testVideoImage(server.url, 'video_short3.webm', video.thumbnailPath, function (err, test) { + if (err) throw err + expect(test).to.equal(true) + + videoId = video.id + + webtorrent.add(video.magnetUri, function (torrent) { + expect(torrent.files).to.exist + expect(torrent.files.length).to.equal(1) + expect(torrent.files[0].path).to.exist.and.to.not.equal('') + + done() + }) + }) }) }) 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 // Wait requests between pods const baseRequestInterval = integrityInterval < constants.REQUESTS_INTERVAL ? integrityInterval : constants.REQUESTS_INTERVAL const requestsMaxPerInterval = baseRequestInterval / actionInterval -const intervalsToMakeAllRequests = Math.ceil(requestsMaxPerInterval / (constants.REQUESTS_LIMIT_PER_POD * numberOfPods)) +const intervalsToMakeAllRequests = Math.ceil(requestsMaxPerInterval / constants.REQUESTS_LIMIT_PER_POD) const waitForBeforeIntegrityCheck = (intervalsToMakeAllRequests * constants.REQUESTS_INTERVAL) + 1000 console.log('Create weight: %d, update weight: %d, remove weight: %d.', createWeight, updateWeight, removeWeight)