]>
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 () {
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',
85 description: 'my super description for pod 1',
86 tags: [ 'tag1p1', 'tag2p1' ],
87 fixture: 'video_short1.webm'
89 videosUtils
.uploadVideo(servers
[0].url
, servers
[0].accessToken
, videoAttributes
, next
)
92 setTimeout(next
, 11000)
94 // All pods should have this video
98 each(servers
, function (server
, callback
) {
101 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
104 const videos
= res
.body
.data
105 expect(videos
).to
.be
.an('array')
106 expect(videos
.length
).to
.equal(1)
107 const video
= videos
[0]
108 expect(video
.name
).to
.equal('my super name for pod 1')
109 expect(video
.category
).to
.equal(5)
110 expect(video
.categoryLabel
).to
.equal('Sports')
111 expect(video
.description
).to
.equal('my super description for pod 1')
112 expect(video
.podHost
).to
.equal('localhost:9001')
113 expect(video
.magnetUri
).to
.exist
114 expect(video
.duration
).to
.equal(10)
115 expect(video
.tags
).to
.deep
.equal([ 'tag1p1', 'tag2p1' ])
116 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
117 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
118 expect(video
.author
).to
.equal('root')
120 if (server
.url
!== 'http://localhost:9001') {
121 expect(video
.isLocal
).to
.be
.false
123 expect(video
.isLocal
).to
.be
.true
126 // All pods should have the same magnet Uri
127 if (baseMagnet
=== null) {
128 baseMagnet
= video
.magnetUri
130 expect(video
.magnetUri
).to
.equal
.magnetUri
133 videosUtils
.testVideoImage(server
.url
, 'video_short1.webm', video
.thumbnailPath
, function (err
, test
) {
135 expect(test
).to
.equal(true)
145 it('Should upload the video on pod 2 and propagate on each pod', function (done
) {
150 const videoAttributes
= {
151 name: 'my super name for pod 2',
153 description: 'my super description for pod 2',
154 tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ],
155 fixture: 'video_short2.webm'
157 videosUtils
.uploadVideo(servers
[1].url
, servers
[1].accessToken
, videoAttributes
, next
)
160 setTimeout(next
, 11000)
162 // All pods should have this video
166 each(servers
, function (server
, callback
) {
167 let baseMagnet
= null
169 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
172 const videos
= res
.body
.data
173 expect(videos
).to
.be
.an('array')
174 expect(videos
.length
).to
.equal(2)
175 const video
= videos
[1]
176 expect(video
.name
).to
.equal('my super name for pod 2')
177 expect(video
.category
).to
.equal(4)
178 expect(video
.categoryLabel
).to
.equal('Art')
179 expect(video
.description
).to
.equal('my super description for pod 2')
180 expect(video
.podHost
).to
.equal('localhost:9002')
181 expect(video
.magnetUri
).to
.exist
182 expect(video
.duration
).to
.equal(5)
183 expect(video
.tags
).to
.deep
.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ])
184 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
185 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
186 expect(video
.author
).to
.equal('root')
188 if (server
.url
!== 'http://localhost:9002') {
189 expect(video
.isLocal
).to
.be
.false
191 expect(video
.isLocal
).to
.be
.true
194 // All pods should have the same magnet Uri
195 if (baseMagnet
=== null) {
196 baseMagnet
= video
.magnetUri
198 expect(video
.magnetUri
).to
.equal
.magnetUri
201 videosUtils
.testVideoImage(server
.url
, 'video_short2.webm', video
.thumbnailPath
, function (err
, test
) {
203 expect(test
).to
.equal(true)
213 it('Should upload two videos on pod 3 and propagate on each pod', function (done
) {
218 const videoAttributes
= {
219 name: 'my super name for pod 3',
221 description: 'my super description for pod 3',
223 fixture: 'video_short3.webm'
225 videosUtils
.uploadVideo(servers
[2].url
, servers
[2].accessToken
, videoAttributes
, next
)
228 const videoAttributes
= {
229 name: 'my super name for pod 3-2',
231 description: 'my super description for pod 3-2',
232 tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ],
233 fixture: 'video_short.webm'
235 videosUtils
.uploadVideo(servers
[2].url
, servers
[2].accessToken
, videoAttributes
, next
)
238 setTimeout(next
, 22000)
243 let baseMagnet
= null
244 // All pods should have this video
245 each(servers
, function (server
, callback
) {
246 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
249 const videos
= res
.body
.data
250 expect(videos
).to
.be
.an('array')
251 expect(videos
.length
).to
.equal(4)
253 // We not sure about the order of the two last uploads
256 if (videos
[2].name
=== 'my super name for pod 3') {
264 expect(video1
.name
).to
.equal('my super name for pod 3')
265 expect(video1
.category
).to
.equal(6)
266 expect(video1
.categoryLabel
).to
.equal('Travels')
267 expect(video1
.description
).to
.equal('my super description for pod 3')
268 expect(video1
.podHost
).to
.equal('localhost:9003')
269 expect(video1
.magnetUri
).to
.exist
270 expect(video1
.duration
).to
.equal(5)
271 expect(video1
.tags
).to
.deep
.equal([ 'tag1p3' ])
272 expect(video1
.author
).to
.equal('root')
273 expect(miscsUtils
.dateIsValid(video1
.createdAt
)).to
.be
.true
274 expect(miscsUtils
.dateIsValid(video1
.updatedAt
)).to
.be
.true
276 expect(video2
.name
).to
.equal('my super name for pod 3-2')
277 expect(video2
.category
).to
.equal(7)
278 expect(video2
.categoryLabel
).to
.equal('Gaming')
279 expect(video2
.description
).to
.equal('my super description for pod 3-2')
280 expect(video2
.podHost
).to
.equal('localhost:9003')
281 expect(video2
.magnetUri
).to
.exist
282 expect(video2
.duration
).to
.equal(5)
283 expect(video2
.tags
).to
.deep
.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ])
284 expect(video2
.author
).to
.equal('root')
285 expect(miscsUtils
.dateIsValid(video2
.createdAt
)).to
.be
.true
286 expect(miscsUtils
.dateIsValid(video2
.updatedAt
)).to
.be
.true
288 if (server
.url
!== 'http://localhost:9003') {
289 expect(video1
.isLocal
).to
.be
.false
290 expect(video2
.isLocal
).to
.be
.false
292 expect(video1
.isLocal
).to
.be
.true
293 expect(video2
.isLocal
).to
.be
.true
296 // All pods should have the same magnet Uri
297 if (baseMagnet
=== null) {
298 baseMagnet
= video2
.magnetUri
300 expect(video2
.magnetUri
).to
.equal
.magnetUri
303 videosUtils
.testVideoImage(server
.url
, 'video_short3.webm', video1
.thumbnailPath
, function (err
, test
) {
305 expect(test
).to
.equal(true)
307 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video2
.thumbnailPath
, function (err
, test
) {
309 expect(test
).to
.equal(true)
321 describe('Should seed the uploaded video', function () {
322 it('Should add the file 1 by asking pod 3', function (done
) {
323 // Yes, this could be long
326 videosUtils
.getVideosList(servers
[2].url
, function (err
, res
) {
329 const video
= res
.body
.data
[0]
330 toRemove
.push(res
.body
.data
[2])
331 toRemove
.push(res
.body
.data
[3])
333 webtorrent
.add(video
.magnetUri
, function (torrent
) {
334 expect(torrent
.files
).to
.exist
335 expect(torrent
.files
.length
).to
.equal(1)
336 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
343 it('Should add the file 2 by asking pod 1', function (done
) {
344 // Yes, this could be long
347 videosUtils
.getVideosList(servers
[0].url
, function (err
, res
) {
350 const video
= res
.body
.data
[1]
352 webtorrent
.add(video
.magnetUri
, function (torrent
) {
353 expect(torrent
.files
).to
.exist
354 expect(torrent
.files
.length
).to
.equal(1)
355 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
362 it('Should add the file 3 by asking pod 2', function (done
) {
363 // Yes, this could be long
366 videosUtils
.getVideosList(servers
[1].url
, function (err
, res
) {
369 const video
= res
.body
.data
[2]
371 webtorrent
.add(video
.magnetUri
, function (torrent
) {
372 expect(torrent
.files
).to
.exist
373 expect(torrent
.files
.length
).to
.equal(1)
374 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
381 it('Should add the file 3-2 by asking pod 1', function (done
) {
382 // Yes, this could be long
385 videosUtils
.getVideosList(servers
[0].url
, function (err
, res
) {
388 const video
= res
.body
.data
[3]
390 webtorrent
.add(video
.magnetUri
, function (torrent
) {
391 expect(torrent
.files
).to
.exist
392 expect(torrent
.files
.length
).to
.equal(1)
393 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
401 describe('Should update video views, likes and dislikes', function () {
402 let localVideosPod3
= []
403 let remoteVideosPod1
= []
404 let remoteVideosPod2
= []
405 let remoteVideosPod3
= []
407 before(function (done
) {
409 function (callback
) {
410 videosUtils
.getVideosList(servers
[0].url
, function (err
, res
) {
413 remoteVideosPod1
= res
.body
.data
.filter(video
=> video
.isLocal
=== false).map(video
=> video
.id
)
419 function (callback
) {
420 videosUtils
.getVideosList(servers
[1].url
, function (err
, res
) {
423 remoteVideosPod2
= res
.body
.data
.filter(video
=> video
.isLocal
=== false).map(video
=> video
.id
)
429 function (callback
) {
430 videosUtils
.getVideosList(servers
[2].url
, function (err
, res
) {
433 localVideosPod3
= res
.body
.data
.filter(video
=> video
.isLocal
=== true).map(video
=> video
.id
)
434 remoteVideosPod3
= res
.body
.data
.filter(video
=> video
.isLocal
=== false).map(video
=> video
.id
)
442 it('Should view multiple videos on owned servers', function (done
) {
446 function (callback
) {
447 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[0], callback
)
450 function (callback
) {
451 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[0], callback
)
454 function (callback
) {
455 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[0], callback
)
458 function (callback
) {
459 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[1], callback
)
462 function (callback
) {
463 setTimeout(callback
, 22000)
468 eachSeries(servers
, function (server
, callback
) {
469 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
472 const videos
= res
.body
.data
473 expect(videos
.find(video
=> video
.views
=== 3)).to
.exist
474 expect(videos
.find(video
=> video
.views
=== 1)).to
.exist
482 it('Should view multiple videos on each servers', function (done
) {
486 function (callback
) {
487 videosUtils
.getVideo(servers
[0].url
, remoteVideosPod1
[0], callback
)
490 function (callback
) {
491 videosUtils
.getVideo(servers
[1].url
, remoteVideosPod2
[0], callback
)
494 function (callback
) {
495 videosUtils
.getVideo(servers
[1].url
, remoteVideosPod2
[0], callback
)
498 function (callback
) {
499 videosUtils
.getVideo(servers
[2].url
, remoteVideosPod3
[0], callback
)
502 function (callback
) {
503 videosUtils
.getVideo(servers
[2].url
, remoteVideosPod3
[1], callback
)
506 function (callback
) {
507 videosUtils
.getVideo(servers
[2].url
, remoteVideosPod3
[1], callback
)
510 function (callback
) {
511 videosUtils
.getVideo(servers
[2].url
, remoteVideosPod3
[1], callback
)
514 function (callback
) {
515 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[1], callback
)
518 function (callback
) {
519 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[1], callback
)
522 function (callback
) {
523 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[1], callback
)
526 function (callback
) {
527 setTimeout(callback
, 22000)
532 let baseVideos
= null
533 eachSeries(servers
, function (server
, callback
) {
534 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
537 const videos
= res
.body
.data
539 // Initialize base videos for future comparisons
540 if (baseVideos
=== null) {
545 baseVideos
.forEach(baseVideo
=> {
546 const sameVideo
= videos
.find(video
=> video
.name
=== baseVideo
.name
)
547 expect(baseVideo
.views
).to
.equal(sameVideo
.views
)
556 it('Should like and dislikes videos on different services', function (done
) {
560 function (callback
) {
561 videosUtils
.rateVideo(servers
[0].url
, servers
[0].accessToken
, remoteVideosPod1
[0], 'like', callback
)
564 function (callback
) {
565 videosUtils
.rateVideo(servers
[0].url
, servers
[0].accessToken
, remoteVideosPod1
[0], 'dislike', callback
)
568 function (callback
) {
569 videosUtils
.rateVideo(servers
[0].url
, servers
[0].accessToken
, remoteVideosPod1
[0], 'like', callback
)
572 function (callback
) {
573 videosUtils
.rateVideo(servers
[2].url
, servers
[2].accessToken
, localVideosPod3
[1], 'like', callback
)
576 function (callback
) {
577 videosUtils
.rateVideo(servers
[2].url
, servers
[2].accessToken
, localVideosPod3
[1], 'dislike', callback
)
580 function (callback
) {
581 videosUtils
.rateVideo(servers
[2].url
, servers
[2].accessToken
, remoteVideosPod3
[1], 'dislike', callback
)
584 function (callback
) {
585 videosUtils
.rateVideo(servers
[2].url
, servers
[2].accessToken
, remoteVideosPod3
[0], 'like', callback
)
588 function (callback
) {
589 setTimeout(callback
, 22000)
594 let baseVideos
= null
595 eachSeries(servers
, function (server
, callback
) {
596 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
599 const videos
= res
.body
.data
601 // Initialize base videos for future comparisons
602 if (baseVideos
=== null) {
607 baseVideos
.forEach(baseVideo
=> {
608 const sameVideo
= videos
.find(video
=> video
.name
=== baseVideo
.name
)
609 expect(baseVideo
.likes
).to
.equal(sameVideo
.likes
)
610 expect(baseVideo
.dislikes
).to
.equal(sameVideo
.dislikes
)
620 describe('Should manipulate these videos', function () {
621 it('Should update the video 3 by asking pod 3', function (done
) {
625 name: 'my super video updated',
627 description: 'my super description updated',
628 tags: [ 'tagup1', 'tagup2' ]
630 videosUtils
.updateVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[0].id
, attributes
, function (err
) {
633 setTimeout(done
, 11000)
637 it('Should have the video 3 updated on each pod', function (done
) {
640 each(servers
, function (server
, callback
) {
641 // Avoid "duplicate torrent" errors
642 const webtorrent
= new WebTorrent()
644 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
647 const videos
= res
.body
.data
648 const videoUpdated
= videos
.find(function (video
) {
649 return video
.name
=== 'my super video updated'
652 expect(!!videoUpdated
).to
.be
.true
653 expect(videoUpdated
.category
).to
.equal(10)
654 expect(videoUpdated
.categoryLabel
).to
.equal('Entertainment')
655 expect(videoUpdated
.description
).to
.equal('my super description updated')
656 expect(videoUpdated
.tags
).to
.deep
.equal([ 'tagup1', 'tagup2' ])
657 expect(miscsUtils
.dateIsValid(videoUpdated
.updatedAt
, 20000)).to
.be
.true
659 videosUtils
.testVideoImage(server
.url
, 'video_short3.webm', videoUpdated
.thumbnailPath
, function (err
, test
) {
661 expect(test
).to
.equal(true)
663 webtorrent
.add(videoUpdated
.magnetUri
, function (torrent
) {
664 expect(torrent
.files
).to
.exist
665 expect(torrent
.files
.length
).to
.equal(1)
666 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
675 it('Should remove the videos 3 and 3-2 by asking pod 3', function (done
) {
680 videosUtils
.removeVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[0].id
, next
)
683 videosUtils
.removeVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[1].id
, next
)
687 setTimeout(done
, 11000)
692 it('Should have videos 1 and 3 on each pod', function (done
) {
693 each(servers
, function (server
, callback
) {
694 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
697 const videos
= res
.body
.data
698 expect(videos
).to
.be
.an('array')
699 expect(videos
.length
).to
.equal(2)
700 expect(videos
[0].name
).not
.to
.equal(videos
[1].name
)
701 expect(videos
[0].name
).not
.to
.equal(toRemove
[0].name
)
702 expect(videos
[1].name
).not
.to
.equal(toRemove
[0].name
)
703 expect(videos
[0].name
).not
.to
.equal(toRemove
[1].name
)
704 expect(videos
[1].name
).not
.to
.equal(toRemove
[1].name
)
712 after(function (done
) {
713 servers
.forEach(function (server
) {
714 process
.kill(-server
.app
.pid
)
717 // Keep the logs if the test failed
719 serversUtils
.flushTests(done
)