]>
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 (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 const videos
= res
.body
.data
64 expect(videos
).to
.be
.an('array')
65 expect(videos
.length
).to
.equal(0)
72 describe('Should upload the video and propagate on each pod', function () {
73 it('Should upload the video on pod 1 and propagate on each pod', function (done
) {
78 utils
.uploadVideo(servers
[0].url
, servers
[0].accessToken
, 'my super name for pod 1', 'my super description for pod 1', 'video_short1.webm', next
)
81 setTimeout(next
, 11000)
83 // All pods should have this video
87 async
.each(servers
, function (server
, callback
) {
90 utils
.getVideosList(server
.url
, function (err
, res
) {
93 const videos
= res
.body
.data
94 expect(videos
).to
.be
.an('array')
95 expect(videos
.length
).to
.equal(1)
96 const video
= videos
[0]
97 expect(video
.name
).to
.equal('my super name for pod 1')
98 expect(video
.description
).to
.equal('my super description for pod 1')
99 expect(video
.podUrl
).to
.equal('localhost:9001')
100 expect(video
.magnetUri
).to
.exist
101 expect(video
.duration
).to
.equal(10)
102 expect(utils
.dateIsValid(video
.createdDate
)).to
.be
.true
104 if (server
.url
!== 'http://localhost:9001') {
105 expect(video
.isLocal
).to
.be
.false
107 expect(video
.isLocal
).to
.be
.true
110 // All pods should have the same magnet Uri
111 if (baseMagnet
=== null) {
112 baseMagnet
= video
.magnetUri
114 expect(video
.magnetUri
).to
.equal
.magnetUri
117 utils
.testImage(server
.url
, 'video_short1.webm', video
.thumbnailPath
, function (err
, test
) {
119 expect(test
).to
.equal(true)
129 it('Should upload the video on pod 2 and propagate on each pod', function (done
) {
134 utils
.uploadVideo(servers
[1].url
, servers
[1].accessToken
, 'my super name for pod 2', 'my super description for pod 2', 'video_short2.webm', next
)
137 setTimeout(next
, 11000)
139 // All pods should have this video
143 async
.each(servers
, function (server
, callback
) {
144 let baseMagnet
= null
146 utils
.getVideosList(server
.url
, function (err
, res
) {
149 const videos
= res
.body
.data
150 expect(videos
).to
.be
.an('array')
151 expect(videos
.length
).to
.equal(2)
152 const video
= videos
[1]
153 expect(video
.name
).to
.equal('my super name for pod 2')
154 expect(video
.description
).to
.equal('my super description for pod 2')
155 expect(video
.podUrl
).to
.equal('localhost:9002')
156 expect(video
.magnetUri
).to
.exist
157 expect(video
.duration
).to
.equal(5)
158 expect(utils
.dateIsValid(video
.createdDate
)).to
.be
.true
160 if (server
.url
!== 'http://localhost:9002') {
161 expect(video
.isLocal
).to
.be
.false
163 expect(video
.isLocal
).to
.be
.true
166 // All pods should have the same magnet Uri
167 if (baseMagnet
=== null) {
168 baseMagnet
= video
.magnetUri
170 expect(video
.magnetUri
).to
.equal
.magnetUri
173 utils
.testImage(server
.url
, 'video_short2.webm', video
.thumbnailPath
, function (err
, test
) {
175 expect(test
).to
.equal(true)
185 it('Should upload two videos on pod 3 and propagate on each pod', function (done
) {
190 utils
.uploadVideo(servers
[2].url
, servers
[2].accessToken
, 'my super name for pod 3', 'my super description for pod 3', 'video_short3.webm', next
)
193 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
)
196 setTimeout(next
, 22000)
201 let baseMagnet
= null
202 // All pods should have this video
203 async
.each(servers
, function (server
, callback
) {
204 utils
.getVideosList(server
.url
, function (err
, res
) {
207 const videos
= res
.body
.data
208 expect(videos
).to
.be
.an('array')
209 expect(videos
.length
).to
.equal(4)
211 // We not sure about the order of the two last uploads
214 if (videos
[2].name
=== 'my super name for pod 3') {
222 expect(video1
.name
).to
.equal('my super name for pod 3')
223 expect(video1
.description
).to
.equal('my super description for pod 3')
224 expect(video1
.podUrl
).to
.equal('localhost:9003')
225 expect(video1
.magnetUri
).to
.exist
226 expect(video1
.duration
).to
.equal(5)
227 expect(utils
.dateIsValid(video1
.createdDate
)).to
.be
.true
229 expect(video2
.name
).to
.equal('my super name for pod 3-2')
230 expect(video2
.description
).to
.equal('my super description for pod 3-2')
231 expect(video2
.podUrl
).to
.equal('localhost:9003')
232 expect(video2
.magnetUri
).to
.exist
233 expect(video2
.duration
).to
.equal(5)
234 expect(utils
.dateIsValid(video2
.createdDate
)).to
.be
.true
236 if (server
.url
!== 'http://localhost:9003') {
237 expect(video1
.isLocal
).to
.be
.false
238 expect(video2
.isLocal
).to
.be
.false
240 expect(video1
.isLocal
).to
.be
.true
241 expect(video2
.isLocal
).to
.be
.true
244 // All pods should have the same magnet Uri
245 if (baseMagnet
=== null) {
246 baseMagnet
= video2
.magnetUri
248 expect(video2
.magnetUri
).to
.equal
.magnetUri
251 utils
.testImage(server
.url
, 'video_short3.webm', video1
.thumbnailPath
, function (err
, test
) {
253 expect(test
).to
.equal(true)
255 utils
.testImage(server
.url
, 'video_short.webm', video2
.thumbnailPath
, function (err
, test
) {
257 expect(test
).to
.equal(true)
269 describe('Should seed the uploaded video', function () {
270 it('Should add the file 1 by asking pod 3', function (done
) {
271 // Yes, this could be long
274 utils
.getVideosList(servers
[2].url
, function (err
, res
) {
277 const video
= res
.body
.data
[0]
278 toRemove
.push(res
.body
.data
[2].id
)
279 toRemove
.push(res
.body
.data
[3].id
)
281 webtorrent
.add(video
.magnetUri
, function (torrent
) {
282 expect(torrent
.files
).to
.exist
283 expect(torrent
.files
.length
).to
.equal(1)
284 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
291 it('Should add the file 2 by asking pod 1', function (done
) {
292 // Yes, this could be long
295 utils
.getVideosList(servers
[0].url
, function (err
, res
) {
298 const video
= res
.body
.data
[1]
300 webtorrent
.add(video
.magnetUri
, function (torrent
) {
301 expect(torrent
.files
).to
.exist
302 expect(torrent
.files
.length
).to
.equal(1)
303 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
310 it('Should add the file 3 by asking pod 2', function (done
) {
311 // Yes, this could be long
314 utils
.getVideosList(servers
[1].url
, function (err
, res
) {
317 const video
= res
.body
.data
[2]
319 webtorrent
.add(video
.magnetUri
, function (torrent
) {
320 expect(torrent
.files
).to
.exist
321 expect(torrent
.files
.length
).to
.equal(1)
322 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
324 webtorrent
.remove(video
.magnetUri
, done
)
329 it('Should add the file 3-2 by asking pod 1', function (done
) {
330 // Yes, this could be long
333 utils
.getVideosList(servers
[0].url
, function (err
, res
) {
336 const video
= res
.body
.data
[3]
338 webtorrent
.add(video
.magnetUri
, function (torrent
) {
339 expect(torrent
.files
).to
.exist
340 expect(torrent
.files
.length
).to
.equal(1)
341 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
348 it('Should remove the file 3 and 3-2 by asking pod 3', function (done
) {
353 utils
.removeVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[0], next
)
356 utils
.removeVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[1], next
)
360 setTimeout(done
, 11000)
365 it('Should have videos 1 and 3 on each pod', function (done
) {
366 async
.each(servers
, function (server
, callback
) {
367 utils
.getVideosList(server
.url
, function (err
, res
) {
370 const videos
= res
.body
.data
371 expect(videos
).to
.be
.an('array')
372 expect(videos
.length
).to
.equal(2)
373 expect(videos
[0].id
).not
.to
.equal(videos
[1].id
)
374 expect(videos
[0].id
).not
.to
.equal(toRemove
[0])
375 expect(videos
[1].id
).not
.to
.equal(toRemove
[0])
376 expect(videos
[0].id
).not
.to
.equal(toRemove
[1])
377 expect(videos
[1].id
).not
.to
.equal(toRemove
[1])
385 after(function (done
) {
386 servers
.forEach(function (server
) {
387 process
.kill(-server
.app
.pid
)
389 process
.kill(-webtorrent
.app
.pid
)
391 // Keep the logs if the test failed
393 utils
.flushTests(done
)