From 9e167724f7e933f41d9ea2e1c31772bf4c560a28 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 21 Feb 2017 21:35:59 +0100 Subject: Server: make a basic "quick and dirty update" for videos This system will be useful to to update some int video attributes (likes, dislikes, views...) The classic system is not used because we need some optimization for scaling --- server/tests/api/multiple-pods.js | 60 ++++++++++++++++++++++++++++++++++++++- server/tests/api/single-pod.js | 11 +++++++ 2 files changed, 70 insertions(+), 1 deletion(-) (limited to 'server/tests') diff --git a/server/tests/api/multiple-pods.js b/server/tests/api/multiple-pods.js index df12ba0e9..871db54be 100644 --- a/server/tests/api/multiple-pods.js +++ b/server/tests/api/multiple-pods.js @@ -3,6 +3,7 @@ const chai = require('chai') const each = require('async/each') const expect = chai.expect +const parallel = require('async/parallel') const series = require('async/series') const WebTorrent = require('webtorrent') const webtorrent = new WebTorrent() @@ -375,6 +376,63 @@ describe('Test multiple pods', function () { }) }) + describe('Should update video views', function () { + let videoId1 + let videoId2 + + before(function (done) { + videosUtils.getVideosList(servers[2].url, function (err, res) { + if (err) throw err + + const videos = res.body.data.filter(video => video.isLocal === true) + videoId1 = videos[0].id + videoId2 = videos[1].id + + done() + }) + }) + + it('Should views multiple videos on owned servers', function (done) { + this.timeout(30000) + + parallel([ + function (callback) { + videosUtils.getVideo(servers[2].url, videoId1, callback) + }, + + function (callback) { + videosUtils.getVideo(servers[2].url, videoId1, callback) + }, + + function (callback) { + videosUtils.getVideo(servers[2].url, videoId1, callback) + }, + + function (callback) { + videosUtils.getVideo(servers[2].url, videoId2, callback) + } + ], function (err) { + if (err) throw err + + setTimeout(done, 22000) + }) + }) + + it('Should have views updated on each pod', function (done) { + each(servers, function (server, callback) { + videosUtils.getVideosList(server.url, function (err, res) { + if (err) throw err + + const videos = res.body.data + expect(videos.find(video => video.views === 3)).to.be.exist + expect(videos.find(video => video.views === 1)).to.be.exist + + callback() + }) + }, done) + }) + }) +/* describe('Should manipulate these videos', function () { it('Should update the video 3 by asking pod 3', function (done) { this.timeout(15000) @@ -462,7 +520,7 @@ describe('Test multiple pods', function () { }, done) }) }) - +*/ after(function (done) { servers.forEach(function (server) { process.kill(-server.app.pid) diff --git a/server/tests/api/single-pod.js b/server/tests/api/single-pod.js index 83a2b4411..40c33686f 100644 --- a/server/tests/api/single-pod.js +++ b/server/tests/api/single-pod.js @@ -129,6 +129,17 @@ describe('Test a single pod', function () { }) }) + it('Should have the views updated', function (done) { + videosUtils.getVideo(server.url, videoId, function (err, res) { + if (err) throw err + + const video = res.body + expect(video.views).to.equal(1) + + done() + }) + }) + it('Should search the video by name by default', function (done) { videosUtils.searchVideo(server.url, 'my', function (err, res) { if (err) throw err -- cgit v1.2.3