]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/multiple-pods.js
e02b6180b48c153fd4013b4a19062d4d6ca3004d
1 /* eslint-disable no-unused-expressions */
5 const chai
= require('chai')
6 const each
= require('async/each')
7 const expect
= chai
.expect
8 const parallel
= require('async/parallel')
9 const series
= require('async/series')
10 const WebTorrent
= require('webtorrent')
11 const webtorrent
= new WebTorrent()
13 const loginUtils
= require('../utils/login')
14 const miscsUtils
= require('../utils/miscs')
15 const podsUtils
= require('../utils/pods')
16 const serversUtils
= require('../utils/servers')
17 const videosUtils
= require('../utils/videos')
19 describe('Test multiple pods', function () {
23 before(function (done
) {
29 serversUtils
.flushAndRunMultipleServers(3, function (serversRun
) {
34 // Get the access tokens
36 each(servers
, function (server
, callbackEach
) {
37 loginUtils
.loginAndGetAccessToken(server
, function (err
, accessToken
) {
38 if (err
) return callbackEach(err
)
40 server
.accessToken
= accessToken
45 // The second pod make friend with the third
47 const server
= servers
[1]
48 podsUtils
.makeFriends(server
.url
, server
.accessToken
, next
)
50 // Wait for the request between pods
52 setTimeout(next
, 10000)
54 // Pod 1 make friends too
56 const server
= servers
[0]
57 podsUtils
.makeFriends(server
.url
, server
.accessToken
, next
)
62 it('Should not have videos for all pods', function (done
) {
63 each(servers
, function (server
, callback
) {
64 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
67 const videos
= res
.body
.data
68 expect(videos
).to
.be
.an('array')
69 expect(videos
.length
).to
.equal(0)
76 describe('Should upload the video and propagate on each pod', function () {
77 it('Should upload the video on pod 1 and propagate on each pod', function (done
) {
82 const name
= 'my super name for pod 1'
83 const description
= 'my super description for pod 1'
84 const tags
= [ 'tag1p1', 'tag2p1' ]
85 const file
= 'video_short1.webm'
86 videosUtils
.uploadVideo(servers
[0].url
, servers
[0].accessToken
, name
, description
, tags
, file
, next
)
89 setTimeout(next
, 11000)
91 // All pods should have this video
95 each(servers
, function (server
, callback
) {
98 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
101 const videos
= res
.body
.data
102 expect(videos
).to
.be
.an('array')
103 expect(videos
.length
).to
.equal(1)
104 const video
= videos
[0]
105 expect(video
.name
).to
.equal('my super name for pod 1')
106 expect(video
.description
).to
.equal('my super description for pod 1')
107 expect(video
.podHost
).to
.equal('localhost:9001')
108 expect(video
.magnetUri
).to
.exist
109 expect(video
.duration
).to
.equal(10)
110 expect(video
.tags
).to
.deep
.equal([ 'tag1p1', 'tag2p1' ])
111 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
112 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
113 expect(video
.author
).to
.equal('root')
115 if (server
.url
!== 'http://localhost:9001') {
116 expect(video
.isLocal
).to
.be
.false
118 expect(video
.isLocal
).to
.be
.true
121 // All pods should have the same magnet Uri
122 if (baseMagnet
=== null) {
123 baseMagnet
= video
.magnetUri
125 expect(video
.magnetUri
).to
.equal
.magnetUri
128 videosUtils
.testVideoImage(server
.url
, 'video_short1.webm', video
.thumbnailPath
, function (err
, test
) {
130 expect(test
).to
.equal(true)
140 it('Should upload the video on pod 2 and propagate on each pod', function (done
) {
145 const name
= 'my super name for pod 2'
146 const description
= 'my super description for pod 2'
147 const tags
= [ 'tag1p2', 'tag2p2', 'tag3p2' ]
148 const file
= 'video_short2.webm'
149 videosUtils
.uploadVideo(servers
[1].url
, servers
[1].accessToken
, name
, description
, tags
, file
, next
)
152 setTimeout(next
, 11000)
154 // All pods should have this video
158 each(servers
, function (server
, callback
) {
159 let baseMagnet
= null
161 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
164 const videos
= res
.body
.data
165 expect(videos
).to
.be
.an('array')
166 expect(videos
.length
).to
.equal(2)
167 const video
= videos
[1]
168 expect(video
.name
).to
.equal('my super name for pod 2')
169 expect(video
.description
).to
.equal('my super description for pod 2')
170 expect(video
.podHost
).to
.equal('localhost:9002')
171 expect(video
.magnetUri
).to
.exist
172 expect(video
.duration
).to
.equal(5)
173 expect(video
.tags
).to
.deep
.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ])
174 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
175 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
176 expect(video
.author
).to
.equal('root')
178 if (server
.url
!== 'http://localhost:9002') {
179 expect(video
.isLocal
).to
.be
.false
181 expect(video
.isLocal
).to
.be
.true
184 // All pods should have the same magnet Uri
185 if (baseMagnet
=== null) {
186 baseMagnet
= video
.magnetUri
188 expect(video
.magnetUri
).to
.equal
.magnetUri
191 videosUtils
.testVideoImage(server
.url
, 'video_short2.webm', video
.thumbnailPath
, function (err
, test
) {
193 expect(test
).to
.equal(true)
203 it('Should upload two videos on pod 3 and propagate on each pod', function (done
) {
208 const name
= 'my super name for pod 3'
209 const description
= 'my super description for pod 3'
210 const tags
= [ 'tag1p3' ]
211 const file
= 'video_short3.webm'
212 videosUtils
.uploadVideo(servers
[2].url
, servers
[2].accessToken
, name
, description
, tags
, file
, next
)
215 const name
= 'my super name for pod 3-2'
216 const description
= 'my super description for pod 3-2'
217 const tags
= [ 'tag2p3', 'tag3p3', 'tag4p3' ]
218 const file
= 'video_short.webm'
219 videosUtils
.uploadVideo(servers
[2].url
, servers
[2].accessToken
, name
, description
, tags
, file
, next
)
222 setTimeout(next
, 22000)
227 let baseMagnet
= null
228 // All pods should have this video
229 each(servers
, function (server
, callback
) {
230 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
233 const videos
= res
.body
.data
234 expect(videos
).to
.be
.an('array')
235 expect(videos
.length
).to
.equal(4)
237 // We not sure about the order of the two last uploads
240 if (videos
[2].name
=== 'my super name for pod 3') {
248 expect(video1
.name
).to
.equal('my super name for pod 3')
249 expect(video1
.description
).to
.equal('my super description for pod 3')
250 expect(video1
.podHost
).to
.equal('localhost:9003')
251 expect(video1
.magnetUri
).to
.exist
252 expect(video1
.duration
).to
.equal(5)
253 expect(video1
.tags
).to
.deep
.equal([ 'tag1p3' ])
254 expect(video1
.author
).to
.equal('root')
255 expect(miscsUtils
.dateIsValid(video1
.createdAt
)).to
.be
.true
256 expect(miscsUtils
.dateIsValid(video1
.updatedAt
)).to
.be
.true
258 expect(video2
.name
).to
.equal('my super name for pod 3-2')
259 expect(video2
.description
).to
.equal('my super description for pod 3-2')
260 expect(video2
.podHost
).to
.equal('localhost:9003')
261 expect(video2
.magnetUri
).to
.exist
262 expect(video2
.duration
).to
.equal(5)
263 expect(video2
.tags
).to
.deep
.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ])
264 expect(video2
.author
).to
.equal('root')
265 expect(miscsUtils
.dateIsValid(video2
.createdAt
)).to
.be
.true
266 expect(miscsUtils
.dateIsValid(video2
.updatedAt
)).to
.be
.true
268 if (server
.url
!== 'http://localhost:9003') {
269 expect(video1
.isLocal
).to
.be
.false
270 expect(video2
.isLocal
).to
.be
.false
272 expect(video1
.isLocal
).to
.be
.true
273 expect(video2
.isLocal
).to
.be
.true
276 // All pods should have the same magnet Uri
277 if (baseMagnet
=== null) {
278 baseMagnet
= video2
.magnetUri
280 expect(video2
.magnetUri
).to
.equal
.magnetUri
283 videosUtils
.testVideoImage(server
.url
, 'video_short3.webm', video1
.thumbnailPath
, function (err
, test
) {
285 expect(test
).to
.equal(true)
287 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video2
.thumbnailPath
, function (err
, test
) {
289 expect(test
).to
.equal(true)
301 describe('Should seed the uploaded video', function () {
302 it('Should add the file 1 by asking pod 3', function (done
) {
303 // Yes, this could be long
306 videosUtils
.getVideosList(servers
[2].url
, function (err
, res
) {
309 const video
= res
.body
.data
[0]
310 toRemove
.push(res
.body
.data
[2])
311 toRemove
.push(res
.body
.data
[3])
313 webtorrent
.add(video
.magnetUri
, function (torrent
) {
314 expect(torrent
.files
).to
.exist
315 expect(torrent
.files
.length
).to
.equal(1)
316 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
323 it('Should add the file 2 by asking pod 1', function (done
) {
324 // Yes, this could be long
327 videosUtils
.getVideosList(servers
[0].url
, function (err
, res
) {
330 const video
= res
.body
.data
[1]
332 webtorrent
.add(video
.magnetUri
, function (torrent
) {
333 expect(torrent
.files
).to
.exist
334 expect(torrent
.files
.length
).to
.equal(1)
335 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
342 it('Should add the file 3 by asking pod 2', function (done
) {
343 // Yes, this could be long
346 videosUtils
.getVideosList(servers
[1].url
, function (err
, res
) {
349 const video
= res
.body
.data
[2]
351 webtorrent
.add(video
.magnetUri
, function (torrent
) {
352 expect(torrent
.files
).to
.exist
353 expect(torrent
.files
.length
).to
.equal(1)
354 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
361 it('Should add the file 3-2 by asking pod 1', function (done
) {
362 // Yes, this could be long
365 videosUtils
.getVideosList(servers
[0].url
, function (err
, res
) {
368 const video
= res
.body
.data
[3]
370 webtorrent
.add(video
.magnetUri
, function (torrent
) {
371 expect(torrent
.files
).to
.exist
372 expect(torrent
.files
.length
).to
.equal(1)
373 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
381 describe('Should update video views', function () {
382 let localVideosPod3
= []
383 let remoteVideosPod1
= []
384 let remoteVideosPod2
= []
385 let remoteVideosPod3
= []
387 before(function (done
) {
389 function (callback
) {
390 videosUtils
.getVideosList(servers
[0].url
, function (err
, res
) {
393 remoteVideosPod1
= res
.body
.data
.filter(video
=> video
.isLocal
=== false).map(video
=> video
.id
)
399 function (callback
) {
400 videosUtils
.getVideosList(servers
[1].url
, function (err
, res
) {
403 remoteVideosPod2
= res
.body
.data
.filter(video
=> video
.isLocal
=== false).map(video
=> video
.id
)
409 function (callback
) {
410 videosUtils
.getVideosList(servers
[2].url
, function (err
, res
) {
413 localVideosPod3
= res
.body
.data
.filter(video
=> video
.isLocal
=== true).map(video
=> video
.id
)
414 remoteVideosPod3
= res
.body
.data
.filter(video
=> video
.isLocal
=== false).map(video
=> video
.id
)
422 it('Should views multiple videos on owned servers', function (done
) {
426 function (callback
) {
427 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[0], callback
)
430 function (callback
) {
431 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[0], callback
)
434 function (callback
) {
435 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[0], callback
)
438 function (callback
) {
439 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[1], callback
)
442 function (callback
) {
443 setTimeout(done
, 22000)
448 each(servers
, function (server
, callback
) {
449 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
452 const videos
= res
.body
.data
453 expect(videos
.find(video
=> video
.views
=== 3)).to
.be
.exist
454 expect(videos
.find(video
=> video
.views
=== 1)).to
.be
.exist
462 it('Should views multiple videos on each servers', function (done
) {
466 function (callback
) {
467 videosUtils
.getVideo(servers
[0].url
, remoteVideosPod1
[0], callback
)
470 function (callback
) {
471 videosUtils
.getVideo(servers
[1].url
, remoteVideosPod2
[0], callback
)
474 function (callback
) {
475 videosUtils
.getVideo(servers
[1].url
, remoteVideosPod2
[0], callback
)
478 function (callback
) {
479 videosUtils
.getVideo(servers
[2].url
, remoteVideosPod3
[0], callback
)
482 function (callback
) {
483 videosUtils
.getVideo(servers
[2].url
, remoteVideosPod3
[1], callback
)
486 function (callback
) {
487 videosUtils
.getVideo(servers
[2].url
, remoteVideosPod3
[1], callback
)
490 function (callback
) {
491 videosUtils
.getVideo(servers
[2].url
, remoteVideosPod3
[1], callback
)
494 function (callback
) {
495 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[1], callback
)
498 function (callback
) {
499 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[1], callback
)
502 function (callback
) {
503 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[1], callback
)
506 function (callback
) {
507 setTimeout(done
, 22000)
512 let baseVideos
= null
513 each(servers
, function (server
, callback
) {
514 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
517 const videos
= res
.body
519 // Initialize base videos for future comparisons
520 if (baseVideos
=== null) {
525 for (let i
= 0; i
< baseVideos
.length
; i
++) {
526 expect(baseVideos
[i
].views
).to
.equal(videos
[i
].views
)
536 describe('Should manipulate these videos', function () {
537 it('Should update the video 3 by asking pod 3', function (done
) {
540 const name
= 'my super video updated'
541 const description
= 'my super description updated'
542 const tags
= [ 'tagup1', 'tagup2' ]
544 videosUtils
.updateVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[0].id
, name
, description
, tags
, function (err
) {
547 setTimeout(done
, 11000)
551 it('Should have the video 3 updated on each pod', function (done
) {
554 each(servers
, function (server
, callback
) {
555 // Avoid "duplicate torrent" errors
556 const webtorrent
= new WebTorrent()
558 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
561 const videos
= res
.body
.data
562 const videoUpdated
= videos
.find(function (video
) {
563 return video
.name
=== 'my super video updated'
566 expect(!!videoUpdated
).to
.be
.true
567 expect(videoUpdated
.description
).to
.equal('my super description updated')
568 expect(videoUpdated
.tags
).to
.deep
.equal([ 'tagup1', 'tagup2' ])
569 expect(miscsUtils
.dateIsValid(videoUpdated
.updatedAt
, 20000)).to
.be
.true
571 videosUtils
.testVideoImage(server
.url
, 'video_short3.webm', videoUpdated
.thumbnailPath
, function (err
, test
) {
573 expect(test
).to
.equal(true)
575 webtorrent
.add(videoUpdated
.magnetUri
, function (torrent
) {
576 expect(torrent
.files
).to
.exist
577 expect(torrent
.files
.length
).to
.equal(1)
578 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
587 it('Should remove the videos 3 and 3-2 by asking pod 3', function (done
) {
592 videosUtils
.removeVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[0].id
, next
)
595 videosUtils
.removeVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[1].id
, next
)
599 setTimeout(done
, 11000)
604 it('Should have videos 1 and 3 on each pod', function (done
) {
605 each(servers
, function (server
, callback
) {
606 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
609 const videos
= res
.body
.data
610 expect(videos
).to
.be
.an('array')
611 expect(videos
.length
).to
.equal(2)
612 expect(videos
[0].name
).not
.to
.equal(videos
[1].name
)
613 expect(videos
[0].name
).not
.to
.equal(toRemove
[0].name
)
614 expect(videos
[1].name
).not
.to
.equal(toRemove
[0].name
)
615 expect(videos
[0].name
).not
.to
.equal(toRemove
[1].name
)
616 expect(videos
[1].name
).not
.to
.equal(toRemove
[1].name
)
624 after(function (done
) {
625 servers
.forEach(function (server
) {
626 process
.kill(-server
.app
.pid
)
629 // Keep the logs if the test failed
631 serversUtils
.flushTests(done
)