diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-02-26 18:57:33 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-02-26 20:01:26 +0100 |
commit | e4c87ec26962e359d1c70b03ed188a3f19d6a25b (patch) | |
tree | 26fe20e6f600bc6f6f569dde2171b0a2346b135c /server/tests/api/multiple-pods.js | |
parent | 9e167724f7e933f41d9ea2e1c31772bf4c560a28 (diff) | |
download | PeerTube-e4c87ec26962e359d1c70b03ed188a3f19d6a25b.tar.gz PeerTube-e4c87ec26962e359d1c70b03ed188a3f19d6a25b.tar.zst PeerTube-e4c87ec26962e359d1c70b03ed188a3f19d6a25b.zip |
Server: implement video views
Diffstat (limited to 'server/tests/api/multiple-pods.js')
-rw-r--r-- | server/tests/api/multiple-pods.js | 150 |
1 files changed, 124 insertions, 26 deletions
diff --git a/server/tests/api/multiple-pods.js b/server/tests/api/multiple-pods.js index 871db54be..94b62e27a 100644 --- a/server/tests/api/multiple-pods.js +++ b/server/tests/api/multiple-pods.js | |||
@@ -377,19 +377,44 @@ describe('Test multiple pods', function () { | |||
377 | }) | 377 | }) |
378 | 378 | ||
379 | describe('Should update video views', function () { | 379 | describe('Should update video views', function () { |
380 | let videoId1 | 380 | let localVideosPod3 = [] |
381 | let videoId2 | 381 | let remoteVideosPod1 = [] |
382 | let remoteVideosPod2 = [] | ||
383 | let remoteVideosPod3 = [] | ||
382 | 384 | ||
383 | before(function (done) { | 385 | before(function (done) { |
384 | videosUtils.getVideosList(servers[2].url, function (err, res) { | 386 | parallel([ |
385 | if (err) throw err | 387 | function (callback) { |
388 | videosUtils.getVideosList(servers[0].url, function (err, res) { | ||
389 | if (err) throw err | ||
386 | 390 | ||
387 | const videos = res.body.data.filter(video => video.isLocal === true) | 391 | remoteVideosPod1 = res.body.data.filter(video => video.isLocal === false).map(video => video.id) |
388 | videoId1 = videos[0].id | ||
389 | videoId2 = videos[1].id | ||
390 | 392 | ||
391 | done() | 393 | callback() |
392 | }) | 394 | }) |
395 | }, | ||
396 | |||
397 | function (callback) { | ||
398 | videosUtils.getVideosList(servers[1].url, function (err, res) { | ||
399 | if (err) throw err | ||
400 | |||
401 | remoteVideosPod2 = res.body.data.filter(video => video.isLocal === false).map(video => video.id) | ||
402 | |||
403 | callback() | ||
404 | }) | ||
405 | }, | ||
406 | |||
407 | function (callback) { | ||
408 | videosUtils.getVideosList(servers[2].url, function (err, res) { | ||
409 | if (err) throw err | ||
410 | |||
411 | localVideosPod3 = res.body.data.filter(video => video.isLocal === true).map(video => video.id) | ||
412 | remoteVideosPod3 = res.body.data.filter(video => video.isLocal === false).map(video => video.id) | ||
413 | |||
414 | callback() | ||
415 | }) | ||
416 | } | ||
417 | ], done) | ||
393 | }) | 418 | }) |
394 | 419 | ||
395 | it('Should views multiple videos on owned servers', function (done) { | 420 | it('Should views multiple videos on owned servers', function (done) { |
@@ -397,42 +422,115 @@ describe('Test multiple pods', function () { | |||
397 | 422 | ||
398 | parallel([ | 423 | parallel([ |
399 | function (callback) { | 424 | function (callback) { |
400 | videosUtils.getVideo(servers[2].url, videoId1, callback) | 425 | videosUtils.getVideo(servers[2].url, localVideosPod3[0], callback) |
401 | }, | 426 | }, |
402 | 427 | ||
403 | function (callback) { | 428 | function (callback) { |
404 | videosUtils.getVideo(servers[2].url, videoId1, callback) | 429 | videosUtils.getVideo(servers[2].url, localVideosPod3[0], callback) |
405 | }, | 430 | }, |
406 | 431 | ||
407 | function (callback) { | 432 | function (callback) { |
408 | videosUtils.getVideo(servers[2].url, videoId1, callback) | 433 | videosUtils.getVideo(servers[2].url, localVideosPod3[0], callback) |
409 | }, | 434 | }, |
410 | 435 | ||
411 | function (callback) { | 436 | function (callback) { |
412 | videosUtils.getVideo(servers[2].url, videoId2, callback) | 437 | videosUtils.getVideo(servers[2].url, localVideosPod3[1], callback) |
438 | }, | ||
439 | |||
440 | function (callback) { | ||
441 | setTimeout(done, 22000) | ||
413 | } | 442 | } |
414 | ], function (err) { | 443 | ], function (err) { |
415 | if (err) throw err | 444 | if (err) throw err |
416 | 445 | ||
417 | setTimeout(done, 22000) | 446 | each(servers, function (server, callback) { |
447 | videosUtils.getVideosList(server.url, function (err, res) { | ||
448 | if (err) throw err | ||
449 | |||
450 | const videos = res.body.data | ||
451 | expect(videos.find(video => video.views === 3)).to.be.exist | ||
452 | expect(videos.find(video => video.views === 1)).to.be.exist | ||
453 | |||
454 | callback() | ||
455 | }) | ||
456 | }, done) | ||
418 | }) | 457 | }) |
419 | }) | 458 | }) |
420 | 459 | ||
421 | it('Should have views updated on each pod', function (done) { | 460 | it('Should views multiple videos on each servers', function (done) { |
422 | each(servers, function (server, callback) { | 461 | this.timeout(30000) |
423 | videosUtils.getVideosList(server.url, function (err, res) { | ||
424 | if (err) throw err | ||
425 | 462 | ||
426 | const videos = res.body.data | 463 | parallel([ |
427 | expect(videos.find(video => video.views === 3)).to.be.exist | 464 | function (callback) { |
428 | expect(videos.find(video => video.views === 1)).to.be.exist | 465 | videosUtils.getVideo(servers[0].url, remoteVideosPod1[0], callback) |
466 | }, | ||
429 | 467 | ||
430 | callback() | 468 | function (callback) { |
431 | }) | 469 | videosUtils.getVideo(servers[1].url, remoteVideosPod2[0], callback) |
432 | }, done) | 470 | }, |
471 | |||
472 | function (callback) { | ||
473 | videosUtils.getVideo(servers[1].url, remoteVideosPod2[0], callback) | ||
474 | }, | ||
475 | |||
476 | function (callback) { | ||
477 | videosUtils.getVideo(servers[2].url, remoteVideosPod3[0], callback) | ||
478 | }, | ||
479 | |||
480 | function (callback) { | ||
481 | videosUtils.getVideo(servers[2].url, remoteVideosPod3[1], callback) | ||
482 | }, | ||
483 | |||
484 | function (callback) { | ||
485 | videosUtils.getVideo(servers[2].url, remoteVideosPod3[1], callback) | ||
486 | }, | ||
487 | |||
488 | function (callback) { | ||
489 | videosUtils.getVideo(servers[2].url, remoteVideosPod3[1], callback) | ||
490 | }, | ||
491 | |||
492 | function (callback) { | ||
493 | videosUtils.getVideo(servers[2].url, localVideosPod3[1], callback) | ||
494 | }, | ||
495 | |||
496 | function (callback) { | ||
497 | videosUtils.getVideo(servers[2].url, localVideosPod3[1], callback) | ||
498 | }, | ||
499 | |||
500 | function (callback) { | ||
501 | videosUtils.getVideo(servers[2].url, localVideosPod3[1], callback) | ||
502 | }, | ||
503 | |||
504 | function (callback) { | ||
505 | setTimeout(done, 22000) | ||
506 | } | ||
507 | ], function (err) { | ||
508 | if (err) throw err | ||
509 | |||
510 | let baseVideos = null | ||
511 | each(servers, function (server, callback) { | ||
512 | videosUtils.getVideosList(server.url, function (err, res) { | ||
513 | if (err) throw err | ||
514 | |||
515 | const videos = res.body | ||
516 | |||
517 | // Initialize base videos for future comparisons | ||
518 | if (baseVideos === null) { | ||
519 | baseVideos = videos | ||
520 | return callback() | ||
521 | } | ||
522 | |||
523 | for (let i = 0; i < baseVideos.length; i++) { | ||
524 | expect(baseVideos[i].views).to.equal(videos[i].views) | ||
525 | } | ||
526 | |||
527 | callback() | ||
528 | }) | ||
529 | }, done) | ||
530 | }) | ||
433 | }) | 531 | }) |
434 | }) | 532 | }) |
435 | /* | 533 | |
436 | describe('Should manipulate these videos', function () { | 534 | describe('Should manipulate these videos', function () { |
437 | it('Should update the video 3 by asking pod 3', function (done) { | 535 | it('Should update the video 3 by asking pod 3', function (done) { |
438 | this.timeout(15000) | 536 | this.timeout(15000) |
@@ -520,7 +618,7 @@ describe('Test multiple pods', function () { | |||
520 | }, done) | 618 | }, done) |
521 | }) | 619 | }) |
522 | }) | 620 | }) |
523 | */ | 621 | |
524 | after(function (done) { | 622 | after(function (done) { |
525 | servers.forEach(function (server) { | 623 | servers.forEach(function (server) { |
526 | process.kill(-server.app.pid) | 624 | process.kill(-server.app.pid) |