aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2017-12-29 10:04:15 +0100
committerChocobozzz <me@florianbigard.com>2017-12-29 10:04:15 +0100
commita7ba16b62d18a53c416d248f4be06fb693b318ac (patch)
treed665a7a5afc69b780f663b314c4d466ba19778f0 /server
parentefed5d5ef61cd14ee3f9ed1dda8ea8e937370405 (diff)
downloadPeerTube-a7ba16b62d18a53c416d248f4be06fb693b318ac.tar.gz
PeerTube-a7ba16b62d18a53c416d248f4be06fb693b318ac.tar.zst
PeerTube-a7ba16b62d18a53c416d248f4be06fb693b318ac.zip
Fix real world script
Diffstat (limited to 'server')
-rw-r--r--server/tests/api/users/users.ts236
-rw-r--r--server/tests/api/videos/services.ts6
-rw-r--r--server/tests/api/videos/video-transcoder.ts20
-rw-r--r--server/tests/real-world/real-world.ts743
4 files changed, 437 insertions, 568 deletions
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts
index a13807b5c..19549acdd 100644
--- a/server/tests/api/users/users.ts
+++ b/server/tests/api/users/users.ts
@@ -40,36 +40,28 @@ describe('Test users', function () {
40 const client = { id: 'client', secret: server.client.secret } 40 const client = { id: 'client', secret: server.client.secret }
41 const res = await login(server.url, client, server.user, 400) 41 const res = await login(server.url, client, server.user, 400)
42 42
43 expect(res.body.error) 43 expect(res.body.error).to.equal('Authentication failed.')
44 .to
45 .equal('Authentication failed.')
46 }) 44 })
47 45
48 it('Should not login with an invalid client secret', async function () { 46 it('Should not login with an invalid client secret', async function () {
49 const client = { id: server.client.id, secret: 'coucou' } 47 const client = { id: server.client.id, secret: 'coucou' }
50 const res = await login(server.url, client, server.user, 400) 48 const res = await login(server.url, client, server.user, 400)
51 49
52 expect(res.body.error) 50 expect(res.body.error).to.equal('Authentication failed.')
53 .to
54 .equal('Authentication failed.')
55 }) 51 })
56 52
57 it('Should not login with an invalid username', async function () { 53 it('Should not login with an invalid username', async function () {
58 const user = { username: 'captain crochet', password: server.user.password } 54 const user = { username: 'captain crochet', password: server.user.password }
59 const res = await login(server.url, server.client, user, 400) 55 const res = await login(server.url, server.client, user, 400)
60 56
61 expect(res.body.error) 57 expect(res.body.error).to.equal('Authentication failed.')
62 .to
63 .equal('Authentication failed.')
64 }) 58 })
65 59
66 it('Should not login with an invalid password', async function () { 60 it('Should not login with an invalid password', async function () {
67 const user = { username: server.user.username, password: 'mew_three' } 61 const user = { username: server.user.username, password: 'mew_three' }
68 const res = await login(server.url, server.client, user, 400) 62 const res = await login(server.url, server.client, user, 400)
69 63
70 expect(res.body.error) 64 expect(res.body.error).to.equal('Authentication failed.')
71 .to
72 .equal('Authentication failed.')
73 }) 65 })
74 66
75 it('Should not be able to upload a video', async function () { 67 it('Should not be able to upload a video', async function () {
@@ -98,9 +90,7 @@ describe('Test users', function () {
98 const res = await getVideosList(server.url) 90 const res = await getVideosList(server.url)
99 const video = res.body.data[ 0 ] 91 const video = res.body.data[ 0 ]
100 92
101 expect(video.accountName) 93 expect(video.accountName).to.equal('root')
102 .to
103 .equal('root')
104 videoId = video.id 94 videoId = video.id
105 }) 95 })
106 96
@@ -114,12 +104,8 @@ describe('Test users', function () {
114 const res = await getMyUserVideoRating(server.url, accessToken, videoId) 104 const res = await getMyUserVideoRating(server.url, accessToken, videoId)
115 const rating = res.body 105 const rating = res.body
116 106
117 expect(rating.videoId) 107 expect(rating.videoId).to.equal(videoId)
118 .to 108 expect(rating.rating).to.equal('like')
119 .equal(videoId)
120 expect(rating.rating)
121 .to
122 .equal('like')
123 }) 109 })
124 110
125 it('Should not be able to remove the video with an incorrect token', async function () { 111 it('Should not be able to remove the video with an incorrect token', async function () {
@@ -181,23 +167,12 @@ describe('Test users', function () {
181 const res = await getMyUserInformation(server.url, accessTokenUser) 167 const res = await getMyUserInformation(server.url, accessTokenUser)
182 const user = res.body 168 const user = res.body
183 169
184 expect(user.username) 170 expect(user.username).to.equal('user_1')
185 .to 171 expect(user.email).to.equal('user_1@example.com')
186 .equal('user_1')
187 expect(user.email)
188 .to
189 .equal('user_1@example.com')
190 expect(user.displayNSFW).to.be.false 172 expect(user.displayNSFW).to.be.false
191 expect(user.videoQuota) 173 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
192 .to 174 expect(user.roleLabel).to.equal('User')
193 .equal(2 * 1024 * 1024) 175 expect(user.id).to.be.a('number')
194 expect(user.roleLabel)
195 .to
196 .equal('User')
197 expect(user.id)
198 .to
199 .be
200 .a('number')
201 }) 176 })
202 177
203 it('Should be able to upload a video with this user', async function () { 178 it('Should be able to upload a video with this user', async function () {
@@ -211,19 +186,12 @@ describe('Test users', function () {
211 186
212 it('Should be able to list my videos', async function () { 187 it('Should be able to list my videos', async function () {
213 const res = await getMyVideos(server.url, accessTokenUser, 0, 5) 188 const res = await getMyVideos(server.url, accessTokenUser, 0, 5)
214 expect(res.body.total) 189 expect(res.body.total).to.equal(1)
215 .to
216 .equal(1)
217 190
218 const videos = res.body.data 191 const videos = res.body.data
219 expect(videos) 192 expect(videos).to.have.lengthOf(1)
220 .to
221 .have
222 .lengthOf(1)
223 193
224 expect(videos[ 0 ].name) 194 expect(videos[ 0 ].name).to.equal('super user video')
225 .to
226 .equal('super user video')
227 }) 195 })
228 196
229 it('Should list all the users', async function () { 197 it('Should list all the users', async function () {
@@ -232,33 +200,18 @@ describe('Test users', function () {
232 const total = result.total 200 const total = result.total
233 const users = result.data 201 const users = result.data
234 202
235 expect(total) 203 expect(total).to.equal(2)
236 .to 204 expect(users).to.be.an('array')
237 .equal(2) 205 expect(users.length).to.equal(2)
238 expect(users)
239 .to
240 .be
241 .an('array')
242 expect(users.length)
243 .to
244 .equal(2)
245 206
246 const user = users[ 0 ] 207 const user = users[ 0 ]
247 expect(user.username) 208 expect(user.username).to.equal('user_1')
248 .to 209 expect(user.email).to.equal('user_1@example.com')
249 .equal('user_1')
250 expect(user.email)
251 .to
252 .equal('user_1@example.com')
253 expect(user.displayNSFW).to.be.false 210 expect(user.displayNSFW).to.be.false
254 211
255 const rootUser = users[ 1 ] 212 const rootUser = users[ 1 ]
256 expect(rootUser.username) 213 expect(rootUser.username).to.equal('root')
257 .to 214 expect(rootUser.email).to.equal('admin1@example.com')
258 .equal('root')
259 expect(rootUser.email)
260 .to
261 .equal('admin1@example.com')
262 expect(rootUser.displayNSFW).to.be.false 215 expect(rootUser.displayNSFW).to.be.false
263 216
264 userId = user.id 217 userId = user.id
@@ -271,23 +224,13 @@ describe('Test users', function () {
271 const total = result.total 224 const total = result.total
272 const users = result.data 225 const users = result.data
273 226
274 expect(total) 227 expect(total).to.equal(2)
275 .to 228 expect(users.length).to.equal(1)
276 .equal(2)
277 expect(users.length)
278 .to
279 .equal(1)
280 229
281 const user = users[ 0 ] 230 const user = users[ 0 ]
282 expect(user.username) 231 expect(user.username).to.equal('root')
283 .to 232 expect(user.email).to.equal('admin1@example.com')
284 .equal('root') 233 expect(user.roleLabel).to.equal('Administrator')
285 expect(user.email)
286 .to
287 .equal('admin1@example.com')
288 expect(user.roleLabel)
289 .to
290 .equal('Administrator')
291 expect(user.displayNSFW).to.be.false 234 expect(user.displayNSFW).to.be.false
292 }) 235 })
293 236
@@ -297,20 +240,12 @@ describe('Test users', function () {
297 const total = result.total 240 const total = result.total
298 const users = result.data 241 const users = result.data
299 242
300 expect(total) 243 expect(total).to.equal(2)
301 .to 244 expect(users.length).to.equal(1)
302 .equal(2)
303 expect(users.length)
304 .to
305 .equal(1)
306 245
307 const user = users[ 0 ] 246 const user = users[ 0 ]
308 expect(user.username) 247 expect(user.username).to.equal('user_1')
309 .to 248 expect(user.email).to.equal('user_1@example.com')
310 .equal('user_1')
311 expect(user.email)
312 .to
313 .equal('user_1@example.com')
314 expect(user.displayNSFW).to.be.false 249 expect(user.displayNSFW).to.be.false
315 }) 250 })
316 251
@@ -320,20 +255,12 @@ describe('Test users', function () {
320 const total = result.total 255 const total = result.total
321 const users = result.data 256 const users = result.data
322 257
323 expect(total) 258 expect(total).to.equal(2)
324 .to 259 expect(users.length).to.equal(1)
325 .equal(2)
326 expect(users.length)
327 .to
328 .equal(1)
329 260
330 const user = users[ 0 ] 261 const user = users[ 0 ]
331 expect(user.username) 262 expect(user.username).to.equal('user_1')
332 .to 263 expect(user.email).to.equal('user_1@example.com')
333 .equal('user_1')
334 expect(user.email)
335 .to
336 .equal('user_1@example.com')
337 expect(user.displayNSFW).to.be.false 264 expect(user.displayNSFW).to.be.false
338 }) 265 })
339 266
@@ -343,27 +270,15 @@ describe('Test users', function () {
343 const total = result.total 270 const total = result.total
344 const users = result.data 271 const users = result.data
345 272
346 expect(total) 273 expect(total).to.equal(2)
347 .to 274 expect(users.length).to.equal(2)
348 .equal(2) 275
349 expect(users.length) 276 expect(users[ 0 ].username).to.equal('root')
350 .to 277 expect(users[ 0 ].email).to.equal('admin1@example.com')
351 .equal(2)
352
353 expect(users[ 0 ].username)
354 .to
355 .equal('root')
356 expect(users[ 0 ].email)
357 .to
358 .equal('admin1@example.com')
359 expect(users[ 0 ].displayNSFW).to.be.false 278 expect(users[ 0 ].displayNSFW).to.be.false
360 279
361 expect(users[ 1 ].username) 280 expect(users[ 1 ].username).to.equal('user_1')
362 .to 281 expect(users[ 1 ].email).to.equal('user_1@example.com')
363 .equal('user_1')
364 expect(users[ 1 ].email)
365 .to
366 .equal('user_1@example.com')
367 expect(users[ 1 ].displayNSFW).to.be.false 282 expect(users[ 1 ].displayNSFW).to.be.false
368 }) 283 })
369 284
@@ -388,20 +303,11 @@ describe('Test users', function () {
388 const res = await getMyUserInformation(server.url, accessTokenUser) 303 const res = await getMyUserInformation(server.url, accessTokenUser)
389 const user = res.body 304 const user = res.body
390 305
391 expect(user.username) 306 expect(user.username).to.equal('user_1')
392 .to 307 expect(user.email).to.equal('user_1@example.com')
393 .equal('user_1')
394 expect(user.email)
395 .to
396 .equal('user_1@example.com')
397 expect(user.displayNSFW).to.be.ok 308 expect(user.displayNSFW).to.be.ok
398 expect(user.videoQuota) 309 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
399 .to 310 expect(user.id).to.be.a('number')
400 .equal(2 * 1024 * 1024)
401 expect(user.id)
402 .to
403 .be
404 .a('number')
405 }) 311 })
406 312
407 it('Should be able to change the autoPlayVideo attribute', async function () { 313 it('Should be able to change the autoPlayVideo attribute', async function () {
@@ -427,20 +333,11 @@ describe('Test users', function () {
427 const res = await getMyUserInformation(server.url, accessTokenUser) 333 const res = await getMyUserInformation(server.url, accessTokenUser)
428 const user = res.body 334 const user = res.body
429 335
430 expect(user.username) 336 expect(user.username).to.equal('user_1')
431 .to 337 expect(user.email).to.equal('updated@example.com')
432 .equal('user_1')
433 expect(user.email)
434 .to
435 .equal('updated@example.com')
436 expect(user.displayNSFW).to.be.ok 338 expect(user.displayNSFW).to.be.ok
437 expect(user.videoQuota) 339 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
438 .to 340 expect(user.id).to.be.a('number')
439 .equal(2 * 1024 * 1024)
440 expect(user.id)
441 .to
442 .be
443 .a('number')
444 }) 341 })
445 342
446 it('Should be able to update another user', async function () { 343 it('Should be able to update another user', async function () {
@@ -456,23 +353,12 @@ describe('Test users', function () {
456 const res = await getUserInformation(server.url, accessToken, userId) 353 const res = await getUserInformation(server.url, accessToken, userId)
457 const user = res.body 354 const user = res.body
458 355
459 expect(user.username) 356 expect(user.username).to.equal('user_1')
460 .to 357 expect(user.email).to.equal('updated2@example.com')
461 .equal('user_1')
462 expect(user.email)
463 .to
464 .equal('updated2@example.com')
465 expect(user.displayNSFW).to.be.ok 358 expect(user.displayNSFW).to.be.ok
466 expect(user.videoQuota) 359 expect(user.videoQuota).to.equal(42)
467 .to 360 expect(user.roleLabel).to.equal('Moderator')
468 .equal(42) 361 expect(user.id).to.be.a('number')
469 expect(user.roleLabel)
470 .to
471 .equal('Moderator')
472 expect(user.id)
473 .to
474 .be
475 .a('number')
476 }) 362 })
477 363
478 it('Should not be able to delete a user by a moderator', async function () { 364 it('Should not be able to delete a user by a moderator', async function () {
@@ -495,14 +381,10 @@ describe('Test users', function () {
495 it('Should not have videos of this user', async function () { 381 it('Should not have videos of this user', async function () {
496 const res = await getVideosList(server.url) 382 const res = await getVideosList(server.url)
497 383
498 expect(res.body.total) 384 expect(res.body.total).to.equal(1)
499 .to
500 .equal(1)
501 385
502 const video = res.body.data[ 0 ] 386 const video = res.body.data[ 0 ]
503 expect(video.accountName) 387 expect(video.accountName).to.equal('root')
504 .to
505 .equal('root')
506 }) 388 })
507 389
508 it('Should register a new user', async function () { 390 it('Should register a new user', async function () {
@@ -522,9 +404,7 @@ describe('Test users', function () {
522 const res = await getMyUserInformation(server.url, accessToken) 404 const res = await getMyUserInformation(server.url, accessToken)
523 const user = res.body 405 const user = res.body
524 406
525 expect(user.videoQuota) 407 expect(user.videoQuota).to.equal(5 * 1024 * 1024)
526 .to
527 .equal(5 * 1024 * 1024)
528 }) 408 })
529 409
530 after(async function () { 410 after(async function () {
diff --git a/server/tests/api/videos/services.ts b/server/tests/api/videos/services.ts
index 1cda464d9..b3167aebc 100644
--- a/server/tests/api/videos/services.ts
+++ b/server/tests/api/videos/services.ts
@@ -30,10 +30,8 @@ describe('Test services', function () {
30 const videoAttributes = { 30 const videoAttributes = {
31 name: 'my super name' 31 name: 'my super name'
32 } 32 }
33 await uploadVideo(server.url, server.accessToken, videoAttributes) 33 const res = await uploadVideo(server.url, server.accessToken, videoAttributes)
34 34 server.video = res.body.video
35 const res = await getVideosList(server.url)
36 server.video = res.body.data[0]
37 }) 35 })
38 36
39 it('Should have a valid oEmbed response', async function () { 37 it('Should have a valid oEmbed response', async function () {
diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts
index 27927a594..9ce2ae190 100644
--- a/server/tests/api/videos/video-transcoder.ts
+++ b/server/tests/api/videos/video-transcoder.ts
@@ -1,21 +1,13 @@
1/* tslint:disable:no-unused-expression */ 1/* tslint:disable:no-unused-expression */
2 2
3import 'mocha'
4import * as chai from 'chai' 3import * as chai from 'chai'
5const expect = chai.expect 4import 'mocha'
6
7import { 5import {
8 ServerInfo, 6 flushAndRunMultipleServers, flushTests, getVideo, getVideosList, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo,
9 flushTests, 7 wait, webtorrentAdd
10 uploadVideo, 8} from '../../utils'
11 getVideosList, 9
12 wait, 10const expect = chai.expect
13 setAccessTokensToServers,
14 flushAndRunMultipleServers,
15 killallServers,
16 webtorrentAdd,
17 getVideo
18} from '../../utils/index'
19 11
20describe('Test video transcoding', function () { 12describe('Test video transcoding', function () {
21 let servers: ServerInfo[] = [] 13 let servers: ServerInfo[] = []
diff --git a/server/tests/real-world/real-world.ts b/server/tests/real-world/real-world.ts
index 1afa55267..e41203351 100644
--- a/server/tests/real-world/real-world.ts
+++ b/server/tests/real-world/real-world.ts
@@ -1,372 +1,371 @@
1// // /!\ Before imports /!\ 1// /!\ Before imports /!\
2// process.env.NODE_ENV = 'test' 2process.env.NODE_ENV = 'test'
3// 3
4// import * as program from 'commander' 4import * as program from 'commander'
5// import { Video, VideoFile, VideoRateType } from '../../../shared' 5import { Video, VideoFile, VideoRateType } from '../../../shared'
6// import { 6import {
7// flushAndRunMultipleServers, 7 flushAndRunMultipleServers,
8// flushTests, 8 flushTests, follow,
9// getAllVideosListBy, 9 getVideo,
10// getVideo, 10 getVideosList, getVideosListPagination,
11// getVideosList, 11 killallServers,
12// killallServers, 12 removeVideo,
13// removeVideo, 13 ServerInfo as DefaultServerInfo,
14// ServerInfo as DefaultServerInfo, 14 setAccessTokensToServers,
15// setAccessTokensToServers, 15 updateVideo,
16// updateVideo, 16 uploadVideo, viewVideo,
17// uploadVideo, 17 wait
18// wait 18} from '../utils'
19// } from '../utils' 19import { getJobsListPaginationAndSort } from '../utils/server/jobs'
20// import { follow } from '../utils/follows' 20
21// 21interface ServerInfo extends DefaultServerInfo {
22// interface ServerInfo extends DefaultServerInfo { 22 requestsNumber: number
23// requestsNumber: number 23}
24// } 24
25// 25program
26// program 26 .option('-c, --create [weight]', 'Weight for creating videos')
27// .option('-c, --create [weight]', 'Weight for creating videos') 27 .option('-r, --remove [weight]', 'Weight for removing videos')
28// .option('-r, --remove [weight]', 'Weight for removing videos') 28 .option('-u, --update [weight]', 'Weight for updating videos')
29// .option('-u, --update [weight]', 'Weight for updating videos') 29 .option('-v, --view [weight]', 'Weight for viewing videos')
30// .option('-v, --view [weight]', 'Weight for viewing videos') 30 .option('-l, --like [weight]', 'Weight for liking videos')
31// .option('-l, --like [weight]', 'Weight for liking videos') 31 .option('-s, --dislike [weight]', 'Weight for disliking videos')
32// .option('-s, --dislike [weight]', 'Weight for disliking videos') 32 .option('-p, --servers [n]', 'Number of servers to run (3 or 6)', /^3|6$/, 3)
33// .option('-p, --servers [n]', 'Number of servers to run (3 or 6)', /^3|6$/, 3) 33 .option('-i, --interval-action [interval]', 'Interval in ms for an action')
34// .option('-i, --interval-action [interval]', 'Interval in ms for an action') 34 .option('-I, --interval-integrity [interval]', 'Interval in ms for an integrity check')
35// .option('-I, --interval-integrity [interval]', 'Interval in ms for an integrity check') 35 .option('-f, --flush', 'Flush data on exit')
36// .option('-f, --flush', 'Flush datas on exit') 36 .option('-d, --difference', 'Display difference if integrity is not okay')
37// .option('-d, --difference', 'Display difference if integrity is not okay') 37 .parse(process.argv)
38// .parse(process.argv) 38
39// 39const createWeight = program['create'] !== undefined ? parseInt(program['create'], 10) : 5
40// const createWeight = program['create'] !== undefined ? parseInt(program['create'], 10) : 5 40const removeWeight = program['remove'] !== undefined ? parseInt(program['remove'], 10) : 4
41// const removeWeight = program['remove'] !== undefined ? parseInt(program['remove'], 10) : 4 41const updateWeight = program['update'] !== undefined ? parseInt(program['update'], 10) : 4
42// const updateWeight = program['update'] !== undefined ? parseInt(program['update'], 10) : 4 42const viewWeight = program['view'] !== undefined ? parseInt(program['view'], 10) : 4
43// const viewWeight = program['view'] !== undefined ? parseInt(program['view'], 10) : 4 43const likeWeight = program['like'] !== undefined ? parseInt(program['like'], 10) : 4
44// const likeWeight = program['like'] !== undefined ? parseInt(program['like'], 10) : 4 44const dislikeWeight = program['dislike'] !== undefined ? parseInt(program['dislike'], 10) : 4
45// const dislikeWeight = program['dislike'] !== undefined ? parseInt(program['dislike'], 10) : 4 45const flushAtExit = program['flush'] || false
46// const flushAtExit = program['flush'] || false 46const actionInterval = program['intervalAction'] !== undefined ? parseInt(program['intervalAction'], 10) : 500
47// const actionInterval = program['intervalAction'] !== undefined ? parseInt(program['intervalAction'], 10) : 500 47const integrityInterval = program['intervalIntegrity'] !== undefined ? parseInt(program['intervalIntegrity'], 10) : 60000
48// const integrityInterval = program['intervalIntegrity'] !== undefined ? parseInt(program['intervalIntegrity'], 10) : 60000 48const displayDiffOnFail = program['difference'] || false
49// const displayDiffOnFail = program['difference'] || false 49
50// 50const numberOfServers = 6
51// const numberOfServers = 6 51
52// 52console.log(
53// console.log( 53 'Create weight: %d, update weight: %d, remove weight: %d, view weight: %d, like weight: %d, dislike weight: %d.',
54// 'Create weight: %d, update weight: %d, remove weight: %d, view weight: %d, like weight: %d, dislike weight: %d.', 54 createWeight, updateWeight, removeWeight, viewWeight, likeWeight, dislikeWeight
55// createWeight, updateWeight, removeWeight, viewWeight, likeWeight, dislikeWeight 55)
56// ) 56
57// 57if (flushAtExit) {
58// if (flushAtExit) { 58 console.log('Program will flush data on exit.')
59// console.log('Program will flush data on exit.') 59} else {
60// } else { 60 console.log('Program will not flush data on exit.')
61// console.log('Program will not flush data on exit.') 61}
62// } 62if (displayDiffOnFail) {
63// if (displayDiffOnFail) { 63 console.log('Program will display diff on failure.')
64// console.log('Program will display diff on failure.') 64} else {
65// } else { 65 console.log('Program will not display diff on failure')
66// console.log('Program will not display diff on failure') 66}
67// } 67console.log('Interval in ms for each action: %d.', actionInterval)
68// console.log('Interval in ms for each action: %d.', actionInterval) 68console.log('Interval in ms for each integrity check: %d.', integrityInterval)
69// console.log('Interval in ms for each integrity check: %d.', integrityInterval) 69
70// 70console.log('Run servers...')
71// console.log('Run servers...') 71
72// 72start()
73// start() 73
74// 74// ----------------------------------------------------------------------------
75// // ---------------------------------------------------------------------------- 75
76// 76async function start () {
77// async function start () { 77 const servers = await runServers(numberOfServers)
78// const servers = await runServers(numberOfServers) 78
79// 79 process.on('exit', async () => {
80// process.on('exit', async () => { 80 await exitServers(servers, flushAtExit)
81// await exitServers(servers, flushAtExit) 81
82// 82 return
83// return 83 })
84// }) 84 process.on('SIGINT', goodbye)
85// process.on('SIGINT', goodbye) 85 process.on('SIGTERM', goodbye)
86// process.on('SIGTERM', goodbye) 86
87// 87 console.log('Servers ran')
88// console.log('Servers ran') 88 initializeRequestsPerServer(servers)
89// initializeRequestsPerServer(servers) 89
90// 90 let checking = false
91// let checking = false 91
92// 92 setInterval(async () => {
93// setInterval(async () => { 93 if (checking === true) return
94// if (checking === true) return 94
95// 95 const rand = getRandomInt(0, createWeight + updateWeight + removeWeight + viewWeight + likeWeight + dislikeWeight)
96// const rand = getRandomInt(0, createWeight + updateWeight + removeWeight + viewWeight + likeWeight + dislikeWeight) 96
97// 97 const numServer = getRandomNumServer(servers)
98// const numServer = getRandomNumServer(servers) 98 servers[numServer].requestsNumber++
99// servers[numServer].requestsNumber++ 99
100// 100 if (rand < createWeight) {
101// if (rand < createWeight) { 101 await upload(servers, numServer)
102// await upload(servers, numServer) 102 } else if (rand < createWeight + updateWeight) {
103// } else if (rand < createWeight + updateWeight) { 103 await update(servers, numServer)
104// await update(servers, numServer) 104 } else if (rand < createWeight + updateWeight + removeWeight) {
105// } else if (rand < createWeight + updateWeight + removeWeight) { 105 await remove(servers, numServer)
106// await remove(servers, numServer) 106 } else if (rand < createWeight + updateWeight + removeWeight + viewWeight) {
107// } else if (rand < createWeight + updateWeight + removeWeight + viewWeight) { 107 await view(servers, numServer)
108// await view(servers, numServer) 108 } else if (rand < createWeight + updateWeight + removeWeight + viewWeight + likeWeight) {
109// } else if (rand < createWeight + updateWeight + removeWeight + viewWeight + likeWeight) { 109 await like(servers, numServer)
110// await like(servers, numServer) 110 } else {
111// } else { 111 await dislike(servers, numServer)
112// await dislike(servers, numServer) 112 }
113// } 113 }, actionInterval)
114// }, actionInterval) 114
115// 115 // The function will check the consistency between servers (should have the same videos with same attributes...)
116// // The function will check the consistency between servers (should have the same videos with same attributes...) 116 setInterval(function () {
117// setInterval(function () { 117 if (checking === true) return
118// if (checking === true) return 118
119// 119 console.log('Checking integrity...')
120// console.log('Checking integrity...') 120 checking = true
121// checking = true 121
122// 122 const waitingInterval = setInterval(async () => {
123// const waitingInterval = setInterval(async () => { 123 const pendingRequests = await isTherePendingRequests(servers)
124// const pendingRequests = await isTherePendingRequests(servers) 124 if (pendingRequests === true) {
125// if (pendingRequests === true) { 125 console.log('A server has pending requests, waiting...')
126// console.log('A server has pending requests, waiting...') 126 return
127// return 127 }
128// } 128
129// 129 // Even if there are no pending request, wait some potential processes
130// // Even if there are no pending request, wait some potential processes 130 await wait(2000)
131// await wait(2000) 131 await checkIntegrity(servers)
132// await checkIntegrity(servers) 132
133// 133 initializeRequestsPerServer(servers)
134// initializeRequestsPerServer(servers) 134 checking = false
135// checking = false 135 clearInterval(waitingInterval)
136// clearInterval(waitingInterval) 136 }, 10000)
137// }, 10000) 137 }, integrityInterval)
138// }, integrityInterval) 138}
139// } 139
140// 140function initializeRequestsPerServer (servers: ServerInfo[]) {
141// function initializeRequestsPerServer (servers: ServerInfo[]) { 141 servers.forEach(server => server.requestsNumber = 0)
142// servers.forEach(server => server.requestsNumber = 0) 142}
143// } 143
144// 144function getRandomInt (min, max) {
145// function getRandomInt (min, max) { 145 return Math.floor(Math.random() * (max - min)) + min
146// return Math.floor(Math.random() * (max - min)) + min 146}
147// } 147
148// 148function getRandomNumServer (servers) {
149// function getRandomNumServer (servers) { 149 return getRandomInt(0, servers.length)
150// return getRandomInt(0, servers.length) 150}
151// } 151
152// 152async function runServers (numberOfServers: number) {
153// async function runServers (numberOfServers: number) { 153 const servers: ServerInfo[] = (await flushAndRunMultipleServers(numberOfServers))
154// const servers: ServerInfo[] = (await flushAndRunMultipleServers(numberOfServers)) 154 .map(s => Object.assign({ requestsNumber: 0 }, s))
155// .map(s => Object.assign({ requestsNumber: 0 }, s)) 155
156// 156 // Get the access tokens
157// // Get the access tokens 157 await setAccessTokensToServers(servers)
158// await setAccessTokensToServers(servers) 158
159// 159 for (let i = 0; i < numberOfServers; i++) {
160// for (let i = 0; i < numberOfServers; i++) { 160 for (let j = 0; j < numberOfServers; j++) {
161// for (let j = 0; j < numberOfServers; j++) { 161 if (i === j) continue
162// if (i === j) continue 162
163// 163 await follow(servers[i].url, [ servers[j].url ], servers[i].accessToken)
164// await follow(servers[i].url, [ servers[j].url ], servers[i].accessToken) 164 }
165// } 165 }
166// } 166
167// 167 return servers
168// return servers 168}
169// } 169
170// 170async function exitServers (servers: ServerInfo[], flushAtExit: boolean) {
171// async function exitServers (servers: ServerInfo[], flushAtExit: boolean) { 171 killallServers(servers)
172// killallServers(servers) 172
173// 173 if (flushAtExit) await flushTests()
174// if (flushAtExit) await flushTests() 174}
175// } 175
176// 176function upload (servers: ServerInfo[], numServer: number) {
177// function upload (servers: ServerInfo[], numServer: number) { 177 console.log('Uploading video to server ' + numServer)
178// console.log('Uploading video to server ' + numServer) 178
179// 179 const videoAttributes = {
180// const videoAttributes = { 180 name: Date.now() + ' name',
181// name: Date.now() + ' name', 181 category: 4,
182// category: 4, 182 nsfw: false,
183// nsfw: false, 183 licence: 2,
184// licence: 2, 184 language: 1,
185// language: 1, 185 description: Date.now() + ' description',
186// description: Date.now() + ' description', 186 tags: [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ],
187// tags: [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ], 187 fixture: 'video_short1.webm'
188// fixture: 'video_short1.webm' 188 }
189// } 189 return uploadVideo(servers[numServer].url, servers[numServer].accessToken, videoAttributes)
190// return uploadVideo(servers[numServer].url, servers[numServer].accessToken, videoAttributes) 190}
191// } 191
192// 192async function update (servers: ServerInfo[], numServer: number) {
193// async function update (servers: ServerInfo[], numServer: number) { 193 const res = await getVideosList(servers[numServer].url)
194// const res = await getVideosList(servers[numServer].url) 194
195// 195 const videos = res.body.data.filter(video => video.isLocal === true)
196// const videos = res.body.data.filter(video => video.isLocal === true) 196 if (videos.length === 0) return undefined
197// if (videos.length === 0) return undefined 197
198// 198 const toUpdate = videos[getRandomInt(0, videos.length)].id
199// const toUpdate = videos[getRandomInt(0, videos.length)].id 199 const attributes = {
200// const attributes = { 200 name: Date.now() + ' name',
201// name: Date.now() + ' name', 201 description: Date.now() + ' description',
202// description: Date.now() + ' description', 202 tags: [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ]
203// tags: [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ] 203 }
204// } 204
205// 205 console.log('Updating video of server ' + numServer)
206// console.log('Updating video of server ' + numServer) 206
207// 207 return updateVideo(servers[numServer].url, servers[numServer].accessToken, toUpdate, attributes)
208// return updateVideo(servers[numServer].url, servers[numServer].accessToken, toUpdate, attributes) 208}
209// } 209
210// 210async function remove (servers: ServerInfo[], numServer: number) {
211// async function remove (servers: ServerInfo[], numServer: number) { 211 const res = await getVideosList(servers[numServer].url)
212// const res = await getVideosList(servers[numServer].url) 212 const videos = res.body.data.filter(video => video.isLocal === true)
213// const videos = res.body.data.filter(video => video.isLocal === true) 213 if (videos.length === 0) return undefined
214// if (videos.length === 0) return undefined 214
215// 215 const toRemove = videos[getRandomInt(0, videos.length)].id
216// const toRemove = videos[getRandomInt(0, videos.length)].id 216
217// 217 console.log('Removing video from server ' + numServer)
218// console.log('Removing video from server ' + numServer) 218 return removeVideo(servers[numServer].url, servers[numServer].accessToken, toRemove)
219// return removeVideo(servers[numServer].url, servers[numServer].accessToken, toRemove) 219}
220// } 220
221// 221async function view (servers: ServerInfo[], numServer: number) {
222// async function view (servers: ServerInfo[], numServer: number) { 222 const res = await getVideosList(servers[numServer].url)
223// const res = await getVideosList(servers[numServer].url) 223
224// 224 const videos = res.body.data
225// const videos = res.body.data 225 if (videos.length === 0) return undefined
226// if (videos.length === 0) return undefined 226
227// 227 const toView = videos[getRandomInt(0, videos.length)].id
228// const toView = videos[getRandomInt(0, videos.length)].id 228
229// 229 console.log('Viewing video from server ' + numServer)
230// console.log('Viewing video from server ' + numServer) 230 return viewVideo(servers[numServer].url, toView)
231// return getVideo(servers[numServer].url, toView) 231}
232// } 232
233// 233function like (servers: ServerInfo[], numServer: number) {
234// function like (servers: ServerInfo[], numServer: number) { 234 return rate(servers, numServer, 'like')
235// return rate(servers, numServer, 'like') 235}
236// } 236
237// 237function dislike (servers: ServerInfo[], numServer: number) {
238// function dislike (servers: ServerInfo[], numServer: number) { 238 return rate(servers, numServer, 'dislike')
239// return rate(servers, numServer, 'dislike') 239}
240// } 240
241// 241async function rate (servers: ServerInfo[], numServer: number, rating: VideoRateType) {
242// async function rate (servers: ServerInfo[], numServer: number, rating: VideoRateType) { 242 const res = await getVideosList(servers[numServer].url)
243// const res = await getVideosList(servers[numServer].url) 243
244// 244 const videos = res.body.data
245// const videos = res.body.data 245 if (videos.length === 0) return undefined
246// if (videos.length === 0) return undefined 246
247// 247 const toRate = videos[getRandomInt(0, videos.length)].id
248// const toRate = videos[getRandomInt(0, videos.length)].id 248
249// 249 console.log('Rating (%s) video from server %d', rating, numServer)
250// console.log('Rating (%s) video from server %d', rating, numServer) 250 return getVideo(servers[numServer].url, toRate)
251// return getVideo(servers[numServer].url, toRate) 251}
252// } 252
253// 253async function checkIntegrity (servers: ServerInfo[]) {
254// async function checkIntegrity (servers: ServerInfo[]) { 254 const videos: Video[][] = []
255// const videos: Video[][] = [] 255 const tasks: Promise<any>[] = []
256// const tasks: Promise<any>[] = [] 256
257// 257 // Fetch all videos and remove some fields that can differ between servers
258// // Fetch all videos and remove some fields that can differ between servers 258 for (const server of servers) {
259// for (const server of servers) { 259 const p = getVideosListPagination(server.url, 0, 1000000, '-createdAt')
260// const p = getAllVideosListBy(server.url).then(res => videos.push(res.body.data)) 260 .then(res => videos.push(res.body.data))
261// tasks.push(p) 261 tasks.push(p)
262// } 262 }
263// 263
264// await Promise.all(tasks) 264 await Promise.all(tasks)
265// 265
266// let i = 0 266 let i = 0
267// for (const video of videos) { 267 for (const video of videos) {
268// const differences = areDifferences(video, videos[0]) 268 const differences = areDifferences(video, videos[0])
269// if (differences !== undefined) { 269 if (differences !== undefined) {
270// console.error('Integrity not ok with server %d!', i + 1) 270 console.error('Integrity not ok with server %d!', i + 1)
271// 271
272// if (displayDiffOnFail) { 272 if (displayDiffOnFail) {
273// console.log(differences) 273 console.log(differences)
274// } 274 }
275// 275
276// process.exit(-1) 276 process.exit(-1)
277// } 277 }
278// 278
279// i++ 279 i++
280// } 280 }
281// 281
282// console.log('Integrity ok.') 282 console.log('Integrity ok.')
283// } 283}
284// 284
285// function areDifferences (videos1: Video[], videos2: Video[]) { 285function areDifferences (videos1: Video[], videos2: Video[]) {
286// // Remove some keys we don't want to compare 286 // Remove some keys we don't want to compare
287// videos1.concat(videos2).forEach(video => { 287 videos1.concat(videos2).forEach(video => {
288// delete video.id 288 delete video.id
289// delete video.isLocal 289 delete video.isLocal
290// delete video.thumbnailPath 290 delete video.thumbnailPath
291// delete video.updatedAt 291 delete video.updatedAt
292// delete video.views 292 delete video.views
293// }) 293 })
294// 294
295// if (videos1.length !== videos2.length) { 295 if (videos1.length !== videos2.length) {
296// return `Videos length are different (${videos1.length}/${videos2.length}).` 296 return `Videos length are different (${videos1.length}/${videos2.length}).`
297// } 297 }
298// 298
299// for (const video1 of videos1) { 299 for (const video1 of videos1) {
300// const video2 = videos2.find(video => video.uuid === video1.uuid) 300 const video2 = videos2.find(video => video.uuid === video1.uuid)
301// 301
302// if (!video2) return 'Video ' + video1.uuid + ' is missing.' 302 if (!video2) return 'Video ' + video1.uuid + ' is missing.'
303// 303
304// for (const videoKey of Object.keys(video1)) { 304 for (const videoKey of Object.keys(video1)) {
305// const attribute1 = video1[videoKey] 305 const attribute1 = video1[videoKey]
306// const attribute2 = video2[videoKey] 306 const attribute2 = video2[videoKey]
307// 307
308// if (videoKey === 'tags') { 308 if (videoKey === 'tags') {
309// if (attribute1.length !== attribute2.length) { 309 if (attribute1.length !== attribute2.length) {
310// return 'Tags are different.' 310 return 'Tags are different.'
311// } 311 }
312// 312
313// attribute1.forEach(tag1 => { 313 attribute1.forEach(tag1 => {
314// if (attribute2.indexOf(tag1) === -1) { 314 if (attribute2.indexOf(tag1) === -1) {
315// return 'Tag ' + tag1 + ' is missing.' 315 return 'Tag ' + tag1 + ' is missing.'
316// } 316 }
317// }) 317 })
318// } else if (videoKey === 'files') { 318 } else if (videoKey === 'files') {
319// if (attribute1.length !== attribute2.length) { 319 if (attribute1.length !== attribute2.length) {
320// return 'Video files are different.' 320 return 'Video files are different.'
321// } 321 }
322// 322
323// attribute1.forEach((videoFile1: VideoFile) => { 323 attribute1.forEach((videoFile1: VideoFile) => {
324// const videoFile2: VideoFile = attribute2.find(videoFile => videoFile.magnetUri === videoFile1.magnetUri) 324 const videoFile2: VideoFile = attribute2.find(videoFile => videoFile.magnetUri === videoFile1.magnetUri)
325// if (!videoFile2) { 325 if (!videoFile2) {
326// return `Video ${video1.uuid} has missing video file ${videoFile1.magnetUri}.` 326 return `Video ${video1.uuid} has missing video file ${videoFile1.magnetUri}.`
327// } 327 }
328// 328
329// if (videoFile1.size !== videoFile2.size || videoFile1.resolutionLabel !== videoFile2.resolutionLabel) { 329 if (videoFile1.size !== videoFile2.size || videoFile1.resolutionLabel !== videoFile2.resolutionLabel) {
330// return `Video ${video1.uuid} has different video file ${videoFile1.magnetUri}.` 330 return `Video ${video1.uuid} has different video file ${videoFile1.magnetUri}.`
331// } 331 }
332// }) 332 })
333// } else { 333 } else {
334// if (attribute1 !== attribute2) { 334 if (attribute1 !== attribute2) {
335// return `Video ${video1.uuid} has different value for attribute ${videoKey}.` 335 return `Video ${video1.uuid} has different value for attribute ${videoKey}.`
336// } 336 }
337// } 337 }
338// } 338 }
339// } 339 }
340// 340
341// return undefined 341 return undefined
342// } 342}
343// 343
344// function goodbye () { 344function goodbye () {
345// return process.exit(-1) 345 return process.exit(-1)
346// } 346}
347// 347
348// async function isTherePendingRequests (servers: ServerInfo[]) { 348async function isTherePendingRequests (servers: ServerInfo[]) {
349// const tasks: Promise<any>[] = [] 349 const tasks: Promise<any>[] = []
350// let pendingRequests = false 350 let pendingRequests = false
351// 351
352// // Check if each server has pending request 352 // Check if each server has pending request
353// for (const server of servers) { 353 for (const server of servers) {
354// const p = getRequestsStats(server).then(res => { 354 const p = getJobsListPaginationAndSort(server.url, server.accessToken, 0, 10, '-createdAt')
355// const stats = res.body 355 .then(res => {
356// 356 const jobs = res.body.data
357// if ( 357
358// stats.requestScheduler.totalRequests !== 0 || 358 for (const job of jobs) {
359// stats.requestVideoEventScheduler.totalRequests !== 0 || 359 if (job.state === 'pending' || job.state === 'processing') {
360// stats.requestVideoQaduScheduler.totalRequests !== 0 360 pendingRequests = true
361// ) { 361 }
362// pendingRequests = true 362 }
363// } 363 })
364// }) 364
365// 365 tasks.push(p)
366// tasks.push(p) 366 }
367// } 367
368// 368 await Promise.all(tasks)
369// await Promise.all(tasks) 369
370// 370 return pendingRequests
371// return pendingRequests 371}
372// }