]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/multiple-pods.js
cc4f7be701090d94fc6e622fab4454444849d013
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
) {
83 const videoAttributes
= {
84 name: 'my super name for pod 1',
88 description: 'my super description for pod 1',
89 tags: [ 'tag1p1', 'tag2p1' ],
90 fixture: 'video_short1.webm'
92 videosUtils
.uploadVideo(servers
[0].url
, servers
[0].accessToken
, videoAttributes
, next
)
95 setTimeout(next
, 11000)
97 // All pods should have this video
101 each(servers
, function (server
, callback
) {
102 let baseMagnet
= null
104 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
107 const videos
= res
.body
.data
108 expect(videos
).to
.be
.an('array')
109 expect(videos
.length
).to
.equal(1)
110 const video
= videos
[0]
111 expect(video
.name
).to
.equal('my super name for pod 1')
112 expect(video
.category
).to
.equal(5)
113 expect(video
.categoryLabel
).to
.equal('Sports')
114 expect(video
.licence
).to
.equal(4)
115 expect(video
.licenceLabel
).to
.equal('Attribution - Non Commercial')
116 expect(video
.nsfw
).to
.be
.truthy
117 expect(video
.description
).to
.equal('my super description for pod 1')
118 expect(video
.podHost
).to
.equal('localhost:9001')
119 expect(video
.magnetUri
).to
.exist
120 expect(video
.duration
).to
.equal(10)
121 expect(video
.tags
).to
.deep
.equal([ 'tag1p1', 'tag2p1' ])
122 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
123 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
124 expect(video
.author
).to
.equal('root')
126 if (server
.url
!== 'http://localhost:9001') {
127 expect(video
.isLocal
).to
.be
.false
129 expect(video
.isLocal
).to
.be
.true
132 // All pods should have the same magnet Uri
133 if (baseMagnet
=== null) {
134 baseMagnet
= video
.magnetUri
136 expect(video
.magnetUri
).to
.equal
.magnetUri
139 videosUtils
.testVideoImage(server
.url
, 'video_short1.webm', video
.thumbnailPath
, function (err
, test
) {
141 expect(test
).to
.equal(true)
151 it('Should upload the video on pod 2 and propagate on each pod', function (done
) {
156 const videoAttributes
= {
157 name: 'my super name for pod 2',
161 description: 'my super description for pod 2',
162 tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ],
163 fixture: 'video_short2.webm'
165 videosUtils
.uploadVideo(servers
[1].url
, servers
[1].accessToken
, videoAttributes
, next
)
168 setTimeout(next
, 11000)
170 // All pods should have this video
174 each(servers
, function (server
, callback
) {
175 let baseMagnet
= null
177 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
180 const videos
= res
.body
.data
181 expect(videos
).to
.be
.an('array')
182 expect(videos
.length
).to
.equal(2)
183 const video
= videos
[1]
184 expect(video
.name
).to
.equal('my super name for pod 2')
185 expect(video
.category
).to
.equal(4)
186 expect(video
.categoryLabel
).to
.equal('Art')
187 expect(video
.licence
).to
.equal(3)
188 expect(video
.licenceLabel
).to
.equal('Attribution - No Derivatives')
189 expect(video
.nsfw
).to
.be
.falsy
190 expect(video
.description
).to
.equal('my super description for pod 2')
191 expect(video
.podHost
).to
.equal('localhost:9002')
192 expect(video
.magnetUri
).to
.exist
193 expect(video
.duration
).to
.equal(5)
194 expect(video
.tags
).to
.deep
.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ])
195 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
196 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
197 expect(video
.author
).to
.equal('root')
199 if (server
.url
!== 'http://localhost:9002') {
200 expect(video
.isLocal
).to
.be
.false
202 expect(video
.isLocal
).to
.be
.true
205 // All pods should have the same magnet Uri
206 if (baseMagnet
=== null) {
207 baseMagnet
= video
.magnetUri
209 expect(video
.magnetUri
).to
.equal
.magnetUri
212 videosUtils
.testVideoImage(server
.url
, 'video_short2.webm', video
.thumbnailPath
, function (err
, test
) {
214 expect(test
).to
.equal(true)
224 it('Should upload two videos on pod 3 and propagate on each pod', function (done
) {
229 const videoAttributes
= {
230 name: 'my super name for pod 3',
234 description: 'my super description for pod 3',
236 fixture: 'video_short3.webm'
238 videosUtils
.uploadVideo(servers
[2].url
, servers
[2].accessToken
, videoAttributes
, next
)
241 const videoAttributes
= {
242 name: 'my super name for pod 3-2',
246 description: 'my super description for pod 3-2',
247 tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ],
248 fixture: 'video_short.webm'
250 videosUtils
.uploadVideo(servers
[2].url
, servers
[2].accessToken
, videoAttributes
, next
)
253 setTimeout(next
, 22000)
258 let baseMagnet
= null
259 // All pods should have this video
260 each(servers
, function (server
, callback
) {
261 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
264 const videos
= res
.body
.data
265 expect(videos
).to
.be
.an('array')
266 expect(videos
.length
).to
.equal(4)
268 // We not sure about the order of the two last uploads
271 if (videos
[2].name
=== 'my super name for pod 3') {
279 expect(video1
.name
).to
.equal('my super name for pod 3')
280 expect(video1
.category
).to
.equal(6)
281 expect(video1
.categoryLabel
).to
.equal('Travels')
282 expect(video1
.licence
).to
.equal(5)
283 expect(video1
.licenceLabel
).to
.equal('Attribution - Non Commercial - Share Alike')
284 expect(video1
.nsfw
).to
.be
.truthy
285 expect(video1
.description
).to
.equal('my super description for pod 3')
286 expect(video1
.podHost
).to
.equal('localhost:9003')
287 expect(video1
.magnetUri
).to
.exist
288 expect(video1
.duration
).to
.equal(5)
289 expect(video1
.tags
).to
.deep
.equal([ 'tag1p3' ])
290 expect(video1
.author
).to
.equal('root')
291 expect(miscsUtils
.dateIsValid(video1
.createdAt
)).to
.be
.true
292 expect(miscsUtils
.dateIsValid(video1
.updatedAt
)).to
.be
.true
294 expect(video2
.name
).to
.equal('my super name for pod 3-2')
295 expect(video2
.category
).to
.equal(7)
296 expect(video2
.categoryLabel
).to
.equal('Gaming')
297 expect(video2
.licence
).to
.equal(6)
298 expect(video2
.licenceLabel
).to
.equal('Attribution - Non Commercial - No Derivatives')
299 expect(video2
.nsfw
).to
.be
.falsy
300 expect(video2
.description
).to
.equal('my super description for pod 3-2')
301 expect(video2
.podHost
).to
.equal('localhost:9003')
302 expect(video2
.magnetUri
).to
.exist
303 expect(video2
.duration
).to
.equal(5)
304 expect(video2
.tags
).to
.deep
.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ])
305 expect(video2
.author
).to
.equal('root')
306 expect(miscsUtils
.dateIsValid(video2
.createdAt
)).to
.be
.true
307 expect(miscsUtils
.dateIsValid(video2
.updatedAt
)).to
.be
.true
309 if (server
.url
!== 'http://localhost:9003') {
310 expect(video1
.isLocal
).to
.be
.false
311 expect(video2
.isLocal
).to
.be
.false
313 expect(video1
.isLocal
).to
.be
.true
314 expect(video2
.isLocal
).to
.be
.true
317 // All pods should have the same magnet Uri
318 if (baseMagnet
=== null) {
319 baseMagnet
= video2
.magnetUri
321 expect(video2
.magnetUri
).to
.equal
.magnetUri
324 videosUtils
.testVideoImage(server
.url
, 'video_short3.webm', video1
.thumbnailPath
, function (err
, test
) {
326 expect(test
).to
.equal(true)
328 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video2
.thumbnailPath
, function (err
, test
) {
330 expect(test
).to
.equal(true)
342 describe('Should seed the uploaded video', function () {
343 it('Should add the file 1 by asking pod 3', function (done
) {
344 // Yes, this could be long
347 videosUtils
.getVideosList(servers
[2].url
, function (err
, res
) {
350 const video
= res
.body
.data
[0]
351 toRemove
.push(res
.body
.data
[2])
352 toRemove
.push(res
.body
.data
[3])
354 webtorrent
.add(video
.magnetUri
, function (torrent
) {
355 expect(torrent
.files
).to
.exist
356 expect(torrent
.files
.length
).to
.equal(1)
357 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
364 it('Should add the file 2 by asking pod 1', function (done
) {
365 // Yes, this could be long
368 videosUtils
.getVideosList(servers
[0].url
, function (err
, res
) {
371 const video
= res
.body
.data
[1]
373 webtorrent
.add(video
.magnetUri
, function (torrent
) {
374 expect(torrent
.files
).to
.exist
375 expect(torrent
.files
.length
).to
.equal(1)
376 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
383 it('Should add the file 3 by asking pod 2', function (done
) {
384 // Yes, this could be long
387 videosUtils
.getVideosList(servers
[1].url
, function (err
, res
) {
390 const video
= res
.body
.data
[2]
392 webtorrent
.add(video
.magnetUri
, function (torrent
) {
393 expect(torrent
.files
).to
.exist
394 expect(torrent
.files
.length
).to
.equal(1)
395 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
402 it('Should add the file 3-2 by asking pod 1', function (done
) {
403 // Yes, this could be long
406 videosUtils
.getVideosList(servers
[0].url
, function (err
, res
) {
409 const video
= res
.body
.data
[3]
411 webtorrent
.add(video
.magnetUri
, function (torrent
) {
412 expect(torrent
.files
).to
.exist
413 expect(torrent
.files
.length
).to
.equal(1)
414 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
422 describe('Should update video views, likes and dislikes', function () {
423 let localVideosPod3
= []
424 let remoteVideosPod1
= []
425 let remoteVideosPod2
= []
426 let remoteVideosPod3
= []
428 before(function (done
) {
430 function (callback
) {
431 videosUtils
.getVideosList(servers
[0].url
, function (err
, res
) {
434 remoteVideosPod1
= res
.body
.data
.filter(video
=> video
.isLocal
=== false).map(video
=> video
.id
)
440 function (callback
) {
441 videosUtils
.getVideosList(servers
[1].url
, function (err
, res
) {
444 remoteVideosPod2
= res
.body
.data
.filter(video
=> video
.isLocal
=== false).map(video
=> video
.id
)
450 function (callback
) {
451 videosUtils
.getVideosList(servers
[2].url
, function (err
, res
) {
454 localVideosPod3
= res
.body
.data
.filter(video
=> video
.isLocal
=== true).map(video
=> video
.id
)
455 remoteVideosPod3
= res
.body
.data
.filter(video
=> video
.isLocal
=== false).map(video
=> video
.id
)
463 it('Should view multiple videos on owned servers', function (done
) {
467 function (callback
) {
468 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[0], callback
)
471 function (callback
) {
472 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[0], callback
)
475 function (callback
) {
476 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[0], callback
)
479 function (callback
) {
480 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[1], callback
)
483 function (callback
) {
484 setTimeout(callback
, 22000)
489 eachSeries(servers
, function (server
, callback
) {
490 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
493 const videos
= res
.body
.data
494 expect(videos
.find(video
=> video
.views
=== 3)).to
.exist
495 expect(videos
.find(video
=> video
.views
=== 1)).to
.exist
503 it('Should view multiple videos on each servers', function (done
) {
507 function (callback
) {
508 videosUtils
.getVideo(servers
[0].url
, remoteVideosPod1
[0], callback
)
511 function (callback
) {
512 videosUtils
.getVideo(servers
[1].url
, remoteVideosPod2
[0], callback
)
515 function (callback
) {
516 videosUtils
.getVideo(servers
[1].url
, remoteVideosPod2
[0], callback
)
519 function (callback
) {
520 videosUtils
.getVideo(servers
[2].url
, remoteVideosPod3
[0], callback
)
523 function (callback
) {
524 videosUtils
.getVideo(servers
[2].url
, remoteVideosPod3
[1], callback
)
527 function (callback
) {
528 videosUtils
.getVideo(servers
[2].url
, remoteVideosPod3
[1], callback
)
531 function (callback
) {
532 videosUtils
.getVideo(servers
[2].url
, remoteVideosPod3
[1], callback
)
535 function (callback
) {
536 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[1], callback
)
539 function (callback
) {
540 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[1], callback
)
543 function (callback
) {
544 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[1], callback
)
547 function (callback
) {
548 setTimeout(callback
, 22000)
553 let baseVideos
= null
554 eachSeries(servers
, function (server
, callback
) {
555 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
558 const videos
= res
.body
.data
560 // Initialize base videos for future comparisons
561 if (baseVideos
=== null) {
566 baseVideos
.forEach(baseVideo
=> {
567 const sameVideo
= videos
.find(video
=> video
.name
=== baseVideo
.name
)
568 expect(baseVideo
.views
).to
.equal(sameVideo
.views
)
577 it('Should like and dislikes videos on different services', function (done
) {
581 function (callback
) {
582 videosUtils
.rateVideo(servers
[0].url
, servers
[0].accessToken
, remoteVideosPod1
[0], 'like', callback
)
585 function (callback
) {
586 videosUtils
.rateVideo(servers
[0].url
, servers
[0].accessToken
, remoteVideosPod1
[0], 'dislike', callback
)
589 function (callback
) {
590 videosUtils
.rateVideo(servers
[0].url
, servers
[0].accessToken
, remoteVideosPod1
[0], 'like', callback
)
593 function (callback
) {
594 videosUtils
.rateVideo(servers
[2].url
, servers
[2].accessToken
, localVideosPod3
[1], 'like', callback
)
597 function (callback
) {
598 videosUtils
.rateVideo(servers
[2].url
, servers
[2].accessToken
, localVideosPod3
[1], 'dislike', callback
)
601 function (callback
) {
602 videosUtils
.rateVideo(servers
[2].url
, servers
[2].accessToken
, remoteVideosPod3
[1], 'dislike', callback
)
605 function (callback
) {
606 videosUtils
.rateVideo(servers
[2].url
, servers
[2].accessToken
, remoteVideosPod3
[0], 'like', callback
)
609 function (callback
) {
610 setTimeout(callback
, 22000)
615 let baseVideos
= null
616 eachSeries(servers
, function (server
, callback
) {
617 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
620 const videos
= res
.body
.data
622 // Initialize base videos for future comparisons
623 if (baseVideos
=== null) {
628 baseVideos
.forEach(baseVideo
=> {
629 const sameVideo
= videos
.find(video
=> video
.name
=== baseVideo
.name
)
630 expect(baseVideo
.likes
).to
.equal(sameVideo
.likes
)
631 expect(baseVideo
.dislikes
).to
.equal(sameVideo
.dislikes
)
641 describe('Should manipulate these videos', function () {
642 it('Should update the video 3 by asking pod 3', function (done
) {
646 name: 'my super video updated',
650 description: 'my super description updated',
651 tags: [ 'tagup1', 'tagup2' ]
653 videosUtils
.updateVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[0].id
, attributes
, function (err
) {
656 setTimeout(done
, 11000)
660 it('Should have the video 3 updated on each pod', function (done
) {
663 each(servers
, function (server
, callback
) {
664 // Avoid "duplicate torrent" errors
665 const webtorrent
= new WebTorrent()
667 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
670 const videos
= res
.body
.data
671 const videoUpdated
= videos
.find(function (video
) {
672 return video
.name
=== 'my super video updated'
675 expect(!!videoUpdated
).to
.be
.true
676 expect(videoUpdated
.category
).to
.equal(10)
677 expect(videoUpdated
.categoryLabel
).to
.equal('Entertainment')
678 expect(videoUpdated
.licence
).to
.equal(7)
679 expect(videoUpdated
.licenceLabel
).to
.equal('Public Domain Dedication')
680 expect(videoUpdated
.nsfw
).to
.be
.truthy
681 expect(videoUpdated
.description
).to
.equal('my super description updated')
682 expect(videoUpdated
.tags
).to
.deep
.equal([ 'tagup1', 'tagup2' ])
683 expect(miscsUtils
.dateIsValid(videoUpdated
.updatedAt
, 20000)).to
.be
.true
685 videosUtils
.testVideoImage(server
.url
, 'video_short3.webm', videoUpdated
.thumbnailPath
, function (err
, test
) {
687 expect(test
).to
.equal(true)
689 webtorrent
.add(videoUpdated
.magnetUri
, function (torrent
) {
690 expect(torrent
.files
).to
.exist
691 expect(torrent
.files
.length
).to
.equal(1)
692 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
701 it('Should remove the videos 3 and 3-2 by asking pod 3', function (done
) {
706 videosUtils
.removeVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[0].id
, next
)
709 videosUtils
.removeVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[1].id
, next
)
713 setTimeout(done
, 11000)
718 it('Should have videos 1 and 3 on each pod', function (done
) {
719 each(servers
, function (server
, callback
) {
720 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
723 const videos
= res
.body
.data
724 expect(videos
).to
.be
.an('array')
725 expect(videos
.length
).to
.equal(2)
726 expect(videos
[0].name
).not
.to
.equal(videos
[1].name
)
727 expect(videos
[0].name
).not
.to
.equal(toRemove
[0].name
)
728 expect(videos
[1].name
).not
.to
.equal(toRemove
[0].name
)
729 expect(videos
[0].name
).not
.to
.equal(toRemove
[1].name
)
730 expect(videos
[1].name
).not
.to
.equal(toRemove
[1].name
)
738 after(function (done
) {
739 servers
.forEach(function (server
) {
740 process
.kill(-server
.app
.pid
)
743 // Keep the logs if the test failed
745 serversUtils
.flushTests(done
)