]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/multiple-pods.js
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 () {
25 before(function (done
) {
31 serversUtils
.flushAndRunMultipleServers(3, function (serversRun
) {
36 // Get the access tokens
38 each(servers
, function (server
, callbackEach
) {
39 loginUtils
.loginAndGetAccessToken(server
, function (err
, accessToken
) {
40 if (err
) return callbackEach(err
)
42 server
.accessToken
= accessToken
47 // The second pod make friend with the third
49 const server
= servers
[1]
50 podsUtils
.makeFriends(server
.url
, server
.accessToken
, next
)
52 // Wait for the request between pods
54 setTimeout(next
, 10000)
56 // Pod 1 make friends too
58 const server
= servers
[0]
59 podsUtils
.makeFriends(server
.url
, server
.accessToken
, next
)
64 it('Should not have videos for all pods', function (done
) {
65 each(servers
, function (server
, callback
) {
66 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
69 const videos
= res
.body
.data
70 expect(videos
).to
.be
.an('array')
71 expect(videos
.length
).to
.equal(0)
78 describe('Should upload the video and propagate on each pod', function () {
79 it('Should upload the video on pod 1 and propagate on each pod', function (done
) {
80 // Pod 1 has video transcoding activated
85 const videoAttributes
= {
86 name: 'my super name for pod 1',
91 description: 'my super description for pod 1',
92 tags: [ 'tag1p1', 'tag2p1' ],
93 fixture: 'video_short1.webm'
95 videosUtils
.uploadVideo(servers
[0].url
, servers
[0].accessToken
, videoAttributes
, next
)
98 setTimeout(next
, 11000)
100 // All pods should have this video
104 each(servers
, function (server
, callback
) {
105 let baseMagnet
= null
107 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
110 const videos
= res
.body
.data
111 expect(videos
).to
.be
.an('array')
112 expect(videos
.length
).to
.equal(1)
113 const video
= videos
[0]
114 expect(video
.name
).to
.equal('my super name for pod 1')
115 expect(video
.category
).to
.equal(5)
116 expect(video
.categoryLabel
).to
.equal('Sports')
117 expect(video
.licence
).to
.equal(4)
118 expect(video
.licenceLabel
).to
.equal('Attribution - Non Commercial')
119 expect(video
.language
).to
.equal(9)
120 expect(video
.languageLabel
).to
.equal('Japanese')
121 expect(video
.nsfw
).to
.be
.truthy
122 expect(video
.description
).to
.equal('my super description for pod 1')
123 expect(video
.podHost
).to
.equal('localhost:9001')
124 expect(video
.magnetUri
).to
.exist
125 expect(video
.duration
).to
.equal(10)
126 expect(video
.tags
).to
.deep
.equal([ 'tag1p1', 'tag2p1' ])
127 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
128 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
129 expect(video
.author
).to
.equal('root')
131 if (server
.url
!== 'http://localhost:9001') {
132 expect(video
.isLocal
).to
.be
.false
134 expect(video
.isLocal
).to
.be
.true
137 // All pods should have the same magnet Uri
138 if (baseMagnet
=== null) {
139 baseMagnet
= video
.magnetUri
141 expect(video
.magnetUri
).to
.equal
.magnetUri
144 videosUtils
.testVideoImage(server
.url
, 'video_short1.webm', video
.thumbnailPath
, function (err
, test
) {
146 expect(test
).to
.equal(true)
156 it('Should upload the video on pod 2 and propagate on each pod', function (done
) {
161 const videoAttributes
= {
162 name: 'my super name for pod 2',
167 description: 'my super description for pod 2',
168 tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ],
169 fixture: 'video_short2.webm'
171 videosUtils
.uploadVideo(servers
[1].url
, servers
[1].accessToken
, videoAttributes
, next
)
174 // Transcoding, so wait more that 22 seconds
175 setTimeout(next
, 42000)
177 // All pods should have this video
181 each(servers
, function (server
, callback
) {
182 let baseMagnet
= null
184 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
187 const videos
= res
.body
.data
188 expect(videos
).to
.be
.an('array')
189 expect(videos
.length
).to
.equal(2)
190 const video
= videos
[1]
191 expect(video
.name
).to
.equal('my super name for pod 2')
192 expect(video
.category
).to
.equal(4)
193 expect(video
.categoryLabel
).to
.equal('Art')
194 expect(video
.licence
).to
.equal(3)
195 expect(video
.licenceLabel
).to
.equal('Attribution - No Derivatives')
196 expect(video
.language
).to
.equal(11)
197 expect(video
.languageLabel
).to
.equal('German')
198 expect(video
.nsfw
).to
.be
.falsy
199 expect(video
.description
).to
.equal('my super description for pod 2')
200 expect(video
.podHost
).to
.equal('localhost:9002')
201 expect(video
.magnetUri
).to
.exist
202 expect(video
.duration
).to
.equal(5)
203 expect(video
.tags
).to
.deep
.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ])
204 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
205 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
206 expect(video
.author
).to
.equal('root')
208 if (server
.url
!== 'http://localhost:9002') {
209 expect(video
.isLocal
).to
.be
.false
211 expect(video
.isLocal
).to
.be
.true
214 // All pods should have the same magnet Uri
215 if (baseMagnet
=== null) {
216 baseMagnet
= video
.magnetUri
218 expect(video
.magnetUri
).to
.equal
.magnetUri
221 videosUtils
.testVideoImage(server
.url
, 'video_short2.webm', video
.thumbnailPath
, function (err
, test
) {
223 expect(test
).to
.equal(true)
233 it('Should upload two videos on pod 3 and propagate on each pod', function (done
) {
238 const videoAttributes
= {
239 name: 'my super name for pod 3',
244 description: 'my super description for pod 3',
246 fixture: 'video_short3.webm'
248 videosUtils
.uploadVideo(servers
[2].url
, servers
[2].accessToken
, videoAttributes
, next
)
251 const videoAttributes
= {
252 name: 'my super name for pod 3-2',
257 description: 'my super description for pod 3-2',
258 tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ],
259 fixture: 'video_short.webm'
261 videosUtils
.uploadVideo(servers
[2].url
, servers
[2].accessToken
, videoAttributes
, next
)
264 setTimeout(next
, 33000)
269 let baseMagnet
= null
270 // All pods should have this video
271 each(servers
, function (server
, callback
) {
272 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
275 const videos
= res
.body
.data
276 expect(videos
).to
.be
.an('array')
277 expect(videos
.length
).to
.equal(4)
279 // We not sure about the order of the two last uploads
282 if (videos
[2].name
=== 'my super name for pod 3') {
290 expect(video1
.name
).to
.equal('my super name for pod 3')
291 expect(video1
.category
).to
.equal(6)
292 expect(video1
.categoryLabel
).to
.equal('Travels')
293 expect(video1
.licence
).to
.equal(5)
294 expect(video1
.licenceLabel
).to
.equal('Attribution - Non Commercial - Share Alike')
295 expect(video1
.language
).to
.equal(11)
296 expect(video1
.languageLabel
).to
.equal('German')
297 expect(video1
.nsfw
).to
.be
.truthy
298 expect(video1
.description
).to
.equal('my super description for pod 3')
299 expect(video1
.podHost
).to
.equal('localhost:9003')
300 expect(video1
.magnetUri
).to
.exist
301 expect(video1
.duration
).to
.equal(5)
302 expect(video1
.tags
).to
.deep
.equal([ 'tag1p3' ])
303 expect(video1
.author
).to
.equal('root')
304 expect(miscsUtils
.dateIsValid(video1
.createdAt
)).to
.be
.true
305 expect(miscsUtils
.dateIsValid(video1
.updatedAt
)).to
.be
.true
307 expect(video2
.name
).to
.equal('my super name for pod 3-2')
308 expect(video2
.category
).to
.equal(7)
309 expect(video2
.categoryLabel
).to
.equal('Gaming')
310 expect(video2
.licence
).to
.equal(6)
311 expect(video2
.licenceLabel
).to
.equal('Attribution - Non Commercial - No Derivatives')
312 expect(video2
.language
).to
.equal(12)
313 expect(video2
.languageLabel
).to
.equal('Korean')
314 expect(video2
.nsfw
).to
.be
.falsy
315 expect(video2
.description
).to
.equal('my super description for pod 3-2')
316 expect(video2
.podHost
).to
.equal('localhost:9003')
317 expect(video2
.magnetUri
).to
.exist
318 expect(video2
.duration
).to
.equal(5)
319 expect(video2
.tags
).to
.deep
.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ])
320 expect(video2
.author
).to
.equal('root')
321 expect(miscsUtils
.dateIsValid(video2
.createdAt
)).to
.be
.true
322 expect(miscsUtils
.dateIsValid(video2
.updatedAt
)).to
.be
.true
324 if (server
.url
!== 'http://localhost:9003') {
325 expect(video1
.isLocal
).to
.be
.false
326 expect(video2
.isLocal
).to
.be
.false
328 expect(video1
.isLocal
).to
.be
.true
329 expect(video2
.isLocal
).to
.be
.true
332 // All pods should have the same magnet Uri
333 if (baseMagnet
=== null) {
334 baseMagnet
= video2
.magnetUri
336 expect(video2
.magnetUri
).to
.equal
.magnetUri
339 videosUtils
.testVideoImage(server
.url
, 'video_short3.webm', video1
.thumbnailPath
, function (err
, test
) {
341 expect(test
).to
.equal(true)
343 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video2
.thumbnailPath
, function (err
, test
) {
345 expect(test
).to
.equal(true)
357 describe('Should seed the uploaded video', function () {
358 it('Should add the file 1 by asking pod 3', function (done
) {
359 // Yes, this could be long
362 videosUtils
.getVideosList(servers
[2].url
, function (err
, res
) {
365 const video
= res
.body
.data
[0]
366 toRemove
.push(res
.body
.data
[2])
367 toRemove
.push(res
.body
.data
[3])
369 webtorrent
.add(video
.magnetUri
, function (torrent
) {
370 expect(torrent
.files
).to
.exist
371 expect(torrent
.files
.length
).to
.equal(1)
372 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
379 it('Should add the file 2 by asking pod 1', function (done
) {
380 // Yes, this could be long
383 videosUtils
.getVideosList(servers
[0].url
, function (err
, res
) {
386 const video
= res
.body
.data
[1]
388 webtorrent
.add(video
.magnetUri
, function (torrent
) {
389 expect(torrent
.files
).to
.exist
390 expect(torrent
.files
.length
).to
.equal(1)
391 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
398 it('Should add the file 3 by asking pod 2', function (done
) {
399 // Yes, this could be long
402 videosUtils
.getVideosList(servers
[1].url
, function (err
, res
) {
405 const video
= res
.body
.data
[2]
407 webtorrent
.add(video
.magnetUri
, function (torrent
) {
408 expect(torrent
.files
).to
.exist
409 expect(torrent
.files
.length
).to
.equal(1)
410 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
417 it('Should add the file 3-2 by asking pod 1', function (done
) {
418 // Yes, this could be long
421 videosUtils
.getVideosList(servers
[0].url
, function (err
, res
) {
424 const video
= res
.body
.data
[3]
426 webtorrent
.add(video
.magnetUri
, function (torrent
) {
427 expect(torrent
.files
).to
.exist
428 expect(torrent
.files
.length
).to
.equal(1)
429 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
437 describe('Should update video views, likes and dislikes', function () {
438 let localVideosPod3
= []
439 let remoteVideosPod1
= []
440 let remoteVideosPod2
= []
441 let remoteVideosPod3
= []
443 before(function (done
) {
445 function (callback
) {
446 videosUtils
.getVideosList(servers
[0].url
, function (err
, res
) {
449 remoteVideosPod1
= res
.body
.data
.filter(video
=> video
.isLocal
=== false).map(video
=> video
.id
)
455 function (callback
) {
456 videosUtils
.getVideosList(servers
[1].url
, function (err
, res
) {
459 remoteVideosPod2
= res
.body
.data
.filter(video
=> video
.isLocal
=== false).map(video
=> video
.id
)
465 function (callback
) {
466 videosUtils
.getVideosList(servers
[2].url
, function (err
, res
) {
469 localVideosPod3
= res
.body
.data
.filter(video
=> video
.isLocal
=== true).map(video
=> video
.id
)
470 remoteVideosPod3
= res
.body
.data
.filter(video
=> video
.isLocal
=== false).map(video
=> video
.id
)
478 it('Should view multiple videos on owned servers', function (done
) {
482 function (callback
) {
483 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[0], callback
)
486 function (callback
) {
487 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[0], callback
)
490 function (callback
) {
491 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[0], callback
)
494 function (callback
) {
495 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[1], callback
)
498 function (callback
) {
499 setTimeout(callback
, 22000)
504 eachSeries(servers
, function (server
, callback
) {
505 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
508 const videos
= res
.body
.data
509 expect(videos
.find(video
=> video
.views
=== 3)).to
.exist
510 expect(videos
.find(video
=> video
.views
=== 1)).to
.exist
518 it('Should view multiple videos on each servers', function (done
) {
522 function (callback
) {
523 videosUtils
.getVideo(servers
[0].url
, remoteVideosPod1
[0], callback
)
526 function (callback
) {
527 videosUtils
.getVideo(servers
[1].url
, remoteVideosPod2
[0], callback
)
530 function (callback
) {
531 videosUtils
.getVideo(servers
[1].url
, remoteVideosPod2
[0], callback
)
534 function (callback
) {
535 videosUtils
.getVideo(servers
[2].url
, remoteVideosPod3
[0], callback
)
538 function (callback
) {
539 videosUtils
.getVideo(servers
[2].url
, remoteVideosPod3
[1], callback
)
542 function (callback
) {
543 videosUtils
.getVideo(servers
[2].url
, remoteVideosPod3
[1], callback
)
546 function (callback
) {
547 videosUtils
.getVideo(servers
[2].url
, remoteVideosPod3
[1], callback
)
550 function (callback
) {
551 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[1], callback
)
554 function (callback
) {
555 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[1], callback
)
558 function (callback
) {
559 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[1], callback
)
562 function (callback
) {
563 setTimeout(callback
, 22000)
568 let baseVideos
= null
569 eachSeries(servers
, function (server
, callback
) {
570 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
573 const videos
= res
.body
.data
575 // Initialize base videos for future comparisons
576 if (baseVideos
=== null) {
581 baseVideos
.forEach(baseVideo
=> {
582 const sameVideo
= videos
.find(video
=> video
.name
=== baseVideo
.name
)
583 expect(baseVideo
.views
).to
.equal(sameVideo
.views
)
592 it('Should like and dislikes videos on different services', function (done
) {
596 function (callback
) {
597 videosUtils
.rateVideo(servers
[0].url
, servers
[0].accessToken
, remoteVideosPod1
[0], 'like', callback
)
600 function (callback
) {
601 videosUtils
.rateVideo(servers
[0].url
, servers
[0].accessToken
, remoteVideosPod1
[0], 'dislike', callback
)
604 function (callback
) {
605 videosUtils
.rateVideo(servers
[0].url
, servers
[0].accessToken
, remoteVideosPod1
[0], 'like', callback
)
608 function (callback
) {
609 videosUtils
.rateVideo(servers
[2].url
, servers
[2].accessToken
, localVideosPod3
[1], 'like', callback
)
612 function (callback
) {
613 videosUtils
.rateVideo(servers
[2].url
, servers
[2].accessToken
, localVideosPod3
[1], 'dislike', callback
)
616 function (callback
) {
617 videosUtils
.rateVideo(servers
[2].url
, servers
[2].accessToken
, remoteVideosPod3
[1], 'dislike', callback
)
620 function (callback
) {
621 videosUtils
.rateVideo(servers
[2].url
, servers
[2].accessToken
, remoteVideosPod3
[0], 'like', callback
)
624 function (callback
) {
625 setTimeout(callback
, 22000)
630 let baseVideos
= null
631 eachSeries(servers
, function (server
, callback
) {
632 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
635 const videos
= res
.body
.data
637 // Initialize base videos for future comparisons
638 if (baseVideos
=== null) {
643 baseVideos
.forEach(baseVideo
=> {
644 const sameVideo
= videos
.find(video
=> video
.name
=== baseVideo
.name
)
645 expect(baseVideo
.likes
).to
.equal(sameVideo
.likes
)
646 expect(baseVideo
.dislikes
).to
.equal(sameVideo
.dislikes
)
656 describe('Should manipulate these videos', function () {
657 it('Should update the video 3 by asking pod 3', function (done
) {
661 name: 'my super video updated',
666 description: 'my super description updated',
667 tags: [ 'tagup1', 'tagup2' ]
669 videosUtils
.updateVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[0].id
, attributes
, function (err
) {
672 setTimeout(done
, 11000)
676 it('Should have the video 3 updated on each pod', function (done
) {
679 each(servers
, function (server
, callback
) {
680 // Avoid "duplicate torrent" errors
681 const webtorrent
= new WebTorrent()
683 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
686 const videos
= res
.body
.data
687 const videoUpdated
= videos
.find(function (video
) {
688 return video
.name
=== 'my super video updated'
691 expect(!!videoUpdated
).to
.be
.true
692 expect(videoUpdated
.category
).to
.equal(10)
693 expect(videoUpdated
.categoryLabel
).to
.equal('Entertainment')
694 expect(videoUpdated
.licence
).to
.equal(7)
695 expect(videoUpdated
.licenceLabel
).to
.equal('Public Domain Dedication')
696 expect(videoUpdated
.language
).to
.equal(13)
697 expect(videoUpdated
.languageLabel
).to
.equal('French')
698 expect(videoUpdated
.nsfw
).to
.be
.truthy
699 expect(videoUpdated
.description
).to
.equal('my super description updated')
700 expect(videoUpdated
.tags
).to
.deep
.equal([ 'tagup1', 'tagup2' ])
701 expect(miscsUtils
.dateIsValid(videoUpdated
.updatedAt
, 20000)).to
.be
.true
703 videosUtils
.testVideoImage(server
.url
, 'video_short3.webm', videoUpdated
.thumbnailPath
, function (err
, test
) {
705 expect(test
).to
.equal(true)
707 webtorrent
.add(videoUpdated
.magnetUri
, function (torrent
) {
708 expect(torrent
.files
).to
.exist
709 expect(torrent
.files
.length
).to
.equal(1)
710 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
719 it('Should remove the videos 3 and 3-2 by asking pod 3', function (done
) {
724 videosUtils
.removeVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[0].id
, next
)
727 videosUtils
.removeVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[1].id
, next
)
731 setTimeout(done
, 11000)
736 it('Should have videos 1 and 3 on each pod', function (done
) {
737 each(servers
, function (server
, callback
) {
738 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
741 const videos
= res
.body
.data
742 expect(videos
).to
.be
.an('array')
743 expect(videos
.length
).to
.equal(2)
744 expect(videos
[0].name
).not
.to
.equal(videos
[1].name
)
745 expect(videos
[0].name
).not
.to
.equal(toRemove
[0].name
)
746 expect(videos
[1].name
).not
.to
.equal(toRemove
[0].name
)
747 expect(videos
[0].name
).not
.to
.equal(toRemove
[1].name
)
748 expect(videos
[1].name
).not
.to
.equal(toRemove
[1].name
)
750 videoUUID
= videos
.find(video
=> video
.name
=== 'my super name for pod 1').uuid
757 it('Should get the same video by UUID on each pod', function (done
) {
759 each(servers
, function (server
, callback
) {
760 videosUtils
.getVideo(server
.url
, videoUUID
, function (err
, res
) {
763 const video
= res
.body
765 if (baseVideo
=== null) {
770 expect(baseVideo
.name
).to
.equal(video
.name
)
771 expect(baseVideo
.uuid
).to
.equal(video
.uuid
)
772 expect(baseVideo
.category
).to
.equal(video
.category
)
773 expect(baseVideo
.language
).to
.equal(video
.language
)
774 expect(baseVideo
.licence
).to
.equal(video
.licence
)
775 expect(baseVideo
.category
).to
.equal(video
.category
)
776 expect(baseVideo
.nsfw
).to
.equal(video
.nsfw
)
777 expect(baseVideo
.author
).to
.equal(video
.author
)
778 expect(baseVideo
.tags
).to
.deep
.equal(video
.tags
)
785 it('Should get the preview from each pod', function (done
) {
786 each(servers
, function (server
, callback
) {
787 videosUtils
.getVideo(server
.url
, videoUUID
, function (err
, res
) {
790 const video
= res
.body
792 videosUtils
.testVideoImage(server
.url
, 'video_short1-preview.webm', video
.previewPath
, function (err
, test
) {
794 expect(test
).to
.equal(true)
803 after(function (done
) {
804 servers
.forEach(function (server
) {
805 process
.kill(-server
.app
.pid
)
808 // Keep the logs if the test failed
810 serversUtils
.flushTests(done
)