aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/real-world/real-world.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/real-world/real-world.js')
-rw-r--r--server/tests/real-world/real-world.js68
1 files changed, 54 insertions, 14 deletions
diff --git a/server/tests/real-world/real-world.js b/server/tests/real-world/real-world.js
index dba1970c5..12ab06d6d 100644
--- a/server/tests/real-world/real-world.js
+++ b/server/tests/real-world/real-world.js
@@ -2,6 +2,7 @@
2 2
3const each = require('async/each') 3const each = require('async/each')
4const isEqual = require('lodash/isEqual') 4const isEqual = require('lodash/isEqual')
5const differenceWith = require('lodash/differenceWith')
5const program = require('commander') 6const program = require('commander')
6const series = require('async/series') 7const series = require('async/series')
7 8
@@ -16,32 +17,41 @@ const videosUtils = require('../utils/videos')
16program 17program
17 .option('-c, --create [weight]', 'Weight for creating videos') 18 .option('-c, --create [weight]', 'Weight for creating videos')
18 .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')
19 .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)
20 .option('-a, --action [interval]', 'Interval in ms for an action') 22 .option('-a, --action [interval]', 'Interval in ms for an action')
21 .option('-i, --integrity [interval]', 'Interval in ms for an integrity check') 23 .option('-i, --integrity [interval]', 'Interval in ms for an integrity check')
22 .option('-f, --flush', 'Flush datas on exit') 24 .option('-f, --flush', 'Flush datas on exit')
25 .option('-d, --difference', 'Display difference if integrity is not okay')
23 .parse(process.argv) 26 .parse(process.argv)
24 27
25const createWeight = parseInt(program.create) || 5 28const createWeight = program.create !== undefined ? parseInt(program.create) : 5
26const removeWeight = parseInt(program.remove) || 4 29const removeWeight = program.remove !== undefined ? parseInt(program.remove) : 4
30const updateWeight = program.update !== undefined ? parseInt(program.update) : 4
27const flushAtExit = program.flush || false 31const flushAtExit = program.flush || false
28const actionInterval = parseInt(program.action) || 500 32const actionInterval = program.action !== undefined ? parseInt(program.action) : 500
29let integrityInterval = parseInt(program.integrity) || 60000 33const integrityInterval = program.integrity !== undefined ? parseInt(program.integrity) : 60000
34const displayDiffOnFail = program.integrity || false
30 35
31const numberOfPods = 6 36const numberOfPods = 6
32// Wait requests between pods
33const requestsMaxPerInterval = constants.INTERVAL / actionInterval
34const intervalsToMakeAllRequests = Math.ceil(requestsMaxPerInterval / constants.REQUESTS_LIMIT)
35const waitForBeforeIntegrityCheck = (intervalsToMakeAllRequests * constants.INTERVAL) + 1000
36 37
37integrityInterval += waitForBeforeIntegrityCheck 38// Wait requests between pods
39const baseRequestInterval = integrityInterval < constants.REQUESTS_INTERVAL ? constants.REQUESTS_INTERVAL : integrityInterval
40const requestsMaxPerInterval = baseRequestInterval / actionInterval
41const intervalsToMakeAllRequests = Math.ceil(requestsMaxPerInterval / constants.REQUESTS_LIMIT_PER_POD)
42const waitForBeforeIntegrityCheck = (intervalsToMakeAllRequests * constants.REQUESTS_INTERVAL) - integrityInterval + 1000
38 43
39console.log('Create weight: %d, remove weight: %d.', createWeight, removeWeight) 44console.log('Create weight: %d, update weight: %d, remove weight: %d.', createWeight, updateWeight, removeWeight)
40if (flushAtExit) { 45if (flushAtExit) {
41 console.log('Program will flush data on exit.') 46 console.log('Program will flush data on exit.')
42} else { 47} else {
43 console.log('Program will not flush data on exit.') 48 console.log('Program will not flush data on exit.')
44} 49}
50if (displayDiffOnFail) {
51 console.log('Program will display diff on failure.')
52} else {
53 console.log('Program will not display diff on failure')
54}
45console.log('Interval in ms for each action: %d.', actionInterval) 55console.log('Interval in ms for each action: %d.', actionInterval)
46console.log('Interval in ms for each integrity check: %d.', integrityInterval) 56console.log('Interval in ms for each integrity check: %d.', integrityInterval)
47console.log('Will wait %d ms before an integrity check.', waitForBeforeIntegrityCheck) 57console.log('Will wait %d ms before an integrity check.', waitForBeforeIntegrityCheck)
@@ -63,16 +73,20 @@ runServers(numberOfPods, function (err, servers) {
63 setInterval(function () { 73 setInterval(function () {
64 if (checking === true) return 74 if (checking === true) return
65 75
66 const rand = getRandomInt(0, createWeight + removeWeight) 76 const rand = getRandomInt(0, createWeight + updateWeight + removeWeight)
67 77
68 if (rand < createWeight) { 78 if (rand < createWeight) {
69 upload(servers, getRandomNumServer(servers)) 79 upload(servers, getRandomNumServer(servers))
80 } else if (rand < createWeight + updateWeight) {
81 update(servers, getRandomNumServer(servers))
70 } else { 82 } else {
71 remove(servers, getRandomNumServer(servers)) 83 remove(servers, getRandomNumServer(servers))
72 } 84 }
73 }, actionInterval) 85 }, actionInterval)
74 86
75 setInterval(function () { 87 setInterval(function () {
88 if (checking === true) return
89
76 console.log('Checking integrity...') 90 console.log('Checking integrity...')
77 checking = true 91 checking = true
78 92
@@ -160,9 +174,9 @@ function exitServers (servers, callback) {
160function upload (servers, numServer, callback) { 174function upload (servers, numServer, callback) {
161 if (!callback) callback = function () {} 175 if (!callback) callback = function () {}
162 176
163 const name = 'my super name for pod 1' 177 const name = Date.now() + ' name'
164 const description = 'my super description for pod 1' 178 const description = Date.now() + ' description'
165 const tags = [ 'tag1p1', 'tag2p1' ] 179 const tags = [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ]
166 const file = 'video_short1.webm' 180 const file = 'video_short1.webm'
167 181
168 console.log('Upload video to server ' + numServer) 182 console.log('Upload video to server ' + numServer)
@@ -170,6 +184,26 @@ function upload (servers, numServer, callback) {
170 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)
171} 185}
172 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
173function remove (servers, numServer, callback) { 207function remove (servers, numServer, callback) {
174 if (!callback) callback = function () {} 208 if (!callback) callback = function () {}
175 209
@@ -196,6 +230,7 @@ function checkIntegrity (servers, callback) {
196 delete serverVideo.id 230 delete serverVideo.id
197 delete serverVideo.isLocal 231 delete serverVideo.isLocal
198 delete serverVideo.thumbnailPath 232 delete serverVideo.thumbnailPath
233 delete serverVideo.updatedAt
199 } 234 }
200 235
201 videos.push(serverVideos) 236 videos.push(serverVideos)
@@ -205,6 +240,11 @@ function checkIntegrity (servers, callback) {
205 for (const video of videos) { 240 for (const video of videos) {
206 if (!isEqual(video, videos[0])) { 241 if (!isEqual(video, videos[0])) {
207 console.error('Integrity not ok!') 242 console.error('Integrity not ok!')
243
244 if (displayDiffOnFail) {
245 console.log(differenceWith(videos[0], video, isEqual))
246 }
247
208 process.exit(-1) 248 process.exit(-1)
209 } 249 }
210 } 250 }