diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-01-12 15:20:03 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-01-12 15:20:03 +0100 |
commit | 99fe265a5fc077cb66c322e7f3d191ff7110aea0 (patch) | |
tree | c9e04ccfcc5496d2300d7c26db5833e494b4cdad /server/tests/real-world | |
parent | fcc5f77b95d330bfcb439c172b7fcc58f3162e4d (diff) | |
parent | 91cc839af88730ba55f84997c56b85ea100070a7 (diff) | |
download | PeerTube-99fe265a5fc077cb66c322e7f3d191ff7110aea0.tar.gz PeerTube-99fe265a5fc077cb66c322e7f3d191ff7110aea0.tar.zst PeerTube-99fe265a5fc077cb66c322e7f3d191ff7110aea0.zip |
Merge branch 'postgresql'
Diffstat (limited to 'server/tests/real-world')
-rw-r--r-- | server/tests/real-world/real-world.js | 68 |
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 | ||
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 | ||
@@ -16,32 +17,41 @@ const videosUtils = require('../utils/videos') | |||
16 | program | 17 | program |
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 | ||
25 | const createWeight = parseInt(program.create) || 5 | 28 | const createWeight = program.create !== undefined ? parseInt(program.create) : 5 |
26 | const removeWeight = parseInt(program.remove) || 4 | 29 | const removeWeight = program.remove !== undefined ? parseInt(program.remove) : 4 |
30 | const updateWeight = program.update !== undefined ? parseInt(program.update) : 4 | ||
27 | const flushAtExit = program.flush || false | 31 | const flushAtExit = program.flush || false |
28 | const actionInterval = parseInt(program.action) || 500 | 32 | const actionInterval = program.action !== undefined ? parseInt(program.action) : 500 |
29 | let integrityInterval = parseInt(program.integrity) || 60000 | 33 | const integrityInterval = program.integrity !== undefined ? parseInt(program.integrity) : 60000 |
34 | const displayDiffOnFail = program.integrity || false | ||
30 | 35 | ||
31 | const numberOfPods = 6 | 36 | const numberOfPods = 6 |
32 | // Wait requests between pods | ||
33 | const requestsMaxPerInterval = constants.INTERVAL / actionInterval | ||
34 | const intervalsToMakeAllRequests = Math.ceil(requestsMaxPerInterval / constants.REQUESTS_LIMIT) | ||
35 | const waitForBeforeIntegrityCheck = (intervalsToMakeAllRequests * constants.INTERVAL) + 1000 | ||
36 | 37 | ||
37 | integrityInterval += waitForBeforeIntegrityCheck | 38 | // Wait requests between pods |
39 | const baseRequestInterval = integrityInterval < constants.REQUESTS_INTERVAL ? constants.REQUESTS_INTERVAL : integrityInterval | ||
40 | const requestsMaxPerInterval = baseRequestInterval / actionInterval | ||
41 | const intervalsToMakeAllRequests = Math.ceil(requestsMaxPerInterval / constants.REQUESTS_LIMIT_PER_POD) | ||
42 | const waitForBeforeIntegrityCheck = (intervalsToMakeAllRequests * constants.REQUESTS_INTERVAL) - integrityInterval + 1000 | ||
38 | 43 | ||
39 | console.log('Create weight: %d, remove weight: %d.', createWeight, removeWeight) | 44 | console.log('Create weight: %d, update weight: %d, remove weight: %d.', createWeight, updateWeight, removeWeight) |
40 | if (flushAtExit) { | 45 | if (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 | } |
50 | if (displayDiffOnFail) { | ||
51 | console.log('Program will display diff on failure.') | ||
52 | } else { | ||
53 | console.log('Program will not display diff on failure') | ||
54 | } | ||
45 | console.log('Interval in ms for each action: %d.', actionInterval) | 55 | console.log('Interval in ms for each action: %d.', actionInterval) |
46 | console.log('Interval in ms for each integrity check: %d.', integrityInterval) | 56 | console.log('Interval in ms for each integrity check: %d.', integrityInterval) |
47 | console.log('Will wait %d ms before an integrity check.', waitForBeforeIntegrityCheck) | 57 | console.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) { | |||
160 | function upload (servers, numServer, callback) { | 174 | function 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 | ||
187 | function 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 | |||
173 | function remove (servers, numServer, callback) { | 207 | function 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 | } |