aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/real-world/real-world.js28
1 files changed, 26 insertions, 2 deletions
diff --git a/server/tests/real-world/real-world.js b/server/tests/real-world/real-world.js
index 9a63860ad..896ba6cce 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')
17program 17program
18 .option('-c, --create [weight]', 'Weight for creating videos') 18 .option('-c, --create [weight]', 'Weight for creating videos')
19 .option('-r, --remove [weight]', 'Weight for removing videos') 19 .option('-r, --remove [weight]', 'Weight for removing videos')
20 .option('-u, --update [weight]', 'Weight for updating videos')
20 .option('-p, --pods [n]', 'Number of pods to run (3 or 6)', /^3|6$/, 3) 21 .option('-p, --pods [n]', 'Number of pods to run (3 or 6)', /^3|6$/, 3)
21 .option('-a, --action [interval]', 'Interval in ms for an action') 22 .option('-a, --action [interval]', 'Interval in ms for an action')
22 .option('-i, --integrity [interval]', 'Interval in ms for an integrity check') 23 .option('-i, --integrity [interval]', 'Interval in ms for an integrity check')
@@ -26,6 +27,7 @@ program
26 27
27const createWeight = program.create !== undefined ? parseInt(program.create) : 5 28const createWeight = program.create !== undefined ? parseInt(program.create) : 5
28const removeWeight = program.remove !== undefined ? parseInt(program.remove) : 4 29const removeWeight = program.remove !== undefined ? parseInt(program.remove) : 4
30const updateWeight = program.update !== undefined ? parseInt(program.update) : 4
29const flushAtExit = program.flush || false 31const flushAtExit = program.flush || false
30const actionInterval = program.action !== undefined ? parseInt(program.action) : 500 32const actionInterval = program.action !== undefined ? parseInt(program.action) : 500
31let integrityInterval = program.integrity !== undefined ? parseInt(program.integrity) : 60000 33let integrityInterval = program.integrity !== undefined ? parseInt(program.integrity) : 60000
@@ -39,7 +41,7 @@ const requestsMaxPerInterval = baseRequestInterval / actionInterval
39const intervalsToMakeAllRequests = Math.ceil(requestsMaxPerInterval / (constants.REQUESTS_LIMIT_PER_POD * numberOfPods)) 41const intervalsToMakeAllRequests = Math.ceil(requestsMaxPerInterval / (constants.REQUESTS_LIMIT_PER_POD * numberOfPods))
40const waitForBeforeIntegrityCheck = (intervalsToMakeAllRequests * constants.REQUESTS_INTERVAL) + 1000 42const waitForBeforeIntegrityCheck = (intervalsToMakeAllRequests * constants.REQUESTS_INTERVAL) + 1000
41 43
42console.log('Create weight: %d, remove weight: %d.', createWeight, removeWeight) 44console.log('Create weight: %d, update weight: %d, remove weight: %d.', createWeight, updateWeight, removeWeight)
43if (flushAtExit) { 45if (flushAtExit) {
44 console.log('Program will flush data on exit.') 46 console.log('Program will flush data on exit.')
45} else { 47} else {
@@ -71,10 +73,12 @@ runServers(numberOfPods, function (err, servers) {
71 setInterval(function () { 73 setInterval(function () {
72 if (checking === true) return 74 if (checking === true) return
73 75
74 const rand = getRandomInt(0, createWeight + removeWeight) 76 const rand = getRandomInt(0, createWeight + updateWeight + removeWeight)
75 77
76 if (rand < createWeight) { 78 if (rand < createWeight) {
77 upload(servers, getRandomNumServer(servers)) 79 upload(servers, getRandomNumServer(servers))
80 } else if (rand < createWeight + updateWeight) {
81 update(servers, getRandomNumServer(servers))
78 } else { 82 } else {
79 remove(servers, getRandomNumServer(servers)) 83 remove(servers, getRandomNumServer(servers))
80 } 84 }
@@ -180,6 +184,26 @@ function upload (servers, numServer, callback) {
180 videosUtils.uploadVideo(servers[numServer].url, servers[numServer].accessToken, name, description, tags, file, callback) 184 videosUtils.uploadVideo(servers[numServer].url, servers[numServer].accessToken, name, description, tags, file, callback)
181} 185}
182 186
187function update (servers, numServer, callback) {
188 if (!callback) callback = function () {}
189
190 videosUtils.getVideosList(servers[numServer].url, function (err, res) {
191 if (err) throw err
192
193 const videos = res.body.data.filter(function (video) { return video.isLocal })
194 if (videos.length === 0) return callback()
195
196 const toUpdate = videos[getRandomInt(0, videos.length)].id
197 const name = Date.now() + ' name'
198 const description = Date.now() + ' description'
199 const tags = [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ]
200
201 console.log('Updating video of server ' + numServer)
202
203 videosUtils.updateVideo(servers[numServer].url, servers[numServer].accessToken, toUpdate, name, description, tags, callback)
204 })
205}
206
183function remove (servers, numServer, callback) { 207function remove (servers, numServer, callback) {
184 if (!callback) callback = function () {} 208 if (!callback) callback = function () {}
185 209