aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-03-19 09:16:33 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-03-19 09:16:33 +0100
commitf148e5edb62c914eff12d7d4a5f879fedcfc64be (patch)
tree2846728352e1c21ed06e7a7b85396eb542108bba /server/tests
parent55b3394641a764b89132d0057d3fdf656dab2389 (diff)
downloadPeerTube-f148e5edb62c914eff12d7d4a5f879fedcfc64be.tar.gz
PeerTube-f148e5edb62c914eff12d7d4a5f879fedcfc64be.tar.zst
PeerTube-f148e5edb62c914eff12d7d4a5f879fedcfc64be.zip
Better real world test
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/real-world/real-world.js135
-rw-r--r--server/tests/utils/requests-stats.js25
2 files changed, 142 insertions, 18 deletions
diff --git a/server/tests/real-world/real-world.js b/server/tests/real-world/real-world.js
index 12ab06d6d..239b790ae 100644
--- a/server/tests/real-world/real-world.js
+++ b/server/tests/real-world/real-world.js
@@ -13,11 +13,15 @@ const loginUtils = require('../utils/login')
13const podsUtils = require('../utils/pods') 13const podsUtils = require('../utils/pods')
14const serversUtils = require('../utils/servers') 14const serversUtils = require('../utils/servers')
15const videosUtils = require('../utils/videos') 15const videosUtils = require('../utils/videos')
16const requestStatsUtils = require('../utils/requests-stats')
16 17
17program 18program
18 .option('-c, --create [weight]', 'Weight for creating videos') 19 .option('-c, --create [weight]', 'Weight for creating videos')
19 .option('-r, --remove [weight]', 'Weight for removing videos') 20 .option('-r, --remove [weight]', 'Weight for removing videos')
20 .option('-u, --update [weight]', 'Weight for updating videos') 21 .option('-u, --update [weight]', 'Weight for updating videos')
22 .option('-v, --view [weight]', 'Weight for viewing videos')
23 .option('-l, --like [weight]', 'Weight for liking videos')
24 .option('-s --dislike [weight]', 'Weight for disliking videos')
21 .option('-p, --pods [n]', 'Number of pods to run (3 or 6)', /^3|6$/, 3) 25 .option('-p, --pods [n]', 'Number of pods to run (3 or 6)', /^3|6$/, 3)
22 .option('-a, --action [interval]', 'Interval in ms for an action') 26 .option('-a, --action [interval]', 'Interval in ms for an action')
23 .option('-i, --integrity [interval]', 'Interval in ms for an integrity check') 27 .option('-i, --integrity [interval]', 'Interval in ms for an integrity check')
@@ -28,6 +32,9 @@ program
28const createWeight = program.create !== undefined ? parseInt(program.create) : 5 32const createWeight = program.create !== undefined ? parseInt(program.create) : 5
29const removeWeight = program.remove !== undefined ? parseInt(program.remove) : 4 33const removeWeight = program.remove !== undefined ? parseInt(program.remove) : 4
30const updateWeight = program.update !== undefined ? parseInt(program.update) : 4 34const updateWeight = program.update !== undefined ? parseInt(program.update) : 4
35const viewWeight = program.view !== undefined ? parseInt(program.view) : 4
36const likeWeight = program.like !== undefined ? parseInt(program.like) : 4
37const dislikeWeight = program.dislike !== undefined ? parseInt(program.dislike) : 4
31const flushAtExit = program.flush || false 38const flushAtExit = program.flush || false
32const actionInterval = program.action !== undefined ? parseInt(program.action) : 500 39const actionInterval = program.action !== undefined ? parseInt(program.action) : 500
33const integrityInterval = program.integrity !== undefined ? parseInt(program.integrity) : 60000 40const integrityInterval = program.integrity !== undefined ? parseInt(program.integrity) : 60000
@@ -35,13 +42,7 @@ const displayDiffOnFail = program.integrity || false
35 42
36const numberOfPods = 6 43const numberOfPods = 6
37 44
38// Wait requests between pods 45console.log('Create weight: %d, update weight: %d, remove weight: %d, view weight: %d, like weight: %d, dislike weight: %d.', createWeight, updateWeight, removeWeight, viewWeight, likeWeight, dislikeWeight)
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
43
44console.log('Create weight: %d, update weight: %d, remove weight: %d.', createWeight, updateWeight, removeWeight)
45if (flushAtExit) { 46if (flushAtExit) {
46 console.log('Program will flush data on exit.') 47 console.log('Program will flush data on exit.')
47} else { 48} else {
@@ -54,7 +55,6 @@ if (displayDiffOnFail) {
54} 55}
55console.log('Interval in ms for each action: %d.', actionInterval) 56console.log('Interval in ms for each action: %d.', actionInterval)
56console.log('Interval in ms for each integrity check: %d.', integrityInterval) 57console.log('Interval in ms for each integrity check: %d.', integrityInterval)
57console.log('Will wait %d ms before an integrity check.', waitForBeforeIntegrityCheck)
58 58
59console.log('Run servers...') 59console.log('Run servers...')
60runServers(numberOfPods, function (err, servers) { 60runServers(numberOfPods, function (err, servers) {
@@ -67,39 +67,65 @@ runServers(numberOfPods, function (err, servers) {
67 process.on('SIGTERM', goodbye) 67 process.on('SIGTERM', goodbye)
68 68
69 console.log('Servers runned') 69 console.log('Servers runned')
70 initializeRequestsPerServer(servers)
70 71
71 let checking = false 72 let checking = false
72 73
73 setInterval(function () { 74 setInterval(function () {
74 if (checking === true) return 75 if (checking === true) return
75 76
76 const rand = getRandomInt(0, createWeight + updateWeight + removeWeight) 77 const rand = getRandomInt(0, createWeight + updateWeight + removeWeight + viewWeight + likeWeight + dislikeWeight)
78
79 const numServer = getRandomNumServer(servers)
80 servers[numServer].requestsNumber++
77 81
78 if (rand < createWeight) { 82 if (rand < createWeight) {
79 upload(servers, getRandomNumServer(servers)) 83 upload(servers, numServer)
80 } else if (rand < createWeight + updateWeight) { 84 } else if (rand < createWeight + updateWeight) {
81 update(servers, getRandomNumServer(servers)) 85 update(servers, numServer)
86 } else if (rand < createWeight + updateWeight + removeWeight) {
87 remove(servers, numServer)
88 } else if (rand < createWeight + updateWeight + removeWeight + viewWeight) {
89 view(servers, numServer)
90 } else if (rand < createWeight + updateWeight + removeWeight + viewWeight + likeWeight) {
91 like(servers, numServer)
82 } else { 92 } else {
83 remove(servers, getRandomNumServer(servers)) 93 dislike(servers, numServer)
84 } 94 }
85 }, actionInterval) 95 }, actionInterval)
86 96
97 // The function will check the consistency between servers (should have the same videos with same attributes...)
87 setInterval(function () { 98 setInterval(function () {
88 if (checking === true) return 99 if (checking === true) return
89 100
90 console.log('Checking integrity...') 101 console.log('Checking integrity...')
91 checking = true 102 checking = true
92 103
93 setTimeout(function () { 104 const waitingInterval = setInterval(function () {
94 checkIntegrity(servers, function () { 105 isThereAwaitingRequests(servers, function (res) {
95 checking = false 106 if (res === true) {
107 console.log('A server has awaiting requests, waiting...')
108 return
109 }
110
111 checkIntegrity(servers, function () {
112 initializeRequestsPerServer(servers)
113 checking = false
114 clearInterval(waitingInterval)
115 })
96 }) 116 })
97 }, waitForBeforeIntegrityCheck) 117 }, constants.REQUESTS_INTERVAL)
98 }, integrityInterval) 118 }, integrityInterval)
99}) 119})
100 120
101// ---------------------------------------------------------------------------- 121// ----------------------------------------------------------------------------
102 122
123function initializeRequestsPerServer (servers) {
124 servers.forEach(function (server) {
125 server.requestsNumber = 0
126 })
127}
128
103function getRandomInt (min, max) { 129function getRandomInt (min, max) {
104 return Math.floor(Math.random() * (max - min)) + min 130 return Math.floor(Math.random() * (max - min)) + min
105} 131}
@@ -179,7 +205,7 @@ function upload (servers, numServer, callback) {
179 const tags = [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ] 205 const tags = [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ]
180 const file = 'video_short1.webm' 206 const file = 'video_short1.webm'
181 207
182 console.log('Upload video to server ' + numServer) 208 console.log('Uploading video to server ' + numServer)
183 209
184 videosUtils.uploadVideo(servers[numServer].url, servers[numServer].accessToken, name, description, tags, file, callback) 210 videosUtils.uploadVideo(servers[numServer].url, servers[numServer].accessToken, name, description, tags, file, callback)
185} 211}
@@ -220,6 +246,46 @@ function remove (servers, numServer, callback) {
220 }) 246 })
221} 247}
222 248
249function view (servers, numServer, callback) {
250 if (!callback) callback = function () {}
251
252 videosUtils.getVideosList(servers[numServer].url, function (err, res) {
253 if (err) throw err
254
255 const videos = res.body.data
256 if (videos.length === 0) return callback()
257
258 const toView = videos[getRandomInt(0, videos.length)].id
259
260 console.log('Viewing video from server ' + numServer)
261 videosUtils.getVideo(servers[numServer].url, toView, callback)
262 })
263}
264
265function like (servers, numServer, callback) {
266 rate(servers, numServer, 'like', callback)
267}
268
269function dislike (servers, numServer, callback) {
270 rate(servers, numServer, 'dislike', callback)
271}
272
273function rate (servers, numServer, rating, callback) {
274 if (!callback) callback = function () {}
275
276 videosUtils.getVideosList(servers[numServer].url, function (err, res) {
277 if (err) throw err
278
279 const videos = res.body.data
280 if (videos.length === 0) return callback()
281
282 const toRate = videos[getRandomInt(0, videos.length)].id
283
284 console.log('Rating (%s) video from server %d', rating, numServer)
285 videosUtils.getVideo(servers[numServer].url, toRate, callback)
286 })
287}
288
223function checkIntegrity (servers, callback) { 289function checkIntegrity (servers, callback) {
224 const videos = [] 290 const videos = []
225 each(servers, function (server, callback) { 291 each(servers, function (server, callback) {
@@ -231,22 +297,28 @@ function checkIntegrity (servers, callback) {
231 delete serverVideo.isLocal 297 delete serverVideo.isLocal
232 delete serverVideo.thumbnailPath 298 delete serverVideo.thumbnailPath
233 delete serverVideo.updatedAt 299 delete serverVideo.updatedAt
300 delete serverVideo.views
234 } 301 }
235 302
236 videos.push(serverVideos) 303 videos.push(serverVideos)
237 callback() 304 callback()
238 }) 305 })
239 }, function () { 306 }, function () {
307 let i = 0
308
240 for (const video of videos) { 309 for (const video of videos) {
241 if (!isEqual(video, videos[0])) { 310 if (!isEqual(video, videos[0])) {
242 console.error('Integrity not ok!') 311 console.error('Integrity not ok with server %d!', i + 1)
243 312
244 if (displayDiffOnFail) { 313 if (displayDiffOnFail) {
245 console.log(differenceWith(videos[0], video, isEqual)) 314 console.log(differenceWith(videos[0], video, isEqual))
315 console.log(differenceWith(video, videos[0], isEqual))
246 } 316 }
247 317
248 process.exit(-1) 318 process.exit(-1)
249 } 319 }
320
321 i++
250 } 322 }
251 323
252 console.log('Integrity ok.') 324 console.log('Integrity ok.')
@@ -257,3 +329,30 @@ function checkIntegrity (servers, callback) {
257function goodbye () { 329function goodbye () {
258 return process.exit(-1) 330 return process.exit(-1)
259} 331}
332
333function isThereAwaitingRequests (servers, callback) {
334 let noRequests = true
335
336 // Check is each server has awaiting requestq
337 each(servers, function (server, callbackEach) {
338 requestStatsUtils.getRequestsStats(server, server.accessToken, function (err, res) {
339 if (err) throw err
340
341 const stats = res.body
342
343 if (
344 stats.requestScheduler.totalRequests !== 0 ||
345 stats.requestVideoEventScheduler.totalRequests !== 0 ||
346 stats.requestVideoQaduScheduler.totalRequests !== 0
347 ) {
348 noRequests = false
349 }
350
351 callbackEach()
352 })
353 }, function (err) {
354 if (err) throw err
355
356 return callback(noRequests === false)
357 })
358}
diff --git a/server/tests/utils/requests-stats.js b/server/tests/utils/requests-stats.js
new file mode 100644
index 000000000..16835ce47
--- /dev/null
+++ b/server/tests/utils/requests-stats.js
@@ -0,0 +1,25 @@
1'use strict'
2
3const request = require('supertest')
4
5const requestsStatsUtils = {
6 getRequestsStats
7}
8
9// ---------------------- Export functions --------------------
10
11function getRequestsStats (server, accessToken, callback) {
12 const path = '/api/v1/requests/stats'
13
14 request(server.url)
15 .get(path)
16 .set('Accept', 'application/json')
17 .set('Authorization', 'Bearer ' + accessToken)
18 .expect(200)
19 .expect('Content-Type', /json/)
20 .end(callback)
21}
22
23// ---------------------------------------------------------------------------
24
25module.exports = requestsStatsUtils