]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/multiplePods.js
3 const async
= require('async')
4 const chai
= require('chai')
5 const expect
= chai
.expect
6 const pathUtils
= require('path')
8 const utils
= require('./utils')
9 const webtorrent
= require(pathUtils
.join(__dirname
, '../../lib/webtorrent'))
10 webtorrent
.silent
= true
12 describe('Test multiple pods', function () {
16 before(function (done
) {
22 utils
.flushAndRunMultipleServers(3, function (servers_run
) {
27 // Get the access tokens
29 async
.each(servers
, function (server
, callback_each
) {
30 utils
.loginAndGetAccessToken(server
, function (err
, access_token
) {
31 if (err
) return callback_each(err
)
33 server
.access_token
= access_token
38 // The second pod make friend with the third
40 utils
.makeFriends(servers
[1].url
, next
)
42 // Wait for the request between pods
44 setTimeout(next
, 10000)
46 // Pod 1 make friends too
48 utils
.makeFriends(servers
[0].url
, next
)
51 webtorrent
.create({ host: 'client', port: '1' }, next
)
56 it('Should not have videos for all pods', function (done
) {
57 async
.each(servers
, function (server
, callback
) {
58 utils
.getVideosList(server
.url
, function (err
, res
) {
61 expect(res
.body
).to
.be
.an('array')
62 expect(res
.body
.length
).to
.equal(0)
69 describe('Should upload the video and propagate on each pod', function () {
70 it('Should upload the video on pod 1 and propagate on each pod', function (done
) {
75 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
)
78 setTimeout(next
, 11000)
80 // All pods should have this video
84 async
.each(servers
, function (server
, callback
) {
85 let base_magnet
= null
87 utils
.getVideosList(server
.url
, function (err
, res
) {
90 const videos
= res
.body
91 expect(videos
).to
.be
.an('array')
92 expect(videos
.length
).to
.equal(1)
93 const video
= videos
[0]
94 expect(video
.name
).to
.equal('my super name for pod 1')
95 expect(video
.description
).to
.equal('my super description for pod 1')
96 expect(video
.podUrl
).to
.equal('http://localhost:9001')
97 expect(video
.magnetUri
).to
.exist
98 expect(video
.duration
).to
.equal(10)
100 if (server
.url
!== 'http://localhost:9001') {
101 expect(video
.isLocal
).to
.be
.false
103 expect(video
.isLocal
).to
.be
.true
106 // All pods should have the same magnet Uri
107 if (base_magnet
=== null) {
108 base_magnet
= video
.magnetUri
110 expect(video
.magnetUri
).to
.equal
.magnetUri
113 utils
.testImage(server
.url
, 'video_short1.webm', video
.thumbnailPath
, function (err
, test
) {
115 expect(test
).to
.equal(true)
125 it('Should upload the video on pod 2 and propagate on each pod', function (done
) {
130 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
)
133 setTimeout(next
, 11000)
135 // All pods should have this video
139 async
.each(servers
, function (server
, callback
) {
140 let base_magnet
= null
142 utils
.getVideosList(server
.url
, function (err
, res
) {
145 const videos
= res
.body
146 expect(videos
).to
.be
.an('array')
147 expect(videos
.length
).to
.equal(2)
148 const video
= videos
[1]
149 expect(video
.name
).to
.equal('my super name for pod 2')
150 expect(video
.description
).to
.equal('my super description for pod 2')
151 expect(video
.podUrl
).to
.equal('http://localhost:9002')
152 expect(video
.magnetUri
).to
.exist
153 expect(video
.duration
).to
.equal(5)
155 if (server
.url
!== 'http://localhost:9002') {
156 expect(video
.isLocal
).to
.be
.false
158 expect(video
.isLocal
).to
.be
.true
161 // All pods should have the same magnet Uri
162 if (base_magnet
=== null) {
163 base_magnet
= video
.magnetUri
165 expect(video
.magnetUri
).to
.equal
.magnetUri
168 utils
.testImage(server
.url
, 'video_short2.webm', video
.thumbnailPath
, function (err
, test
) {
170 expect(test
).to
.equal(true)
180 it('Should upload two videos on pod 3 and propagate on each pod', function (done
) {
185 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
)
188 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
)
191 setTimeout(next
, 22000)
196 let base_magnet
= null
197 // All pods should have this video
198 async
.each(servers
, function (server
, callback
) {
199 utils
.getVideosList(server
.url
, function (err
, res
) {
202 const videos
= res
.body
203 expect(videos
).to
.be
.an('array')
204 expect(videos
.length
).to
.equal(4)
206 // We not sure about the order of the two last uploads
209 if (videos
[2].name
=== 'my super name for pod 3') {
217 expect(video1
.name
).to
.equal('my super name for pod 3')
218 expect(video1
.description
).to
.equal('my super description for pod 3')
219 expect(video1
.podUrl
).to
.equal('http://localhost:9003')
220 expect(video1
.magnetUri
).to
.exist
221 expect(video1
.duration
).to
.equal(5)
223 expect(video2
.name
).to
.equal('my super name for pod 3-2')
224 expect(video2
.description
).to
.equal('my super description for pod 3-2')
225 expect(video2
.podUrl
).to
.equal('http://localhost:9003')
226 expect(video2
.magnetUri
).to
.exist
227 expect(video2
.duration
).to
.equal(5)
229 if (server
.url
!== 'http://localhost:9003') {
230 expect(video1
.isLocal
).to
.be
.false
231 expect(video2
.isLocal
).to
.be
.false
233 expect(video1
.isLocal
).to
.be
.true
234 expect(video2
.isLocal
).to
.be
.true
237 // All pods should have the same magnet Uri
238 if (base_magnet
=== null) {
239 base_magnet
= video2
.magnetUri
241 expect(video2
.magnetUri
).to
.equal
.magnetUri
244 utils
.testImage(server
.url
, 'video_short3.webm', video1
.thumbnailPath
, function (err
, test
) {
246 expect(test
).to
.equal(true)
248 utils
.testImage(server
.url
, 'video_short.webm', video2
.thumbnailPath
, function (err
, test
) {
250 expect(test
).to
.equal(true)
262 describe('Should seed the uploaded video', function () {
263 it('Should add the file 1 by asking pod 3', function (done
) {
264 // Yes, this could be long
267 utils
.getVideosList(servers
[2].url
, function (err
, res
) {
270 const video
= res
.body
[0]
271 to_remove
.push(res
.body
[2].id
)
272 to_remove
.push(res
.body
[3].id
)
274 webtorrent
.add(video
.magnetUri
, function (torrent
) {
275 expect(torrent
.files
).to
.exist
276 expect(torrent
.files
.length
).to
.equal(1)
277 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
284 it('Should add the file 2 by asking pod 1', function (done
) {
285 // Yes, this could be long
288 utils
.getVideosList(servers
[0].url
, function (err
, res
) {
291 const video
= res
.body
[1]
293 webtorrent
.add(video
.magnetUri
, function (torrent
) {
294 expect(torrent
.files
).to
.exist
295 expect(torrent
.files
.length
).to
.equal(1)
296 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
303 it('Should add the file 3 by asking pod 2', function (done
) {
304 // Yes, this could be long
307 utils
.getVideosList(servers
[1].url
, function (err
, res
) {
310 const video
= res
.body
[2]
312 webtorrent
.add(video
.magnetUri
, function (torrent
) {
313 expect(torrent
.files
).to
.exist
314 expect(torrent
.files
.length
).to
.equal(1)
315 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
322 it('Should add the file 3-2 by asking pod 1', function (done
) {
323 // Yes, this could be long
326 utils
.getVideosList(servers
[0].url
, function (err
, res
) {
329 const video
= res
.body
[3]
331 webtorrent
.add(video
.magnetUri
, function (torrent
) {
332 expect(torrent
.files
).to
.exist
333 expect(torrent
.files
.length
).to
.equal(1)
334 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
341 it('Should remove the file 3 and 3-2 by asking pod 3', function (done
) {
346 utils
.removeVideo(servers
[2].url
, servers
[2].access_token
, to_remove
[0], next
)
349 utils
.removeVideo(servers
[2].url
, servers
[2].access_token
, to_remove
[1], next
)
353 setTimeout(done
, 11000)
358 it('Should have videos 1 and 3 on each pod', function (done
) {
359 async
.each(servers
, function (server
, callback
) {
360 utils
.getVideosList(server
.url
, function (err
, res
) {
363 const videos
= res
.body
364 expect(videos
).to
.be
.an('array')
365 expect(videos
.length
).to
.equal(2)
366 expect(videos
[0].id
).not
.to
.equal(videos
[1].id
)
367 expect(videos
[0].id
).not
.to
.equal(to_remove
[0])
368 expect(videos
[1].id
).not
.to
.equal(to_remove
[0])
369 expect(videos
[0].id
).not
.to
.equal(to_remove
[1])
370 expect(videos
[1].id
).not
.to
.equal(to_remove
[1])
378 after(function (done
) {
379 servers
.forEach(function (server
) {
380 process
.kill(-server
.app
.pid
)
382 process
.kill(-webtorrent
.app
.pid
)
384 // Keep the logs if the test failed
386 utils
.flushTests(done
)