]>
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 const name
= 'my super name for pod 1'
79 const description
= 'my super description for pod 1'
80 const tags
= [ 'tag1p1', 'tag2p1' ]
81 const file
= 'video_short1.webm'
82 utils
.uploadVideo(servers
[0].url
, servers
[0].accessToken
, name
, description
, tags
, file
, next
)
85 setTimeout(next
, 11000)
87 // All pods should have this video
91 async
.each(servers
, function (server
, callback
) {
94 utils
.getVideosList(server
.url
, function (err
, res
) {
97 const videos
= res
.body
.data
98 expect(videos
).to
.be
.an('array')
99 expect(videos
.length
).to
.equal(1)
100 const video
= videos
[0]
101 expect(video
.name
).to
.equal('my super name for pod 1')
102 expect(video
.description
).to
.equal('my super description for pod 1')
103 expect(video
.podUrl
).to
.equal('localhost:9001')
104 expect(video
.magnetUri
).to
.exist
105 expect(video
.duration
).to
.equal(10)
106 expect(video
.tags
).to
.deep
.equal([ 'tag1p1', 'tag2p1' ])
107 expect(utils
.dateIsValid(video
.createdDate
)).to
.be
.true
109 if (server
.url
!== 'http://localhost:9001') {
110 expect(video
.isLocal
).to
.be
.false
112 expect(video
.isLocal
).to
.be
.true
115 // All pods should have the same magnet Uri
116 if (baseMagnet
=== null) {
117 baseMagnet
= video
.magnetUri
119 expect(video
.magnetUri
).to
.equal
.magnetUri
122 utils
.testImage(server
.url
, 'video_short1.webm', video
.thumbnailPath
, function (err
, test
) {
124 expect(test
).to
.equal(true)
134 it('Should upload the video on pod 2 and propagate on each pod', function (done
) {
139 const name
= 'my super name for pod 2'
140 const description
= 'my super description for pod 2'
141 const tags
= [ 'tag1p2', 'tag2p2', 'tag3p2' ]
142 const file
= 'video_short2.webm'
143 utils
.uploadVideo(servers
[1].url
, servers
[1].accessToken
, name
, description
, tags
, file
, next
)
146 setTimeout(next
, 11000)
148 // All pods should have this video
152 async
.each(servers
, function (server
, callback
) {
153 let baseMagnet
= null
155 utils
.getVideosList(server
.url
, function (err
, res
) {
158 const videos
= res
.body
.data
159 expect(videos
).to
.be
.an('array')
160 expect(videos
.length
).to
.equal(2)
161 const video
= videos
[1]
162 expect(video
.name
).to
.equal('my super name for pod 2')
163 expect(video
.description
).to
.equal('my super description for pod 2')
164 expect(video
.podUrl
).to
.equal('localhost:9002')
165 expect(video
.magnetUri
).to
.exist
166 expect(video
.duration
).to
.equal(5)
167 expect(video
.tags
).to
.deep
.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ])
168 expect(utils
.dateIsValid(video
.createdDate
)).to
.be
.true
170 if (server
.url
!== 'http://localhost:9002') {
171 expect(video
.isLocal
).to
.be
.false
173 expect(video
.isLocal
).to
.be
.true
176 // All pods should have the same magnet Uri
177 if (baseMagnet
=== null) {
178 baseMagnet
= video
.magnetUri
180 expect(video
.magnetUri
).to
.equal
.magnetUri
183 utils
.testImage(server
.url
, 'video_short2.webm', video
.thumbnailPath
, function (err
, test
) {
185 expect(test
).to
.equal(true)
195 it('Should upload two videos on pod 3 and propagate on each pod', function (done
) {
200 const name
= 'my super name for pod 3'
201 const description
= 'my super description for pod 3'
202 const tags
= [ 'tag1p3' ]
203 const file
= 'video_short3.webm'
204 utils
.uploadVideo(servers
[2].url
, servers
[2].accessToken
, name
, description
, tags
, file
, next
)
207 const name
= 'my super name for pod 3-2'
208 const description
= 'my super description for pod 3-2'
209 const tags
= [ 'tag2p3', 'tag3p3', 'tag4p3' ]
210 const file
= 'video_short.webm'
211 utils
.uploadVideo(servers
[2].url
, servers
[2].accessToken
, name
, description
, tags
, file
, next
)
214 setTimeout(next
, 22000)
219 let baseMagnet
= null
220 // All pods should have this video
221 async
.each(servers
, function (server
, callback
) {
222 utils
.getVideosList(server
.url
, function (err
, res
) {
225 const videos
= res
.body
.data
226 expect(videos
).to
.be
.an('array')
227 expect(videos
.length
).to
.equal(4)
229 // We not sure about the order of the two last uploads
232 if (videos
[2].name
=== 'my super name for pod 3') {
240 expect(video1
.name
).to
.equal('my super name for pod 3')
241 expect(video1
.description
).to
.equal('my super description for pod 3')
242 expect(video1
.podUrl
).to
.equal('localhost:9003')
243 expect(video1
.magnetUri
).to
.exist
244 expect(video1
.duration
).to
.equal(5)
245 expect(video1
.tags
).to
.deep
.equal([ 'tag1p3' ])
246 expect(utils
.dateIsValid(video1
.createdDate
)).to
.be
.true
248 expect(video2
.name
).to
.equal('my super name for pod 3-2')
249 expect(video2
.description
).to
.equal('my super description for pod 3-2')
250 expect(video2
.podUrl
).to
.equal('localhost:9003')
251 expect(video2
.magnetUri
).to
.exist
252 expect(video2
.duration
).to
.equal(5)
253 expect(video2
.tags
).to
.deep
.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ])
254 expect(utils
.dateIsValid(video2
.createdDate
)).to
.be
.true
256 if (server
.url
!== 'http://localhost:9003') {
257 expect(video1
.isLocal
).to
.be
.false
258 expect(video2
.isLocal
).to
.be
.false
260 expect(video1
.isLocal
).to
.be
.true
261 expect(video2
.isLocal
).to
.be
.true
264 // All pods should have the same magnet Uri
265 if (baseMagnet
=== null) {
266 baseMagnet
= video2
.magnetUri
268 expect(video2
.magnetUri
).to
.equal
.magnetUri
271 utils
.testImage(server
.url
, 'video_short3.webm', video1
.thumbnailPath
, function (err
, test
) {
273 expect(test
).to
.equal(true)
275 utils
.testImage(server
.url
, 'video_short.webm', video2
.thumbnailPath
, function (err
, test
) {
277 expect(test
).to
.equal(true)
289 describe('Should seed the uploaded video', function () {
290 it('Should add the file 1 by asking pod 3', function (done
) {
291 // Yes, this could be long
294 utils
.getVideosList(servers
[2].url
, function (err
, res
) {
297 const video
= res
.body
.data
[0]
298 toRemove
.push(res
.body
.data
[2].id
)
299 toRemove
.push(res
.body
.data
[3].id
)
301 webtorrent
.add(video
.magnetUri
, function (torrent
) {
302 expect(torrent
.files
).to
.exist
303 expect(torrent
.files
.length
).to
.equal(1)
304 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
311 it('Should add the file 2 by asking pod 1', function (done
) {
312 // Yes, this could be long
315 utils
.getVideosList(servers
[0].url
, function (err
, res
) {
318 const video
= res
.body
.data
[1]
320 webtorrent
.add(video
.magnetUri
, function (torrent
) {
321 expect(torrent
.files
).to
.exist
322 expect(torrent
.files
.length
).to
.equal(1)
323 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
330 it('Should add the file 3 by asking pod 2', function (done
) {
331 // Yes, this could be long
334 utils
.getVideosList(servers
[1].url
, function (err
, res
) {
337 const video
= res
.body
.data
[2]
339 webtorrent
.add(video
.magnetUri
, function (torrent
) {
340 expect(torrent
.files
).to
.exist
341 expect(torrent
.files
.length
).to
.equal(1)
342 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
344 webtorrent
.remove(video
.magnetUri
, done
)
349 it('Should add the file 3-2 by asking pod 1', function (done
) {
350 // Yes, this could be long
353 utils
.getVideosList(servers
[0].url
, function (err
, res
) {
356 const video
= res
.body
.data
[3]
358 webtorrent
.add(video
.magnetUri
, function (torrent
) {
359 expect(torrent
.files
).to
.exist
360 expect(torrent
.files
.length
).to
.equal(1)
361 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
368 it('Should remove the file 3 and 3-2 by asking pod 3', function (done
) {
373 utils
.removeVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[0], next
)
376 utils
.removeVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[1], next
)
380 setTimeout(done
, 11000)
385 it('Should have videos 1 and 3 on each pod', function (done
) {
386 async
.each(servers
, function (server
, callback
) {
387 utils
.getVideosList(server
.url
, function (err
, res
) {
390 const videos
= res
.body
.data
391 expect(videos
).to
.be
.an('array')
392 expect(videos
.length
).to
.equal(2)
393 expect(videos
[0].id
).not
.to
.equal(videos
[1].id
)
394 expect(videos
[0].id
).not
.to
.equal(toRemove
[0])
395 expect(videos
[1].id
).not
.to
.equal(toRemove
[0])
396 expect(videos
[0].id
).not
.to
.equal(toRemove
[1])
397 expect(videos
[1].id
).not
.to
.equal(toRemove
[1])
405 after(function (done
) {
406 servers
.forEach(function (server
) {
407 process
.kill(-server
.app
.pid
)
409 process
.kill(-webtorrent
.app
.pid
)
411 // Keep the logs if the test failed
413 utils
.flushTests(done
)