ActivityPub-federated video streaming platform using P2P directly in your web browser
Server: add update case to real world script
Chocobozzzf2cdb86675c3
diff --git a/server/tests/real-world/real-world.js b/server/tests/real-world/real-world.jsindex 9a63860adc..896ba6cce4 100644--- a/server/tests/real-world/real-world.js+++ b/server/tests/real-world/real-world.js@@ -17,6 +17,7 @@ const videosUtils = require('../utils/videos')program.option('-c, --create [weight]', 'Weight for creating videos').option('-r, --remove [weight]', 'Weight for removing videos')+ .option('-u, --update [weight]', 'Weight for updating videos').option('-p, --pods [n]', 'Number of pods to run (3 or 6)', /^3|6$/, 3).option('-a, --action [interval]', 'Interval in ms for an action').option('-i, --integrity [interval]', 'Interval in ms for an integrity check')@@ -26,6 +27,7 @@ programconst createWeight = program.create !== undefined ? parseInt(program.create) : 5const removeWeight = program.remove !== undefined ? parseInt(program.remove) : 4+const updateWeight = program.update !== undefined ? parseInt(program.update) : 4const flushAtExit = program.flush || falseconst actionInterval = program.action !== undefined ? parseInt(program.action) : 500let integrityInterval = program.integrity !== undefined ? parseInt(program.integrity) : 60000@@ -39,7 +41,7 @@ const requestsMaxPerInterval = baseRequestInterval / actionIntervalconst intervalsToMakeAllRequests = Math.ceil(requestsMaxPerInterval / (constants.REQUESTS_LIMIT_PER_POD * numberOfPods))const waitForBeforeIntegrityCheck = (intervalsToMakeAllRequests * constants.REQUESTS_INTERVAL) + 1000-console.log('Create weight: %d, remove weight: %d.', createWeight, removeWeight)+console.log('Create weight: %d, update weight: %d, remove weight: %d.', createWeight, updateWeight, removeWeight)if (flushAtExit) {console.log('Program will flush data on exit.')} else {@@ -71,10 +73,12 @@ runServers(numberOfPods, function (err, servers) {setInterval(function () {if (checking === true) return- const rand = getRandomInt(0, createWeight + removeWeight)+ const rand = getRandomInt(0, createWeight + updateWeight + removeWeight)if (rand < createWeight) {upload(servers, getRandomNumServer(servers))+ } else if (rand < createWeight + updateWeight) {+ update(servers, getRandomNumServer(servers))} else {remove(servers, getRandomNumServer(servers))}@@ -180,6 +184,26 @@ function upload (servers, numServer, callback) {videosUtils.uploadVideo(servers[numServer].url, servers[numServer].accessToken, name, description, tags, file, callback)}+function update (servers, numServer, callback) {+ if (!callback) callback = function () {}++ videosUtils.getVideosList(servers[numServer].url, function (err, res) {+ if (err) throw err++ const videos = res.body.data.filter(function (video) { return video.isLocal })+ if (videos.length === 0) return callback()++ const toUpdate = videos[getRandomInt(0, videos.length)].id+ const name = Date.now() + ' name'+ const description = Date.now() + ' description'+ const tags = [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ]++ console.log('Updating video of server ' + numServer)++ videosUtils.updateVideo(servers[numServer].url, servers[numServer].accessToken, toUpdate, name, description, tags, callback)+ })+}+function remove (servers, numServer, callback) {if (!callback) callback = function () {}