X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2FmultiplePods.js;h=f1415f6f14ba2a3d90d96fed84c9187b5f8f72e0;hb=bc503c2a62dcf9aed6b8d90b68f0f27a7755ac01;hp=e8b1826221016119a2e6d849fa1bb884fb42f2db;hpb=f0f5567b6918fc60c8cab15e13aec03a89a91dfb;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/multiplePods.js b/server/tests/api/multiplePods.js index e8b182622..f1415f6f1 100644 --- a/server/tests/api/multiplePods.js +++ b/server/tests/api/multiplePods.js @@ -10,9 +10,8 @@ const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent')) webtorrent.silent = true describe('Test multiple pods', function () { - let apps = [] - let urls = [] - const to_remove = [] + let servers = [] + const toRemove = [] before(function (done) { this.timeout(30000) @@ -20,15 +19,25 @@ describe('Test multiple pods', function () { async.series([ // Run servers function (next) { - utils.flushAndRunMultipleServers(3, function (apps_run, urls_run) { - apps = apps_run - urls = urls_run + utils.flushAndRunMultipleServers(3, function (serversRun) { + servers = serversRun next() }) }, + // Get the access tokens + function (next) { + async.each(servers, function (server, callbackEach) { + utils.loginAndGetAccessToken(server, function (err, accessToken) { + if (err) return callbackEach(err) + + server.accessToken = accessToken + callbackEach() + }) + }, next) + }, // The second pod make friend with the third function (next) { - utils.makeFriends(urls[1], next) + utils.makeFriends(servers[1].url, next) }, // Wait for the request between pods function (next) { @@ -36,7 +45,7 @@ describe('Test multiple pods', function () { }, // Pod 1 make friends too function (next) { - utils.makeFriends(urls[0], next) + utils.makeFriends(servers[0].url, next) }, function (next) { webtorrent.create({ host: 'client', port: '1' }, next) @@ -45,8 +54,8 @@ describe('Test multiple pods', function () { }) it('Should not have videos for all pods', function (done) { - async.each(urls, function (url, callback) { - utils.getVideosList(url, function (err, res) { + async.each(servers, function (server, callback) { + utils.getVideosList(server.url, function (err, res) { if (err) throw err expect(res.body).to.be.an('array') @@ -63,7 +72,7 @@ describe('Test multiple pods', function () { async.series([ function (next) { - utils.uploadVideo(urls[0], 'my super name for pod 1', 'my super description for pod 1', 'video_short1.webm', next) + utils.uploadVideo(servers[0].url, servers[0].access_token, 'my super name for pod 1', 'my super description for pod 1', 'video_short1.webm', next) }, function (next) { setTimeout(next, 11000) @@ -72,10 +81,10 @@ describe('Test multiple pods', function () { function (err) { if (err) throw err - async.each(urls, function (url, callback) { - let base_magnet = null + async.each(servers, function (server, callback) { + let baseMagnet = null - utils.getVideosList(url, function (err, res) { + utils.getVideosList(server.url, function (err, res) { if (err) throw err const videos = res.body @@ -86,15 +95,27 @@ describe('Test multiple pods', function () { expect(video.description).to.equal('my super description for pod 1') expect(video.podUrl).to.equal('http://localhost:9001') expect(video.magnetUri).to.exist + expect(video.duration).to.equal(10) + + if (server.url !== 'http://localhost:9001') { + expect(video.isLocal).to.be.false + } else { + expect(video.isLocal).to.be.true + } // All pods should have the same magnet Uri - if (base_magnet === null) { - base_magnet = video.magnetUri + if (baseMagnet === null) { + baseMagnet = video.magnetUri } else { expect(video.magnetUri).to.equal.magnetUri } - callback() + utils.testImage(server.url, 'video_short1.webm', video.thumbnailPath, function (err, test) { + if (err) throw err + expect(test).to.equal(true) + + callback() + }) }) }, done) } @@ -106,7 +127,7 @@ describe('Test multiple pods', function () { async.series([ function (next) { - utils.uploadVideo(urls[1], 'my super name for pod 2', 'my super description for pod 2', 'video_short2.webm', next) + utils.uploadVideo(servers[1].url, servers[1].access_token, 'my super name for pod 2', 'my super description for pod 2', 'video_short2.webm', next) }, function (next) { setTimeout(next, 11000) @@ -115,10 +136,10 @@ describe('Test multiple pods', function () { function (err) { if (err) throw err - async.each(urls, function (url, callback) { - let base_magnet = null + async.each(servers, function (server, callback) { + let baseMagnet = null - utils.getVideosList(url, function (err, res) { + utils.getVideosList(server.url, function (err, res) { if (err) throw err const videos = res.body @@ -129,15 +150,27 @@ describe('Test multiple pods', function () { expect(video.description).to.equal('my super description for pod 2') expect(video.podUrl).to.equal('http://localhost:9002') expect(video.magnetUri).to.exist + expect(video.duration).to.equal(5) + + if (server.url !== 'http://localhost:9002') { + expect(video.isLocal).to.be.false + } else { + expect(video.isLocal).to.be.true + } // All pods should have the same magnet Uri - if (base_magnet === null) { - base_magnet = video.magnetUri + if (baseMagnet === null) { + baseMagnet = video.magnetUri } else { expect(video.magnetUri).to.equal.magnetUri } - callback() + utils.testImage(server.url, 'video_short2.webm', video.thumbnailPath, function (err, test) { + if (err) throw err + expect(test).to.equal(true) + + callback() + }) }) }, done) } @@ -149,10 +182,10 @@ describe('Test multiple pods', function () { async.series([ function (next) { - utils.uploadVideo(urls[2], 'my super name for pod 3', 'my super description for pod 3', 'video_short3.webm', next) + utils.uploadVideo(servers[2].url, servers[2].access_token, 'my super name for pod 3', 'my super description for pod 3', 'video_short3.webm', next) }, function (next) { - utils.uploadVideo(urls[2], 'my super name for pod 3-2', 'my super description for pod 3-2', 'video_short.webm', next) + utils.uploadVideo(servers[2].url, servers[2].access_token, 'my super name for pod 3-2', 'my super description for pod 3-2', 'video_short.webm', next) }, function (next) { setTimeout(next, 22000) @@ -160,35 +193,65 @@ describe('Test multiple pods', function () { function (err) { if (err) throw err - let base_magnet = null + let baseMagnet = null // All pods should have this video - async.each(urls, function (url, callback) { - utils.getVideosList(url, function (err, res) { + async.each(servers, function (server, callback) { + utils.getVideosList(server.url, function (err, res) { if (err) throw err const videos = res.body expect(videos).to.be.an('array') expect(videos.length).to.equal(4) - let video = videos[2] - expect(video.name).to.equal('my super name for pod 3') - expect(video.description).to.equal('my super description for pod 3') - expect(video.podUrl).to.equal('http://localhost:9003') - expect(video.magnetUri).to.exist - video = videos[3] - expect(video.name).to.equal('my super name for pod 3-2') - expect(video.description).to.equal('my super description for pod 3-2') - expect(video.podUrl).to.equal('http://localhost:9003') - expect(video.magnetUri).to.exist + // We not sure about the order of the two last uploads + let video1 = null + let video2 = null + if (videos[2].name === 'my super name for pod 3') { + video1 = videos[2] + video2 = videos[3] + } else { + video1 = videos[3] + video2 = videos[2] + } + + expect(video1.name).to.equal('my super name for pod 3') + expect(video1.description).to.equal('my super description for pod 3') + expect(video1.podUrl).to.equal('http://localhost:9003') + expect(video1.magnetUri).to.exist + expect(video1.duration).to.equal(5) + + expect(video2.name).to.equal('my super name for pod 3-2') + expect(video2.description).to.equal('my super description for pod 3-2') + expect(video2.podUrl).to.equal('http://localhost:9003') + expect(video2.magnetUri).to.exist + expect(video2.duration).to.equal(5) + + if (server.url !== 'http://localhost:9003') { + expect(video1.isLocal).to.be.false + expect(video2.isLocal).to.be.false + } else { + expect(video1.isLocal).to.be.true + expect(video2.isLocal).to.be.true + } // All pods should have the same magnet Uri - if (base_magnet === null) { - base_magnet = video.magnetUri + if (baseMagnet === null) { + baseMagnet = video2.magnetUri } else { - expect(video.magnetUri).to.equal.magnetUri + expect(video2.magnetUri).to.equal.magnetUri } - callback() + utils.testImage(server.url, 'video_short3.webm', video1.thumbnailPath, function (err, test) { + if (err) throw err + expect(test).to.equal(true) + + utils.testImage(server.url, 'video_short.webm', video2.thumbnailPath, function (err, test) { + if (err) throw err + expect(test).to.equal(true) + + callback() + }) + }) }) }, done) } @@ -201,12 +264,12 @@ describe('Test multiple pods', function () { // Yes, this could be long this.timeout(200000) - utils.getVideosList(urls[2], function (err, res) { + utils.getVideosList(servers[2].url, function (err, res) { if (err) throw err const video = res.body[0] - to_remove.push(res.body[2]._id) - to_remove.push(res.body[3]._id) + toRemove.push(res.body[2].id) + toRemove.push(res.body[3].id) webtorrent.add(video.magnetUri, function (torrent) { expect(torrent.files).to.exist @@ -222,7 +285,7 @@ describe('Test multiple pods', function () { // Yes, this could be long this.timeout(200000) - utils.getVideosList(urls[0], function (err, res) { + utils.getVideosList(servers[0].url, function (err, res) { if (err) throw err const video = res.body[1] @@ -241,7 +304,7 @@ describe('Test multiple pods', function () { // Yes, this could be long this.timeout(200000) - utils.getVideosList(urls[1], function (err, res) { + utils.getVideosList(servers[1].url, function (err, res) { if (err) throw err const video = res.body[2] @@ -260,7 +323,7 @@ describe('Test multiple pods', function () { // Yes, this could be long this.timeout(200000) - utils.getVideosList(urls[0], function (err, res) { + utils.getVideosList(servers[0].url, function (err, res) { if (err) throw err const video = res.body[3] @@ -280,10 +343,10 @@ describe('Test multiple pods', function () { async.series([ function (next) { - utils.removeVideo(urls[2], to_remove[0], next) + utils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[0], next) }, function (next) { - utils.removeVideo(urls[2], to_remove[1], next) + utils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[1], next) }], function (err) { if (err) throw err @@ -293,18 +356,18 @@ describe('Test multiple pods', function () { }) it('Should have videos 1 and 3 on each pod', function (done) { - async.each(urls, function (url, callback) { - utils.getVideosList(url, function (err, res) { + async.each(servers, function (server, callback) { + utils.getVideosList(server.url, function (err, res) { if (err) throw err const videos = res.body expect(videos).to.be.an('array') expect(videos.length).to.equal(2) - expect(videos[0]._id).not.to.equal(videos[1]._id) - expect(videos[0]._id).not.to.equal(to_remove[0]) - expect(videos[1]._id).not.to.equal(to_remove[0]) - expect(videos[0]._id).not.to.equal(to_remove[1]) - expect(videos[1]._id).not.to.equal(to_remove[1]) + expect(videos[0].id).not.to.equal(videos[1].id) + expect(videos[0].id).not.to.equal(toRemove[0]) + expect(videos[1].id).not.to.equal(toRemove[0]) + expect(videos[0].id).not.to.equal(toRemove[1]) + expect(videos[1].id).not.to.equal(toRemove[1]) callback() }) @@ -313,8 +376,8 @@ describe('Test multiple pods', function () { }) after(function (done) { - apps.forEach(function (app) { - process.kill(-app.pid) + servers.forEach(function (server) { + process.kill(-server.app.pid) }) process.kill(-webtorrent.app.pid)