]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/multiple-pods.js
eccc9ecef6494de6e3907562b12b870496212300
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 name
= 'my super name for pod 1'
85 const description
= 'my super description for pod 1'
86 const tags
= [ 'tag1p1', 'tag2p1' ]
87 const file
= 'video_short1.webm'
88 videosUtils
.uploadVideo(servers
[0].url
, servers
[0].accessToken
, name
, category
, description
, tags
, file
, next
)
91 setTimeout(next
, 11000)
93 // All pods should have this video
97 each(servers
, function (server
, callback
) {
100 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
103 const videos
= res
.body
.data
104 expect(videos
).to
.be
.an('array')
105 expect(videos
.length
).to
.equal(1)
106 const video
= videos
[0]
107 expect(video
.name
).to
.equal('my super name for pod 1')
108 expect(video
.category
).to
.equal(5)
109 expect(video
.categoryLabel
).to
.equal('Sports')
110 expect(video
.description
).to
.equal('my super description for pod 1')
111 expect(video
.podHost
).to
.equal('localhost:9001')
112 expect(video
.magnetUri
).to
.exist
113 expect(video
.duration
).to
.equal(10)
114 expect(video
.tags
).to
.deep
.equal([ 'tag1p1', 'tag2p1' ])
115 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
116 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
117 expect(video
.author
).to
.equal('root')
119 if (server
.url
!== 'http://localhost:9001') {
120 expect(video
.isLocal
).to
.be
.false
122 expect(video
.isLocal
).to
.be
.true
125 // All pods should have the same magnet Uri
126 if (baseMagnet
=== null) {
127 baseMagnet
= video
.magnetUri
129 expect(video
.magnetUri
).to
.equal
.magnetUri
132 videosUtils
.testVideoImage(server
.url
, 'video_short1.webm', video
.thumbnailPath
, function (err
, test
) {
134 expect(test
).to
.equal(true)
144 it('Should upload the video on pod 2 and propagate on each pod', function (done
) {
149 const name
= 'my super name for pod 2'
151 const description
= 'my super description for pod 2'
152 const tags
= [ 'tag1p2', 'tag2p2', 'tag3p2' ]
153 const file
= 'video_short2.webm'
154 videosUtils
.uploadVideo(servers
[1].url
, servers
[1].accessToken
, name
, category
, description
, tags
, file
, next
)
157 setTimeout(next
, 11000)
159 // All pods should have this video
163 each(servers
, function (server
, callback
) {
164 let baseMagnet
= null
166 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
169 const videos
= res
.body
.data
170 expect(videos
).to
.be
.an('array')
171 expect(videos
.length
).to
.equal(2)
172 const video
= videos
[1]
173 expect(video
.name
).to
.equal('my super name for pod 2')
174 expect(video
.category
).to
.equal(4)
175 expect(video
.categoryLabel
).to
.equal('Art')
176 expect(video
.description
).to
.equal('my super description for pod 2')
177 expect(video
.podHost
).to
.equal('localhost:9002')
178 expect(video
.magnetUri
).to
.exist
179 expect(video
.duration
).to
.equal(5)
180 expect(video
.tags
).to
.deep
.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ])
181 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
182 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
183 expect(video
.author
).to
.equal('root')
185 if (server
.url
!== 'http://localhost:9002') {
186 expect(video
.isLocal
).to
.be
.false
188 expect(video
.isLocal
).to
.be
.true
191 // All pods should have the same magnet Uri
192 if (baseMagnet
=== null) {
193 baseMagnet
= video
.magnetUri
195 expect(video
.magnetUri
).to
.equal
.magnetUri
198 videosUtils
.testVideoImage(server
.url
, 'video_short2.webm', video
.thumbnailPath
, function (err
, test
) {
200 expect(test
).to
.equal(true)
210 it('Should upload two videos on pod 3 and propagate on each pod', function (done
) {
215 const name
= 'my super name for pod 3'
217 const description
= 'my super description for pod 3'
218 const tags
= [ 'tag1p3' ]
219 const file
= 'video_short3.webm'
220 videosUtils
.uploadVideo(servers
[2].url
, servers
[2].accessToken
, name
, category
, description
, tags
, file
, next
)
223 const name
= 'my super name for pod 3-2'
225 const description
= 'my super description for pod 3-2'
226 const tags
= [ 'tag2p3', 'tag3p3', 'tag4p3' ]
227 const file
= 'video_short.webm'
228 videosUtils
.uploadVideo(servers
[2].url
, servers
[2].accessToken
, name
, category
, description
, tags
, file
, next
)
231 setTimeout(next
, 22000)
236 let baseMagnet
= null
237 // All pods should have this video
238 each(servers
, function (server
, callback
) {
239 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
242 const videos
= res
.body
.data
243 expect(videos
).to
.be
.an('array')
244 expect(videos
.length
).to
.equal(4)
246 // We not sure about the order of the two last uploads
249 if (videos
[2].name
=== 'my super name for pod 3') {
257 expect(video1
.name
).to
.equal('my super name for pod 3')
258 expect(video1
.category
).to
.equal(6)
259 expect(video1
.categoryLabel
).to
.equal('Travels')
260 expect(video1
.description
).to
.equal('my super description for pod 3')
261 expect(video1
.podHost
).to
.equal('localhost:9003')
262 expect(video1
.magnetUri
).to
.exist
263 expect(video1
.duration
).to
.equal(5)
264 expect(video1
.tags
).to
.deep
.equal([ 'tag1p3' ])
265 expect(video1
.author
).to
.equal('root')
266 expect(miscsUtils
.dateIsValid(video1
.createdAt
)).to
.be
.true
267 expect(miscsUtils
.dateIsValid(video1
.updatedAt
)).to
.be
.true
269 expect(video2
.name
).to
.equal('my super name for pod 3-2')
270 expect(video2
.category
).to
.equal(7)
271 expect(video2
.categoryLabel
).to
.equal('Gaming')
272 expect(video2
.description
).to
.equal('my super description for pod 3-2')
273 expect(video2
.podHost
).to
.equal('localhost:9003')
274 expect(video2
.magnetUri
).to
.exist
275 expect(video2
.duration
).to
.equal(5)
276 expect(video2
.tags
).to
.deep
.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ])
277 expect(video2
.author
).to
.equal('root')
278 expect(miscsUtils
.dateIsValid(video2
.createdAt
)).to
.be
.true
279 expect(miscsUtils
.dateIsValid(video2
.updatedAt
)).to
.be
.true
281 if (server
.url
!== 'http://localhost:9003') {
282 expect(video1
.isLocal
).to
.be
.false
283 expect(video2
.isLocal
).to
.be
.false
285 expect(video1
.isLocal
).to
.be
.true
286 expect(video2
.isLocal
).to
.be
.true
289 // All pods should have the same magnet Uri
290 if (baseMagnet
=== null) {
291 baseMagnet
= video2
.magnetUri
293 expect(video2
.magnetUri
).to
.equal
.magnetUri
296 videosUtils
.testVideoImage(server
.url
, 'video_short3.webm', video1
.thumbnailPath
, function (err
, test
) {
298 expect(test
).to
.equal(true)
300 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video2
.thumbnailPath
, function (err
, test
) {
302 expect(test
).to
.equal(true)
314 describe('Should seed the uploaded video', function () {
315 it('Should add the file 1 by asking pod 3', function (done
) {
316 // Yes, this could be long
319 videosUtils
.getVideosList(servers
[2].url
, function (err
, res
) {
322 const video
= res
.body
.data
[0]
323 toRemove
.push(res
.body
.data
[2])
324 toRemove
.push(res
.body
.data
[3])
326 webtorrent
.add(video
.magnetUri
, function (torrent
) {
327 expect(torrent
.files
).to
.exist
328 expect(torrent
.files
.length
).to
.equal(1)
329 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
336 it('Should add the file 2 by asking pod 1', function (done
) {
337 // Yes, this could be long
340 videosUtils
.getVideosList(servers
[0].url
, function (err
, res
) {
343 const video
= res
.body
.data
[1]
345 webtorrent
.add(video
.magnetUri
, function (torrent
) {
346 expect(torrent
.files
).to
.exist
347 expect(torrent
.files
.length
).to
.equal(1)
348 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
355 it('Should add the file 3 by asking pod 2', function (done
) {
356 // Yes, this could be long
359 videosUtils
.getVideosList(servers
[1].url
, function (err
, res
) {
362 const video
= res
.body
.data
[2]
364 webtorrent
.add(video
.magnetUri
, function (torrent
) {
365 expect(torrent
.files
).to
.exist
366 expect(torrent
.files
.length
).to
.equal(1)
367 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
374 it('Should add the file 3-2 by asking pod 1', function (done
) {
375 // Yes, this could be long
378 videosUtils
.getVideosList(servers
[0].url
, function (err
, res
) {
381 const video
= res
.body
.data
[3]
383 webtorrent
.add(video
.magnetUri
, function (torrent
) {
384 expect(torrent
.files
).to
.exist
385 expect(torrent
.files
.length
).to
.equal(1)
386 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
394 describe('Should update video views, likes and dislikes', function () {
395 let localVideosPod3
= []
396 let remoteVideosPod1
= []
397 let remoteVideosPod2
= []
398 let remoteVideosPod3
= []
400 before(function (done
) {
402 function (callback
) {
403 videosUtils
.getVideosList(servers
[0].url
, function (err
, res
) {
406 remoteVideosPod1
= res
.body
.data
.filter(video
=> video
.isLocal
=== false).map(video
=> video
.id
)
412 function (callback
) {
413 videosUtils
.getVideosList(servers
[1].url
, function (err
, res
) {
416 remoteVideosPod2
= res
.body
.data
.filter(video
=> video
.isLocal
=== false).map(video
=> video
.id
)
422 function (callback
) {
423 videosUtils
.getVideosList(servers
[2].url
, function (err
, res
) {
426 localVideosPod3
= res
.body
.data
.filter(video
=> video
.isLocal
=== true).map(video
=> video
.id
)
427 remoteVideosPod3
= res
.body
.data
.filter(video
=> video
.isLocal
=== false).map(video
=> video
.id
)
435 it('Should view multiple videos on owned servers', function (done
) {
439 function (callback
) {
440 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[0], callback
)
443 function (callback
) {
444 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[0], callback
)
447 function (callback
) {
448 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[0], callback
)
451 function (callback
) {
452 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[1], callback
)
455 function (callback
) {
456 setTimeout(callback
, 22000)
461 eachSeries(servers
, function (server
, callback
) {
462 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
465 const videos
= res
.body
.data
466 expect(videos
.find(video
=> video
.views
=== 3)).to
.exist
467 expect(videos
.find(video
=> video
.views
=== 1)).to
.exist
475 it('Should view multiple videos on each servers', function (done
) {
479 function (callback
) {
480 videosUtils
.getVideo(servers
[0].url
, remoteVideosPod1
[0], callback
)
483 function (callback
) {
484 videosUtils
.getVideo(servers
[1].url
, remoteVideosPod2
[0], callback
)
487 function (callback
) {
488 videosUtils
.getVideo(servers
[1].url
, remoteVideosPod2
[0], callback
)
491 function (callback
) {
492 videosUtils
.getVideo(servers
[2].url
, remoteVideosPod3
[0], callback
)
495 function (callback
) {
496 videosUtils
.getVideo(servers
[2].url
, remoteVideosPod3
[1], callback
)
499 function (callback
) {
500 videosUtils
.getVideo(servers
[2].url
, remoteVideosPod3
[1], callback
)
503 function (callback
) {
504 videosUtils
.getVideo(servers
[2].url
, remoteVideosPod3
[1], callback
)
507 function (callback
) {
508 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[1], callback
)
511 function (callback
) {
512 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[1], callback
)
515 function (callback
) {
516 videosUtils
.getVideo(servers
[2].url
, localVideosPod3
[1], callback
)
519 function (callback
) {
520 setTimeout(callback
, 22000)
525 let baseVideos
= null
526 eachSeries(servers
, function (server
, callback
) {
527 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
530 const videos
= res
.body
.data
532 // Initialize base videos for future comparisons
533 if (baseVideos
=== null) {
538 baseVideos
.forEach(baseVideo
=> {
539 const sameVideo
= videos
.find(video
=> video
.name
=== baseVideo
.name
)
540 expect(baseVideo
.views
).to
.equal(sameVideo
.views
)
549 it('Should like and dislikes videos on different services', function (done
) {
553 function (callback
) {
554 videosUtils
.rateVideo(servers
[0].url
, servers
[0].accessToken
, remoteVideosPod1
[0], 'like', callback
)
557 function (callback
) {
558 videosUtils
.rateVideo(servers
[0].url
, servers
[0].accessToken
, remoteVideosPod1
[0], 'dislike', callback
)
561 function (callback
) {
562 videosUtils
.rateVideo(servers
[0].url
, servers
[0].accessToken
, remoteVideosPod1
[0], 'like', callback
)
565 function (callback
) {
566 videosUtils
.rateVideo(servers
[2].url
, servers
[2].accessToken
, localVideosPod3
[1], 'like', callback
)
569 function (callback
) {
570 videosUtils
.rateVideo(servers
[2].url
, servers
[2].accessToken
, localVideosPod3
[1], 'dislike', callback
)
573 function (callback
) {
574 videosUtils
.rateVideo(servers
[2].url
, servers
[2].accessToken
, remoteVideosPod3
[1], 'dislike', callback
)
577 function (callback
) {
578 videosUtils
.rateVideo(servers
[2].url
, servers
[2].accessToken
, remoteVideosPod3
[0], 'like', callback
)
581 function (callback
) {
582 setTimeout(callback
, 22000)
587 let baseVideos
= null
588 eachSeries(servers
, function (server
, callback
) {
589 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
592 const videos
= res
.body
.data
594 // Initialize base videos for future comparisons
595 if (baseVideos
=== null) {
600 baseVideos
.forEach(baseVideo
=> {
601 const sameVideo
= videos
.find(video
=> video
.name
=== baseVideo
.name
)
602 expect(baseVideo
.likes
).to
.equal(sameVideo
.likes
)
603 expect(baseVideo
.dislikes
).to
.equal(sameVideo
.dislikes
)
613 describe('Should manipulate these videos', function () {
614 it('Should update the video 3 by asking pod 3', function (done
) {
617 const name
= 'my super video updated'
619 const description
= 'my super description updated'
620 const tags
= [ 'tagup1', 'tagup2' ]
622 videosUtils
.updateVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[0].id
, name
, category
, description
, tags
, function (err
) {
625 setTimeout(done
, 11000)
629 it('Should have the video 3 updated on each pod', function (done
) {
632 each(servers
, function (server
, callback
) {
633 // Avoid "duplicate torrent" errors
634 const webtorrent
= new WebTorrent()
636 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
639 const videos
= res
.body
.data
640 const videoUpdated
= videos
.find(function (video
) {
641 return video
.name
=== 'my super video updated'
644 expect(!!videoUpdated
).to
.be
.true
645 expect(videoUpdated
.category
).to
.equal(10)
646 expect(videoUpdated
.categoryLabel
).to
.equal('Entertainment')
647 expect(videoUpdated
.description
).to
.equal('my super description updated')
648 expect(videoUpdated
.tags
).to
.deep
.equal([ 'tagup1', 'tagup2' ])
649 expect(miscsUtils
.dateIsValid(videoUpdated
.updatedAt
, 20000)).to
.be
.true
651 videosUtils
.testVideoImage(server
.url
, 'video_short3.webm', videoUpdated
.thumbnailPath
, function (err
, test
) {
653 expect(test
).to
.equal(true)
655 webtorrent
.add(videoUpdated
.magnetUri
, function (torrent
) {
656 expect(torrent
.files
).to
.exist
657 expect(torrent
.files
.length
).to
.equal(1)
658 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
667 it('Should remove the videos 3 and 3-2 by asking pod 3', function (done
) {
672 videosUtils
.removeVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[0].id
, next
)
675 videosUtils
.removeVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[1].id
, next
)
679 setTimeout(done
, 11000)
684 it('Should have videos 1 and 3 on each pod', function (done
) {
685 each(servers
, function (server
, callback
) {
686 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
689 const videos
= res
.body
.data
690 expect(videos
).to
.be
.an('array')
691 expect(videos
.length
).to
.equal(2)
692 expect(videos
[0].name
).not
.to
.equal(videos
[1].name
)
693 expect(videos
[0].name
).not
.to
.equal(toRemove
[0].name
)
694 expect(videos
[1].name
).not
.to
.equal(toRemove
[0].name
)
695 expect(videos
[0].name
).not
.to
.equal(toRemove
[1].name
)
696 expect(videos
[1].name
).not
.to
.equal(toRemove
[1].name
)
704 after(function (done
) {
705 servers
.forEach(function (server
) {
706 process
.kill(-server
.app
.pid
)
709 // Keep the logs if the test failed
711 serversUtils
.flushTests(done
)