]>
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 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)
102 if (server
.url
!== 'http://localhost:9001') {
103 expect(video
.isLocal
).to
.be
.false
105 expect(video
.isLocal
).to
.be
.true
108 // All pods should have the same magnet Uri
109 if (baseMagnet
=== null) {
110 baseMagnet
= video
.magnetUri
112 expect(video
.magnetUri
).to
.equal
.magnetUri
115 utils
.testImage(server
.url
, 'video_short1.webm', video
.thumbnailPath
, function (err
, test
) {
117 expect(test
).to
.equal(true)
127 it('Should upload the video on pod 2 and propagate on each pod', function (done
) {
132 utils
.uploadVideo(servers
[1].url
, servers
[1].accessToken
, 'my super name for pod 2', 'my super description for pod 2', 'video_short2.webm', next
)
135 setTimeout(next
, 11000)
137 // All pods should have this video
141 async
.each(servers
, function (server
, callback
) {
142 let baseMagnet
= null
144 utils
.getVideosList(server
.url
, function (err
, res
) {
147 const videos
= res
.body
148 expect(videos
).to
.be
.an('array')
149 expect(videos
.length
).to
.equal(2)
150 const video
= videos
[1]
151 expect(video
.name
).to
.equal('my super name for pod 2')
152 expect(video
.description
).to
.equal('my super description for pod 2')
153 expect(video
.podUrl
).to
.equal('http://localhost:9002')
154 expect(video
.magnetUri
).to
.exist
155 expect(video
.duration
).to
.equal(5)
157 if (server
.url
!== 'http://localhost:9002') {
158 expect(video
.isLocal
).to
.be
.false
160 expect(video
.isLocal
).to
.be
.true
163 // All pods should have the same magnet Uri
164 if (baseMagnet
=== null) {
165 baseMagnet
= video
.magnetUri
167 expect(video
.magnetUri
).to
.equal
.magnetUri
170 utils
.testImage(server
.url
, 'video_short2.webm', video
.thumbnailPath
, function (err
, test
) {
172 expect(test
).to
.equal(true)
182 it('Should upload two videos on pod 3 and propagate on each pod', function (done
) {
187 utils
.uploadVideo(servers
[2].url
, servers
[2].accessToken
, 'my super name for pod 3', 'my super description for pod 3', 'video_short3.webm', next
)
190 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
)
193 setTimeout(next
, 22000)
198 let baseMagnet
= null
199 // All pods should have this video
200 async
.each(servers
, function (server
, callback
) {
201 utils
.getVideosList(server
.url
, function (err
, res
) {
204 const videos
= res
.body
205 expect(videos
).to
.be
.an('array')
206 expect(videos
.length
).to
.equal(4)
208 // We not sure about the order of the two last uploads
211 if (videos
[2].name
=== 'my super name for pod 3') {
219 expect(video1
.name
).to
.equal('my super name for pod 3')
220 expect(video1
.description
).to
.equal('my super description for pod 3')
221 expect(video1
.podUrl
).to
.equal('http://localhost:9003')
222 expect(video1
.magnetUri
).to
.exist
223 expect(video1
.duration
).to
.equal(5)
225 expect(video2
.name
).to
.equal('my super name for pod 3-2')
226 expect(video2
.description
).to
.equal('my super description for pod 3-2')
227 expect(video2
.podUrl
).to
.equal('http://localhost:9003')
228 expect(video2
.magnetUri
).to
.exist
229 expect(video2
.duration
).to
.equal(5)
231 if (server
.url
!== 'http://localhost:9003') {
232 expect(video1
.isLocal
).to
.be
.false
233 expect(video2
.isLocal
).to
.be
.false
235 expect(video1
.isLocal
).to
.be
.true
236 expect(video2
.isLocal
).to
.be
.true
239 // All pods should have the same magnet Uri
240 if (baseMagnet
=== null) {
241 baseMagnet
= video2
.magnetUri
243 expect(video2
.magnetUri
).to
.equal
.magnetUri
246 utils
.testImage(server
.url
, 'video_short3.webm', video1
.thumbnailPath
, function (err
, test
) {
248 expect(test
).to
.equal(true)
250 utils
.testImage(server
.url
, 'video_short.webm', video2
.thumbnailPath
, function (err
, test
) {
252 expect(test
).to
.equal(true)
264 describe('Should seed the uploaded video', function () {
265 it('Should add the file 1 by asking pod 3', function (done
) {
266 // Yes, this could be long
269 utils
.getVideosList(servers
[2].url
, function (err
, res
) {
272 const video
= res
.body
[0]
273 toRemove
.push(res
.body
[2].id
)
274 toRemove
.push(res
.body
[3].id
)
276 webtorrent
.add(video
.magnetUri
, function (torrent
) {
277 expect(torrent
.files
).to
.exist
278 expect(torrent
.files
.length
).to
.equal(1)
279 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
286 it('Should add the file 2 by asking pod 1', function (done
) {
287 // Yes, this could be long
290 utils
.getVideosList(servers
[0].url
, function (err
, res
) {
293 const video
= res
.body
[1]
295 webtorrent
.add(video
.magnetUri
, function (torrent
) {
296 expect(torrent
.files
).to
.exist
297 expect(torrent
.files
.length
).to
.equal(1)
298 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
305 it('Should add the file 3 by asking pod 2', function (done
) {
306 // Yes, this could be long
309 utils
.getVideosList(servers
[1].url
, function (err
, res
) {
312 const video
= res
.body
[2]
314 webtorrent
.add(video
.magnetUri
, function (torrent
) {
315 expect(torrent
.files
).to
.exist
316 expect(torrent
.files
.length
).to
.equal(1)
317 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
319 webtorrent
.remove(video
.magnetUri
, done
)
324 it('Should add the file 3-2 by asking pod 1', function (done
) {
325 // Yes, this could be long
328 utils
.getVideosList(servers
[0].url
, function (err
, res
) {
331 const video
= res
.body
[3]
333 webtorrent
.add(video
.magnetUri
, function (torrent
) {
334 expect(torrent
.files
).to
.exist
335 expect(torrent
.files
.length
).to
.equal(1)
336 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
343 it('Should remove the file 3 and 3-2 by asking pod 3', function (done
) {
348 utils
.removeVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[0], next
)
351 utils
.removeVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[1], next
)
355 setTimeout(done
, 11000)
360 it('Should have videos 1 and 3 on each pod', function (done
) {
361 async
.each(servers
, function (server
, callback
) {
362 utils
.getVideosList(server
.url
, function (err
, res
) {
365 const videos
= res
.body
366 expect(videos
).to
.be
.an('array')
367 expect(videos
.length
).to
.equal(2)
368 expect(videos
[0].id
).not
.to
.equal(videos
[1].id
)
369 expect(videos
[0].id
).not
.to
.equal(toRemove
[0])
370 expect(videos
[1].id
).not
.to
.equal(toRemove
[0])
371 expect(videos
[0].id
).not
.to
.equal(toRemove
[1])
372 expect(videos
[1].id
).not
.to
.equal(toRemove
[1])
380 after(function (done
) {
381 servers
.forEach(function (server
) {
382 process
.kill(-server
.app
.pid
)
384 process
.kill(-webtorrent
.app
.pid
)
386 // Keep the logs if the test failed
388 utils
.flushTests(done
)