]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/multiple-pods.js
feba68d743f2ffac9118311a9a4142fc223bdabd
1 /* eslint-disable no-unused-expressions */
5 const chai
= require('chai')
6 const each
= require('async/each')
7 const eachSeries
= require('async/eachSeries')
8 const expect
= chai
.expect
9 const parallel
= require('async/parallel')
10 const series
= require('async/series')
11 const WebTorrent
= require('webtorrent')
12 const webtorrent
= new WebTorrent()
14 const loginUtils
= require('../utils/login')
15 const miscsUtils
= require('../utils/miscs')
16 const podsUtils
= require('../utils/pods')
17 const serversUtils
= require('../utils/servers')
18 const videosUtils
= require('../utils/videos')
20 describe('Test multiple pods', function () {
24 before(function (done
) {
30 serversUtils
.flushAndRunMultipleServers(3, function (serversRun
) {
35 // Get the access tokens
37 each(servers
, function (server
, callbackEach
) {
38 loginUtils
.loginAndGetAccessToken(server
, function (err
, accessToken
) {
39 if (err
) return callbackEach(err
)
41 server
.accessToken
= accessToken
46 // The second pod make friend with the third
48 const server
= servers
[1]
49 podsUtils
.makeFriends(server
.url
, server
.accessToken
, next
)
51 // Wait for the request between pods
53 setTimeout(next
, 10000)
55 // Pod 1 make friends too
57 const server
= servers
[0]
58 podsUtils
.makeFriends(server
.url
, server
.accessToken
, next
)
63 it('Should not have videos for all pods', function (done
) {
64 each(servers
, function (server
, callback
) {
65 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
68 const videos
= res
.body
.data
69 expect(videos
).to
.be
.an('array')
70 expect(videos
.length
).to
.equal(0)
77 describe('Should upload the video and propagate on each pod', function () {
78 it('Should upload the video on pod 1 and propagate on each pod', function (done
) {
79 // Pod 1 has video transcoding activated
84 const videoAttributes
= {
85 name: 'my super name for pod 1',
90 description: 'my super description for pod 1',
91 tags: [ 'tag1p1', 'tag2p1' ],
92 fixture: 'video_short1.webm'
94 videosUtils
.uploadVideo(servers
[0].url
, servers
[0].accessToken
, videoAttributes
, next
)
97 setTimeout(next
, 11000)
99 // All pods should have this video
103 each(servers
, function (server
, callback
) {
104 let baseMagnet
= null
106 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
109 const videos
= res
.body
.data
110 expect(videos
).to
.be
.an('array')
111 expect(videos
.length
).to
.equal(1)
112 const video
= videos
[0]
113 expect(video
.name
).to
.equal('my super name for pod 1')
114 expect(video
.category
).to
.equal(5)
115 expect(video
.categoryLabel
).to
.equal('Sports')
116 expect(video
.licence
).to
.equal(4)
117 expect(video
.licenceLabel
).to
.equal('Attribution - Non Commercial')
118 expect(video
.language
).to
.equal(9)
119 expect(video
.languageLabel
).to
.equal('Japanese')
120 expect(video
.nsfw
).to
.be
.truthy
121 expect(video
.description
).to
.equal('my super description for pod 1')
122 expect(video
.podHost
).to
.equal('localhost:9001')
123 expect(video
.magnetUri
).to
.exist
124 expect(video
.duration
).to
.equal(10)
125 expect(video
.tags
).to
.deep
.equal([ 'tag1p1', 'tag2p1' ])
126 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
127 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
128 expect(video
.author
).to
.equal('root')
130 if (server
.url
!== 'http://localhost:9001') {
131 expect(video
.isLocal
).to
.be
.false
133 expect(video
.isLocal
).to
.be
.true
136 // All pods should have the same magnet Uri
137 if (baseMagnet
=== null) {
138 baseMagnet
= video
.magnetUri
140 expect(video
.magnetUri
).to
.equal
.magnetUri
143 videosUtils
.testVideoImage(server
.url
, 'video_short1.webm', video
.thumbnailPath
, function (err
, test
) {
145 expect(test
).to
.equal(true)
155 it('Should upload the video on pod 2 and propagate on each pod', function (done
) {
160 const videoAttributes
= {
161 name: 'my super name for pod 2',
166 description: 'my super description for pod 2',
167 tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ],
168 fixture: 'video_short2.webm'
170 videosUtils
.uploadVideo(servers
[1].url
, servers
[1].accessToken
, videoAttributes
, next
)
173 setTimeout(next
, 22000)
175 // All pods should have this video
179 each(servers
, function (server
, callback
) {
180 let baseMagnet
= null
182 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
185 const videos
= res
.body
.data
186 expect(videos
).to
.be
.an('array')
187 expect(videos
.length
).to
.equal(2)
188 const video
= videos
[1]
189 expect(video
.name
).to
.equal('my super name for pod 2')
190 expect(video
.category
).to
.equal(4)
191 expect(video
.categoryLabel
).to
.equal('Art')
192 expect(video
.licence
).to
.equal(3)
193 expect(video
.licenceLabel
).to
.equal('Attribution - No Derivatives')
194 expect(video
.language
).to
.equal(11)
195 expect(video
.languageLabel
).to
.equal('German')
196 expect(video
.nsfw
).to
.be
.falsy
197 expect(video
.description
).to
.equal('my super description for pod 2')
198 expect(video
.podHost
).to
.equal('localhost:9002')
199 expect(video
.magnetUri
).to
.exist
200 expect(video
.duration
).to
.equal(5)
201 expect(video
.tags
).to
.deep
.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ])
202 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
203 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
204 expect(video
.author
).to
.equal('root')
206 if (server
.url
!== 'http://localhost:9002') {
207 expect(video
.isLocal
).to
.be
.false
209 expect(video
.isLocal
).to
.be
.true
212 // All pods should have the same magnet Uri
213 if (baseMagnet
=== null) {
214 baseMagnet
= video
.magnetUri
216 expect(video
.magnetUri
).to
.equal
.magnetUri
219 videosUtils
.testVideoImage(server
.url
, 'video_short2.webm', video
.thumbnailPath
, function (err
, test
) {
221 expect(test
).to
.equal(true)
231 it('Should upload two videos on pod 3 and propagate on each pod', function (done
) {
236 const videoAttributes
= {
237 name: 'my super name for pod 3',
242 description: 'my super description for pod 3',
244 fixture: 'video_short3.webm'
246 videosUtils
.uploadVideo(servers
[2].url
, servers
[2].accessToken
, videoAttributes
, next
)
249 const videoAttributes
= {
250 name: 'my super name for pod 3-2',
255 description: 'my super description for pod 3-2',
256 tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ],
257 fixture: 'video_short.webm'
259 videosUtils
.uploadVideo(servers
[2].url
, servers
[2].accessToken
, videoAttributes
, next
)
262 setTimeout(next
, 22000)
267 let baseMagnet
= null
268 // All pods should have this video
269 each(servers
, function (server
, callback
) {
270 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
273 const videos
= res
.body
.data
274 expect(videos
).to
.be
.an('array')
275 expect(videos
.length
).to
.equal(4)
277 // We not sure about the order of the two last uploads
280 if (videos
[2].name
=== 'my super name for pod 3') {
288 expect(video1
.name
).to
.equal('my super name for pod 3')
289 expect(video1
.category
).to
.equal(6)
290 expect(video1
.categoryLabel
).to
.equal('Travels')
291 expect(video1
.licence
).to
.equal(5)
292 expect(video1
.licenceLabel
).to
.equal('Attribution - Non Commercial - Share Alike')
293 expect(video1
.language
).to
.equal(11)
294 expect(video1
.languageLabel
).to
.equal('German')
295 expect(video1
.nsfw
).to
.be
.truthy
296 expect(video1
.description
).to
.equal('my super description for pod 3')
297 expect(video1
.podHost
).to
.equal('localhost:9003')
298 expect(video1
.magnetUri
).to
.exist
299 expect(video1
.duration
).to
.equal(5)
300 expect(video1
.tags
).to
.deep
.equal([ 'tag1p3' ])
301 expect(video1
.author
).to
.equal('root')
302 expect(miscsUtils
.dateIsValid(video1
.createdAt
)).to
.be
.true
303 expect(miscsUtils
.dateIsValid(video1
.updatedAt
)).to
.be
.true
305 expect(video2
.name
).to
.equal('my super name for pod 3-2')
306 expect(video2
.category
).to
.equal(7)
307 expect(video2
.categoryLabel
).to
.equal('Gaming')
308 expect(video2
.licence
).to
.equal(6)
309 expect(video2
.licenceLabel
).to
.equal('Attribution - Non Commercial - No Derivatives')
310 expect(video2
.language
).to
.equal(12)
311 expect(video2
.languageLabel
).to
.equal('Korean')
312 expect(video2
.nsfw
).to
.be
.falsy
313 expect(video2
.description
).to
.equal('my super description for pod 3-2')
314 expect(video2
.podHost
).to
.equal('localhost:9003')
315 expect(video2
.magnetUri
).to
.exist
316 expect(video2
.duration
).to
.equal(5)
317 expect(video2
.tags
).to
.deep
.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ])
318 expect(video2
.author
).to
.equal('root')
319 expect(miscsUtils
.dateIsValid(video2
.createdAt
)).to
.be
.true
320 expect(miscsUtils
.dateIsValid(video2
.updatedAt
)).to
.be
.true
322 if (server
.url
!== 'http://localhost:9003') {
323 expect(video1
.isLocal
).to
.be
.false
324 expect(video2
.isLocal
).to
.be
.false
326 expect(video1
.isLocal
).to
.be
.true
327 expect(video2
.isLocal
).to
.be
.true
330 // All pods should have the same magnet Uri
331 if (baseMagnet
=== null) {
332 baseMagnet
= video2
.magnetUri
334 expect(video2
.magnetUri
).to
.equal
.magnetUri
337 videosUtils
.testVideoImage(server
.url
, 'video_short3.webm', video1
.thumbnailPath
, function (err
, test
) {
339 expect(test
).to
.equal(true)
341 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video2
.thumbnailPath
, function (err
, test
) {
343 expect(test
).to
.equal(true)
355 describe('Should seed the uploaded video', function () {
356 it('Should add the file 1 by asking pod 3', function (done
) {
357 // Yes, this could be long
360 videosUtils
.getVideosList(servers
[2].url
, function (err
, res
) {
363 const video
= res
.body
.data
[0]
364 toRemove
.push(res
.body
.data
[2])
365 toRemove
.push(res
.body
.data
[3])
367 webtorrent
.add(video
.magnetUri
, function (torrent
) {
368 expect(torrent
.files
).to
.exist
369 expect(torrent
.files
.length
).to
.equal(1)
370 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
377 it('Should add the file 2 by asking pod 1', function (done
) {
378 // Yes, this could be long
381 videosUtils
.getVideosList(servers
[0].url
, function (err
, res
) {
384 const video
= res
.body
.data
[1]
386 webtorrent
.add(video
.magnetUri
, function (torrent
) {
387 expect(torrent
.files
).to
.exist
388 expect(torrent
.files
.length
).to
.equal(1)
389 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
396 it('Should add the file 3 by asking pod 2', function (done
) {
397 // Yes, this could be long
400 videosUtils
.getVideosList(servers
[1].url
, function (err
, res
) {
403 const video
= res
.body
.data
[2]
405 webtorrent
.add(video
.magnetUri
, function (torrent
) {
406 expect(torrent
.files
).to
.exist
407 expect(torrent
.files
.length
).to
.equal(1)
408 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
415 it('Should add the file 3-2 by asking pod 1', function (done
) {
416 // Yes, this could be long
419 videosUtils
.getVideosList(servers
[0].url
, function (err
, res
) {
422 const video
= res
.body
.data
[3]
424 webtorrent
.add(video
.magnetUri
, function (torrent
) {
425 expect(torrent
.files
).to
.exist
426 expect(torrent
.files
.length
).to
.equal(1)
427 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
435 describe('Should update video views, likes and dislikes', function () {
436 let localVideosPod3
= []
437 let remoteVideosPod1
= []
438 let remoteVideosPod2
= []
439 let remoteVideosPod3
= []
441 before(function (done
) {
443 function (callback
) {
444 videosUtils
.getVideosList(servers
[0].url
, function (err
, res
) {
447 remoteVideosPod1
= res
.body
.data
.filter(video
=> video
.isLocal
=== false).map(video
=> video
.id
)
453 function (callback
) {
454 videosUtils
.getVideosList(servers
[1].url
, function (err
, res
) {
457 remoteVideosPod2
= res
.body
.data
.filter(video
=> video
.isLocal
=== false).map(video
=> video
.id
)
463 function (callback
) {
464 videosUtils
.getVideosList(servers
[2].url
, function (err
, res
) {
467 localVideosPod3
= res
.body
.data
.filter(video
=> video
.isLocal
=== true).map(video
=> video
.id
)
468 remoteVideosPod3
= res
.body
.data
.filter(video
=> video
.isLocal
=== false).map(video
=> video
.id
)
476 it('Should view multiple videos on owned servers', function (done
) {
480 function (callback
) {
481 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[0], callback
)
484 function (callback
) {
485 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[0], callback
)
488 function (callback
) {
489 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[0], callback
)
492 function (callback
) {
493 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[1], callback
)
496 function (callback
) {
497 setTimeout(callback
, 22000)
502 eachSeries(servers
, function (server
, callback
) {
503 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
506 const videos
= res
.body
.data
507 expect(videos
.find(video
=> video
.views
=== 3)).to
.exist
508 expect(videos
.find(video
=> video
.views
=== 1)).to
.exist
516 it('Should view multiple videos on each servers', function (done
) {
520 function (callback
) {
521 videosUtils
.getVideo(servers
[0].url
, remoteVideosPod1
[0], callback
)
524 function (callback
) {
525 videosUtils
.getVideo(servers
[1].url
, remoteVideosPod2
[0], callback
)
528 function (callback
) {
529 videosUtils
.getVideo(servers
[1].url
, remoteVideosPod2
[0], callback
)
532 function (callback
) {
533 videosUtils
.getVideo(servers
[2].url
, remoteVideosPod3
[0], callback
)
536 function (callback
) {
537 videosUtils
.getVideo(servers
[2].url
, remoteVideosPod3
[1], callback
)
540 function (callback
) {
541 videosUtils
.getVideo(servers
[2].url
, remoteVideosPod3
[1], callback
)
544 function (callback
) {
545 videosUtils
.getVideo(servers
[2].url
, remoteVideosPod3
[1], callback
)
548 function (callback
) {
549 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[1], callback
)
552 function (callback
) {
553 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[1], callback
)
556 function (callback
) {
557 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[1], callback
)
560 function (callback
) {
561 setTimeout(callback
, 22000)
566 let baseVideos
= null
567 eachSeries(servers
, function (server
, callback
) {
568 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
571 const videos
= res
.body
.data
573 // Initialize base videos for future comparisons
574 if (baseVideos
=== null) {
579 baseVideos
.forEach(baseVideo
=> {
580 const sameVideo
= videos
.find(video
=> video
.name
=== baseVideo
.name
)
581 expect(baseVideo
.views
).to
.equal(sameVideo
.views
)
590 it('Should like and dislikes videos on different services', function (done
) {
594 function (callback
) {
595 videosUtils
.rateVideo(servers
[0].url
, servers
[0].accessToken
, remoteVideosPod1
[0], 'like', callback
)
598 function (callback
) {
599 videosUtils
.rateVideo(servers
[0].url
, servers
[0].accessToken
, remoteVideosPod1
[0], 'dislike', callback
)
602 function (callback
) {
603 videosUtils
.rateVideo(servers
[0].url
, servers
[0].accessToken
, remoteVideosPod1
[0], 'like', callback
)
606 function (callback
) {
607 videosUtils
.rateVideo(servers
[2].url
, servers
[2].accessToken
, localVideosPod3
[1], 'like', callback
)
610 function (callback
) {
611 videosUtils
.rateVideo(servers
[2].url
, servers
[2].accessToken
, localVideosPod3
[1], 'dislike', callback
)
614 function (callback
) {
615 videosUtils
.rateVideo(servers
[2].url
, servers
[2].accessToken
, remoteVideosPod3
[1], 'dislike', callback
)
618 function (callback
) {
619 videosUtils
.rateVideo(servers
[2].url
, servers
[2].accessToken
, remoteVideosPod3
[0], 'like', callback
)
622 function (callback
) {
623 setTimeout(callback
, 22000)
628 let baseVideos
= null
629 eachSeries(servers
, function (server
, callback
) {
630 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
633 const videos
= res
.body
.data
635 // Initialize base videos for future comparisons
636 if (baseVideos
=== null) {
641 baseVideos
.forEach(baseVideo
=> {
642 const sameVideo
= videos
.find(video
=> video
.name
=== baseVideo
.name
)
643 expect(baseVideo
.likes
).to
.equal(sameVideo
.likes
)
644 expect(baseVideo
.dislikes
).to
.equal(sameVideo
.dislikes
)
654 describe('Should manipulate these videos', function () {
655 it('Should update the video 3 by asking pod 3', function (done
) {
659 name: 'my super video updated',
664 description: 'my super description updated',
665 tags: [ 'tagup1', 'tagup2' ]
667 videosUtils
.updateVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[0].id
, attributes
, function (err
) {
670 setTimeout(done
, 11000)
674 it('Should have the video 3 updated on each pod', function (done
) {
677 each(servers
, function (server
, callback
) {
678 // Avoid "duplicate torrent" errors
679 const webtorrent
= new WebTorrent()
681 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
684 const videos
= res
.body
.data
685 const videoUpdated
= videos
.find(function (video
) {
686 return video
.name
=== 'my super video updated'
689 expect(!!videoUpdated
).to
.be
.true
690 expect(videoUpdated
.category
).to
.equal(10)
691 expect(videoUpdated
.categoryLabel
).to
.equal('Entertainment')
692 expect(videoUpdated
.licence
).to
.equal(7)
693 expect(videoUpdated
.licenceLabel
).to
.equal('Public Domain Dedication')
694 expect(videoUpdated
.language
).to
.equal(13)
695 expect(videoUpdated
.languageLabel
).to
.equal('French')
696 expect(videoUpdated
.nsfw
).to
.be
.truthy
697 expect(videoUpdated
.description
).to
.equal('my super description updated')
698 expect(videoUpdated
.tags
).to
.deep
.equal([ 'tagup1', 'tagup2' ])
699 expect(miscsUtils
.dateIsValid(videoUpdated
.updatedAt
, 20000)).to
.be
.true
701 videosUtils
.testVideoImage(server
.url
, 'video_short3.webm', videoUpdated
.thumbnailPath
, function (err
, test
) {
703 expect(test
).to
.equal(true)
705 webtorrent
.add(videoUpdated
.magnetUri
, function (torrent
) {
706 expect(torrent
.files
).to
.exist
707 expect(torrent
.files
.length
).to
.equal(1)
708 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
717 it('Should remove the videos 3 and 3-2 by asking pod 3', function (done
) {
722 videosUtils
.removeVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[0].id
, next
)
725 videosUtils
.removeVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[1].id
, next
)
729 setTimeout(done
, 11000)
734 it('Should have videos 1 and 3 on each pod', function (done
) {
735 each(servers
, function (server
, callback
) {
736 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
739 const videos
= res
.body
.data
740 expect(videos
).to
.be
.an('array')
741 expect(videos
.length
).to
.equal(2)
742 expect(videos
[0].name
).not
.to
.equal(videos
[1].name
)
743 expect(videos
[0].name
).not
.to
.equal(toRemove
[0].name
)
744 expect(videos
[1].name
).not
.to
.equal(toRemove
[0].name
)
745 expect(videos
[0].name
).not
.to
.equal(toRemove
[1].name
)
746 expect(videos
[1].name
).not
.to
.equal(toRemove
[1].name
)
754 after(function (done
) {
755 servers
.forEach(function (server
) {
756 process
.kill(-server
.app
.pid
)
759 // Keep the logs if the test failed
761 serversUtils
.flushTests(done
)