diff options
-rw-r--r-- | server/tests/real-world/real-world.js | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/server/tests/real-world/real-world.js b/server/tests/real-world/real-world.js index 2ae3dc15b..751d3923f 100644 --- a/server/tests/real-world/real-world.js +++ b/server/tests/real-world/real-world.js | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | const each = require('async/each') | 3 | const each = require('async/each') |
4 | const isEqual = require('lodash/isEqual') | 4 | const isEqual = require('lodash/isEqual') |
5 | const differenceWith = require('lodash/differenceWith') | ||
5 | const program = require('commander') | 6 | const program = require('commander') |
6 | const series = require('async/series') | 7 | const series = require('async/series') |
7 | 8 | ||
@@ -20,28 +21,35 @@ program | |||
20 | .option('-a, --action [interval]', 'Interval in ms for an action') | 21 | .option('-a, --action [interval]', 'Interval in ms for an action') |
21 | .option('-i, --integrity [interval]', 'Interval in ms for an integrity check') | 22 | .option('-i, --integrity [interval]', 'Interval in ms for an integrity check') |
22 | .option('-f, --flush', 'Flush datas on exit') | 23 | .option('-f, --flush', 'Flush datas on exit') |
24 | .option('-d, --difference', 'Display difference if integrity is not okay') | ||
23 | .parse(process.argv) | 25 | .parse(process.argv) |
24 | 26 | ||
25 | const createWeight = parseInt(program.create) || 5 | 27 | const createWeight = program.create !== undefined ? parseInt(program.create) : 5 |
26 | const removeWeight = parseInt(program.remove) || 4 | 28 | const removeWeight = program.remove !== undefined ? parseInt(program.remove) : 4 |
27 | const flushAtExit = program.flush || false | 29 | const flushAtExit = program.flush || false |
28 | const actionInterval = parseInt(program.action) || 500 | 30 | const actionInterval = program.action !== undefined ? parseInt(program.action) : 500 |
29 | let integrityInterval = parseInt(program.integrity) || 60000 | 31 | let integrityInterval = program.integrity !== undefined ? parseInt(program.integrity) : 60000 |
32 | const displayDiffOnFail = program.integrity || false | ||
30 | 33 | ||
31 | const numberOfPods = 6 | 34 | const numberOfPods = 6 |
35 | |||
32 | // Wait requests between pods | 36 | // Wait requests between pods |
33 | const requestsMaxPerInterval = constants.REQUESTS_INTERVAL / actionInterval | 37 | const baseRequestInterval = integrityInterval < constants.REQUESTS_INTERVAL ? integrityInterval : constants.REQUESTS_INTERVAL |
38 | const requestsMaxPerInterval = baseRequestInterval / actionInterval | ||
34 | const intervalsToMakeAllRequests = Math.ceil(requestsMaxPerInterval / constants.REQUESTS_LIMIT) | 39 | const intervalsToMakeAllRequests = Math.ceil(requestsMaxPerInterval / constants.REQUESTS_LIMIT) |
35 | const waitForBeforeIntegrityCheck = (intervalsToMakeAllRequests * constants.REQUESTS_INTERVAL) + 1000 | 40 | const waitForBeforeIntegrityCheck = (intervalsToMakeAllRequests * constants.REQUESTS_INTERVAL) + 1000 |
36 | 41 | ||
37 | integrityInterval += waitForBeforeIntegrityCheck | ||
38 | |||
39 | console.log('Create weight: %d, remove weight: %d.', createWeight, removeWeight) | 42 | console.log('Create weight: %d, remove weight: %d.', createWeight, removeWeight) |
40 | if (flushAtExit) { | 43 | if (flushAtExit) { |
41 | console.log('Program will flush data on exit.') | 44 | console.log('Program will flush data on exit.') |
42 | } else { | 45 | } else { |
43 | console.log('Program will not flush data on exit.') | 46 | console.log('Program will not flush data on exit.') |
44 | } | 47 | } |
48 | if (displayDiffOnFail) { | ||
49 | console.log('Program will display diff on failure.') | ||
50 | } else { | ||
51 | console.log('Program will not display diff on failure') | ||
52 | } | ||
45 | console.log('Interval in ms for each action: %d.', actionInterval) | 53 | console.log('Interval in ms for each action: %d.', actionInterval) |
46 | console.log('Interval in ms for each integrity check: %d.', integrityInterval) | 54 | console.log('Interval in ms for each integrity check: %d.', integrityInterval) |
47 | console.log('Will wait %d ms before an integrity check.', waitForBeforeIntegrityCheck) | 55 | console.log('Will wait %d ms before an integrity check.', waitForBeforeIntegrityCheck) |
@@ -73,6 +81,8 @@ runServers(numberOfPods, function (err, servers) { | |||
73 | }, actionInterval) | 81 | }, actionInterval) |
74 | 82 | ||
75 | setInterval(function () { | 83 | setInterval(function () { |
84 | if (checking === true) return | ||
85 | |||
76 | console.log('Checking integrity...') | 86 | console.log('Checking integrity...') |
77 | checking = true | 87 | checking = true |
78 | 88 | ||
@@ -196,6 +206,7 @@ function checkIntegrity (servers, callback) { | |||
196 | delete serverVideo.id | 206 | delete serverVideo.id |
197 | delete serverVideo.isLocal | 207 | delete serverVideo.isLocal |
198 | delete serverVideo.thumbnailPath | 208 | delete serverVideo.thumbnailPath |
209 | delete serverVideo.updatedAt | ||
199 | } | 210 | } |
200 | 211 | ||
201 | videos.push(serverVideos) | 212 | videos.push(serverVideos) |
@@ -206,6 +217,10 @@ function checkIntegrity (servers, callback) { | |||
206 | if (!isEqual(video, videos[0])) { | 217 | if (!isEqual(video, videos[0])) { |
207 | console.error('Integrity not ok!') | 218 | console.error('Integrity not ok!') |
208 | 219 | ||
220 | if (displayDiffOnFail) { | ||
221 | console.log(differenceWith(videos[0], video, isEqual)) | ||
222 | } | ||
223 | |||
209 | process.exit(-1) | 224 | process.exit(-1) |
210 | } | 225 | } |
211 | } | 226 | } |