]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/multiplePods.js
c31c18b0254125dfe9d7391e0761986eabcf49f7
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 (serversRun
) {
27 // Get the access tokens
29 async
.each(servers
, function (server
, callbackEach
) {
30 utils
.loginAndGetAccessToken(server
, function (err
, accessToken
) {
31 if (err
) return callbackEach(err
)
33 server
.accessToken
= accessToken
38 // The second pod make friend with the third
40 const server
= servers
[1]
41 utils
.makeFriends(server
.url
, server
.accessToken
, next
)
43 // Wait for the request between pods
45 setTimeout(next
, 10000)
47 // Pod 1 make friends too
49 const server
= servers
[0]
50 utils
.makeFriends(server
.url
, server
.accessToken
, next
)
53 webtorrent
.create({ host: 'client', port: '1' }, next
)
58 it('Should not have videos for all pods', function (done
) {
59 async
.each(servers
, function (server
, callback
) {
60 utils
.getVideosList(server
.url
, function (err
, res
) {
63 expect(res
.body
).to
.be
.an('array')
64 expect(res
.body
.length
).to
.equal(0)
71 describe('Should upload the video and propagate on each pod', function () {
72 it('Should upload the video on pod 1 and propagate on each pod', function (done
) {
77 utils
.uploadVideo(servers
[0].url
, servers
[0].accessToken
, 'my super name for pod 1', 'my super description for pod 1', 'video_short1.webm', next
)
80 setTimeout(next
, 11000)
82 // All pods should have this video
86 async
.each(servers
, function (server
, callback
) {
89 utils
.getVideosList(server
.url
, function (err
, res
) {
92 const videos
= res
.body
93 expect(videos
).to
.be
.an('array')
94 expect(videos
.length
).to
.equal(1)
95 const video
= videos
[0]
96 expect(video
.name
).to
.equal('my super name for pod 1')
97 expect(video
.description
).to
.equal('my super description for pod 1')
98 expect(video
.podUrl
).to
.equal('http://localhost:9001')
99 expect(video
.magnetUri
).to
.exist
100 expect(video
.duration
).to
.equal(10)
101 expect(utils
.dateIsValid(video
.createdDate
)).to
.be
.true
103 if (server
.url
!== 'http://localhost:9001') {
104 expect(video
.isLocal
).to
.be
.false
106 expect(video
.isLocal
).to
.be
.true
109 // All pods should have the same magnet Uri
110 if (baseMagnet
=== null) {
111 baseMagnet
= video
.magnetUri
113 expect(video
.magnetUri
).to
.equal
.magnetUri
116 utils
.testImage(server
.url
, 'video_short1.webm', video
.thumbnailPath
, function (err
, test
) {
118 expect(test
).to
.equal(true)
128 it('Should upload the video on pod 2 and propagate on each pod', function (done
) {
133 utils
.uploadVideo(servers
[1].url
, servers
[1].accessToken
, 'my super name for pod 2', 'my super description for pod 2', 'video_short2.webm', next
)
136 setTimeout(next
, 11000)
138 // All pods should have this video
142 async
.each(servers
, function (server
, callback
) {
143 let baseMagnet
= null
145 utils
.getVideosList(server
.url
, function (err
, res
) {
148 const videos
= res
.body
149 expect(videos
).to
.be
.an('array')
150 expect(videos
.length
).to
.equal(2)
151 const video
= videos
[1]
152 expect(video
.name
).to
.equal('my super name for pod 2')
153 expect(video
.description
).to
.equal('my super description for pod 2')
154 expect(video
.podUrl
).to
.equal('http://localhost:9002')
155 expect(video
.magnetUri
).to
.exist
156 expect(video
.duration
).to
.equal(5)
157 expect(utils
.dateIsValid(video
.createdDate
)).to
.be
.true
159 if (server
.url
!== 'http://localhost:9002') {
160 expect(video
.isLocal
).to
.be
.false
162 expect(video
.isLocal
).to
.be
.true
165 // All pods should have the same magnet Uri
166 if (baseMagnet
=== null) {
167 baseMagnet
= video
.magnetUri
169 expect(video
.magnetUri
).to
.equal
.magnetUri
172 utils
.testImage(server
.url
, 'video_short2.webm', video
.thumbnailPath
, function (err
, test
) {
174 expect(test
).to
.equal(true)
184 it('Should upload two videos on pod 3 and propagate on each pod', function (done
) {
189 utils
.uploadVideo(servers
[2].url
, servers
[2].accessToken
, 'my super name for pod 3', 'my super description for pod 3', 'video_short3.webm', next
)
192 utils
.uploadVideo(servers
[2].url
, servers
[2].accessToken
, 'my super name for pod 3-2', 'my super description for pod 3-2', 'video_short.webm', next
)
195 setTimeout(next
, 22000)
200 let baseMagnet
= null
201 // All pods should have this video
202 async
.each(servers
, function (server
, callback
) {
203 utils
.getVideosList(server
.url
, function (err
, res
) {
206 const videos
= res
.body
207 expect(videos
).to
.be
.an('array')
208 expect(videos
.length
).to
.equal(4)
210 // We not sure about the order of the two last uploads
213 if (videos
[2].name
=== 'my super name for pod 3') {
221 expect(video1
.name
).to
.equal('my super name for pod 3')
222 expect(video1
.description
).to
.equal('my super description for pod 3')
223 expect(video1
.podUrl
).to
.equal('http://localhost:9003')
224 expect(video1
.magnetUri
).to
.exist
225 expect(video1
.duration
).to
.equal(5)
226 expect(utils
.dateIsValid(video1
.createdDate
)).to
.be
.true
228 expect(video2
.name
).to
.equal('my super name for pod 3-2')
229 expect(video2
.description
).to
.equal('my super description for pod 3-2')
230 expect(video2
.podUrl
).to
.equal('http://localhost:9003')
231 expect(video2
.magnetUri
).to
.exist
232 expect(video2
.duration
).to
.equal(5)
233 expect(utils
.dateIsValid(video2
.createdDate
)).to
.be
.true
235 if (server
.url
!== 'http://localhost:9003') {
236 expect(video1
.isLocal
).to
.be
.false
237 expect(video2
.isLocal
).to
.be
.false
239 expect(video1
.isLocal
).to
.be
.true
240 expect(video2
.isLocal
).to
.be
.true
243 // All pods should have the same magnet Uri
244 if (baseMagnet
=== null) {
245 baseMagnet
= video2
.magnetUri
247 expect(video2
.magnetUri
).to
.equal
.magnetUri
250 utils
.testImage(server
.url
, 'video_short3.webm', video1
.thumbnailPath
, function (err
, test
) {
252 expect(test
).to
.equal(true)
254 utils
.testImage(server
.url
, 'video_short.webm', video2
.thumbnailPath
, function (err
, test
) {
256 expect(test
).to
.equal(true)
268 describe('Should seed the uploaded video', function () {
269 it('Should add the file 1 by asking pod 3', function (done
) {
270 // Yes, this could be long
273 utils
.getVideosList(servers
[2].url
, function (err
, res
) {
276 const video
= res
.body
[0]
277 toRemove
.push(res
.body
[2].id
)
278 toRemove
.push(res
.body
[3].id
)
280 webtorrent
.add(video
.magnetUri
, function (torrent
) {
281 expect(torrent
.files
).to
.exist
282 expect(torrent
.files
.length
).to
.equal(1)
283 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
290 it('Should add the file 2 by asking pod 1', function (done
) {
291 // Yes, this could be long
294 utils
.getVideosList(servers
[0].url
, function (err
, res
) {
297 const video
= res
.body
[1]
299 webtorrent
.add(video
.magnetUri
, function (torrent
) {
300 expect(torrent
.files
).to
.exist
301 expect(torrent
.files
.length
).to
.equal(1)
302 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
309 it('Should add the file 3 by asking pod 2', function (done
) {
310 // Yes, this could be long
313 utils
.getVideosList(servers
[1].url
, function (err
, res
) {
316 const video
= res
.body
[2]
318 webtorrent
.add(video
.magnetUri
, function (torrent
) {
319 expect(torrent
.files
).to
.exist
320 expect(torrent
.files
.length
).to
.equal(1)
321 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
323 webtorrent
.remove(video
.magnetUri
, done
)
328 it('Should add the file 3-2 by asking pod 1', function (done
) {
329 // Yes, this could be long
332 utils
.getVideosList(servers
[0].url
, function (err
, res
) {
335 const video
= res
.body
[3]
337 webtorrent
.add(video
.magnetUri
, function (torrent
) {
338 expect(torrent
.files
).to
.exist
339 expect(torrent
.files
.length
).to
.equal(1)
340 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
347 it('Should remove the file 3 and 3-2 by asking pod 3', function (done
) {
352 utils
.removeVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[0], next
)
355 utils
.removeVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[1], next
)
359 setTimeout(done
, 11000)
364 it('Should have videos 1 and 3 on each pod', function (done
) {
365 async
.each(servers
, function (server
, callback
) {
366 utils
.getVideosList(server
.url
, function (err
, res
) {
369 const videos
= res
.body
370 expect(videos
).to
.be
.an('array')
371 expect(videos
.length
).to
.equal(2)
372 expect(videos
[0].id
).not
.to
.equal(videos
[1].id
)
373 expect(videos
[0].id
).not
.to
.equal(toRemove
[0])
374 expect(videos
[1].id
).not
.to
.equal(toRemove
[0])
375 expect(videos
[0].id
).not
.to
.equal(toRemove
[1])
376 expect(videos
[1].id
).not
.to
.equal(toRemove
[1])
384 after(function (done
) {
385 servers
.forEach(function (server
) {
386 process
.kill(-server
.app
.pid
)
388 process
.kill(-webtorrent
.app
.pid
)
390 // Keep the logs if the test failed
392 utils
.flushTests(done
)