function updateVideo (req, res, finalCallback) {
const videoInstance = res.locals.video
+ const videoFieldsSave = videoInstance.toJSON()
const videoInfosToUpdate = req.body
waterfall([
},
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)
})
// 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)
}
}
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'
}
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')
expect(torrent.files.length).to.equal(1)
expect(torrent.files[0].path).to.exist.and.to.not.equal('')
- done()
+ webtorrent.remove(video.magnetUri, done)
})
})
})
expect(torrent.files.length).to.equal(1)
expect(torrent.files[0].path).to.exist.and.to.not.equal('')
- done()
+ webtorrent.remove(video.magnetUri, done)
})
})
})
expect(torrent.files.length).to.equal(1)
expect(torrent.files[0].path).to.exist.and.to.not.equal('')
- done()
+ webtorrent.remove(video.magnetUri, done)
})
})
})
expect(torrent.files.length).to.equal(1)
expect(torrent.files[0].path).to.exist.and.to.not.equal('')
- done()
+ webtorrent.remove(video.magnetUri, done)
})
})
})
})
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
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)
})
expect(torrent.files.length).to.equal(1)
expect(torrent.files[0].path).to.exist.and.to.not.equal('')
- done()
+ webtorrent.remove(video.magnetUri, done)
})
})
})
})
it('Should have the video updated', function (done) {
+ this.timeout(60000)
+
videosUtils.getVideo(server.url, videoId, function (err, res) {
if (err) throw err
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()
+ })
+ })
})
})
// 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)