]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/multiple-pods.js
3 const chai
= require('chai')
4 const each
= require('async/each')
5 const expect
= chai
.expect
6 const parallel
= require('async/parallel')
7 const series
= require('async/series')
8 const WebTorrent
= require('webtorrent')
9 const webtorrent
= new WebTorrent()
11 const loginUtils
= require('../utils/login')
12 const miscsUtils
= require('../utils/miscs')
13 const podsUtils
= require('../utils/pods')
14 const serversUtils
= require('../utils/servers')
15 const videosUtils
= require('../utils/videos')
17 describe('Test multiple pods', function () {
21 before(function (done
) {
27 serversUtils
.flushAndRunMultipleServers(3, function (serversRun
) {
32 // Get the access tokens
34 each(servers
, function (server
, callbackEach
) {
35 loginUtils
.loginAndGetAccessToken(server
, function (err
, accessToken
) {
36 if (err
) return callbackEach(err
)
38 server
.accessToken
= accessToken
43 // The second pod make friend with the third
45 const server
= servers
[1]
46 podsUtils
.makeFriends(server
.url
, server
.accessToken
, next
)
48 // Wait for the request between pods
50 setTimeout(next
, 10000)
52 // Pod 1 make friends too
54 const server
= servers
[0]
55 podsUtils
.makeFriends(server
.url
, server
.accessToken
, next
)
60 it('Should not have videos for all pods', function (done
) {
61 each(servers
, function (server
, callback
) {
62 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
65 const videos
= res
.body
.data
66 expect(videos
).to
.be
.an('array')
67 expect(videos
.length
).to
.equal(0)
74 describe('Should upload the video and propagate on each pod', function () {
75 it('Should upload the video on pod 1 and propagate on each pod', function (done
) {
80 const name
= 'my super name for pod 1'
81 const description
= 'my super description for pod 1'
82 const tags
= [ 'tag1p1', 'tag2p1' ]
83 const file
= 'video_short1.webm'
84 videosUtils
.uploadVideo(servers
[0].url
, servers
[0].accessToken
, name
, description
, tags
, file
, next
)
87 setTimeout(next
, 11000)
89 // All pods should have this video
93 each(servers
, function (server
, callback
) {
96 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
99 const videos
= res
.body
.data
100 expect(videos
).to
.be
.an('array')
101 expect(videos
.length
).to
.equal(1)
102 const video
= videos
[0]
103 expect(video
.name
).to
.equal('my super name for pod 1')
104 expect(video
.description
).to
.equal('my super description for pod 1')
105 expect(video
.podHost
).to
.equal('localhost:9001')
106 expect(video
.magnetUri
).to
.exist
107 expect(video
.duration
).to
.equal(10)
108 expect(video
.tags
).to
.deep
.equal([ 'tag1p1', 'tag2p1' ])
109 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
110 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
111 expect(video
.author
).to
.equal('root')
113 if (server
.url
!== 'http://localhost:9001') {
114 expect(video
.isLocal
).to
.be
.false
116 expect(video
.isLocal
).to
.be
.true
119 // All pods should have the same magnet Uri
120 if (baseMagnet
=== null) {
121 baseMagnet
= video
.magnetUri
123 expect(video
.magnetUri
).to
.equal
.magnetUri
126 videosUtils
.testVideoImage(server
.url
, 'video_short1.webm', video
.thumbnailPath
, function (err
, test
) {
128 expect(test
).to
.equal(true)
138 it('Should upload the video on pod 2 and propagate on each pod', function (done
) {
143 const name
= 'my super name for pod 2'
144 const description
= 'my super description for pod 2'
145 const tags
= [ 'tag1p2', 'tag2p2', 'tag3p2' ]
146 const file
= 'video_short2.webm'
147 videosUtils
.uploadVideo(servers
[1].url
, servers
[1].accessToken
, name
, description
, tags
, file
, next
)
150 setTimeout(next
, 11000)
152 // All pods should have this video
156 each(servers
, function (server
, callback
) {
157 let baseMagnet
= null
159 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
162 const videos
= res
.body
.data
163 expect(videos
).to
.be
.an('array')
164 expect(videos
.length
).to
.equal(2)
165 const video
= videos
[1]
166 expect(video
.name
).to
.equal('my super name for pod 2')
167 expect(video
.description
).to
.equal('my super description for pod 2')
168 expect(video
.podHost
).to
.equal('localhost:9002')
169 expect(video
.magnetUri
).to
.exist
170 expect(video
.duration
).to
.equal(5)
171 expect(video
.tags
).to
.deep
.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ])
172 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
173 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
174 expect(video
.author
).to
.equal('root')
176 if (server
.url
!== 'http://localhost:9002') {
177 expect(video
.isLocal
).to
.be
.false
179 expect(video
.isLocal
).to
.be
.true
182 // All pods should have the same magnet Uri
183 if (baseMagnet
=== null) {
184 baseMagnet
= video
.magnetUri
186 expect(video
.magnetUri
).to
.equal
.magnetUri
189 videosUtils
.testVideoImage(server
.url
, 'video_short2.webm', video
.thumbnailPath
, function (err
, test
) {
191 expect(test
).to
.equal(true)
201 it('Should upload two videos on pod 3 and propagate on each pod', function (done
) {
206 const name
= 'my super name for pod 3'
207 const description
= 'my super description for pod 3'
208 const tags
= [ 'tag1p3' ]
209 const file
= 'video_short3.webm'
210 videosUtils
.uploadVideo(servers
[2].url
, servers
[2].accessToken
, name
, description
, tags
, file
, next
)
213 const name
= 'my super name for pod 3-2'
214 const description
= 'my super description for pod 3-2'
215 const tags
= [ 'tag2p3', 'tag3p3', 'tag4p3' ]
216 const file
= 'video_short.webm'
217 videosUtils
.uploadVideo(servers
[2].url
, servers
[2].accessToken
, name
, description
, tags
, file
, next
)
220 setTimeout(next
, 22000)
225 let baseMagnet
= null
226 // All pods should have this video
227 each(servers
, function (server
, callback
) {
228 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
231 const videos
= res
.body
.data
232 expect(videos
).to
.be
.an('array')
233 expect(videos
.length
).to
.equal(4)
235 // We not sure about the order of the two last uploads
238 if (videos
[2].name
=== 'my super name for pod 3') {
246 expect(video1
.name
).to
.equal('my super name for pod 3')
247 expect(video1
.description
).to
.equal('my super description for pod 3')
248 expect(video1
.podHost
).to
.equal('localhost:9003')
249 expect(video1
.magnetUri
).to
.exist
250 expect(video1
.duration
).to
.equal(5)
251 expect(video1
.tags
).to
.deep
.equal([ 'tag1p3' ])
252 expect(video1
.author
).to
.equal('root')
253 expect(miscsUtils
.dateIsValid(video1
.createdAt
)).to
.be
.true
254 expect(miscsUtils
.dateIsValid(video1
.updatedAt
)).to
.be
.true
256 expect(video2
.name
).to
.equal('my super name for pod 3-2')
257 expect(video2
.description
).to
.equal('my super description for pod 3-2')
258 expect(video2
.podHost
).to
.equal('localhost:9003')
259 expect(video2
.magnetUri
).to
.exist
260 expect(video2
.duration
).to
.equal(5)
261 expect(video2
.tags
).to
.deep
.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ])
262 expect(video2
.author
).to
.equal('root')
263 expect(miscsUtils
.dateIsValid(video2
.createdAt
)).to
.be
.true
264 expect(miscsUtils
.dateIsValid(video2
.updatedAt
)).to
.be
.true
266 if (server
.url
!== 'http://localhost:9003') {
267 expect(video1
.isLocal
).to
.be
.false
268 expect(video2
.isLocal
).to
.be
.false
270 expect(video1
.isLocal
).to
.be
.true
271 expect(video2
.isLocal
).to
.be
.true
274 // All pods should have the same magnet Uri
275 if (baseMagnet
=== null) {
276 baseMagnet
= video2
.magnetUri
278 expect(video2
.magnetUri
).to
.equal
.magnetUri
281 videosUtils
.testVideoImage(server
.url
, 'video_short3.webm', video1
.thumbnailPath
, function (err
, test
) {
283 expect(test
).to
.equal(true)
285 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video2
.thumbnailPath
, function (err
, test
) {
287 expect(test
).to
.equal(true)
299 describe('Should seed the uploaded video', function () {
300 it('Should add the file 1 by asking pod 3', function (done
) {
301 // Yes, this could be long
304 videosUtils
.getVideosList(servers
[2].url
, function (err
, res
) {
307 const video
= res
.body
.data
[0]
308 toRemove
.push(res
.body
.data
[2])
309 toRemove
.push(res
.body
.data
[3])
311 webtorrent
.add(video
.magnetUri
, function (torrent
) {
312 expect(torrent
.files
).to
.exist
313 expect(torrent
.files
.length
).to
.equal(1)
314 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
321 it('Should add the file 2 by asking pod 1', function (done
) {
322 // Yes, this could be long
325 videosUtils
.getVideosList(servers
[0].url
, function (err
, res
) {
328 const video
= res
.body
.data
[1]
330 webtorrent
.add(video
.magnetUri
, function (torrent
) {
331 expect(torrent
.files
).to
.exist
332 expect(torrent
.files
.length
).to
.equal(1)
333 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
340 it('Should add the file 3 by asking pod 2', function (done
) {
341 // Yes, this could be long
344 videosUtils
.getVideosList(servers
[1].url
, function (err
, res
) {
347 const video
= res
.body
.data
[2]
349 webtorrent
.add(video
.magnetUri
, function (torrent
) {
350 expect(torrent
.files
).to
.exist
351 expect(torrent
.files
.length
).to
.equal(1)
352 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
359 it('Should add the file 3-2 by asking pod 1', function (done
) {
360 // Yes, this could be long
363 videosUtils
.getVideosList(servers
[0].url
, function (err
, res
) {
366 const video
= res
.body
.data
[3]
368 webtorrent
.add(video
.magnetUri
, function (torrent
) {
369 expect(torrent
.files
).to
.exist
370 expect(torrent
.files
.length
).to
.equal(1)
371 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
379 describe('Should update video views', function () {
383 before(function (done
) {
384 videosUtils
.getVideosList(servers
[2].url
, function (err
, res
) {
387 const videos
= res
.body
.data
.filter(video
=> video
.isLocal
=== true)
388 videoId1
= videos
[0].id
389 videoId2
= videos
[1].id
395 it('Should views multiple videos on owned servers', function (done
) {
399 function (callback
) {
400 videosUtils
.getVideo(servers
[2].url
, videoId1
, callback
)
403 function (callback
) {
404 videosUtils
.getVideo(servers
[2].url
, videoId1
, callback
)
407 function (callback
) {
408 videosUtils
.getVideo(servers
[2].url
, videoId1
, callback
)
411 function (callback
) {
412 videosUtils
.getVideo(servers
[2].url
, videoId2
, callback
)
417 setTimeout(done
, 22000)
421 it('Should have views updated on each pod', function (done
) {
422 each(servers
, function (server
, callback
) {
423 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
426 const videos
= res
.body
.data
427 expect(videos
.find(video
=> video
.views
=== 3)).to
.be
.exist
428 expect(videos
.find(video
=> video
.views
=== 1)).to
.be
.exist
436 describe('Should manipulate these videos', function () {
437 it('Should update the video 3 by asking pod 3', function (done) {
440 const name = 'my super video updated'
441 const description = 'my super description updated'
442 const tags = [ 'tagup1', 'tagup2' ]
444 videosUtils.updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, name, description, tags, function (err) {
447 setTimeout(done, 11000)
451 it('Should have the video 3 updated on each pod', function (done) {
454 each(servers, function (server, callback) {
455 // Avoid "duplicate torrent" errors
456 const webtorrent = new WebTorrent()
458 videosUtils.getVideosList(server.url, function (err, res) {
461 const videos = res.body.data
462 const videoUpdated = videos.find(function (video) {
463 return video.name === 'my super video updated'
466 expect(!!videoUpdated).to.be.true
467 expect(videoUpdated.description).to.equal('my super description updated')
468 expect(videoUpdated.tags).to.deep.equal([ 'tagup1', 'tagup2' ])
469 expect(miscsUtils.dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true
471 videosUtils.testVideoImage(server.url, 'video_short3.webm', videoUpdated.thumbnailPath, function (err, test) {
473 expect(test).to.equal(true)
475 webtorrent.add(videoUpdated.magnetUri, function (torrent) {
476 expect(torrent.files).to.exist
477 expect(torrent.files.length).to.equal(1)
478 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
487 it('Should remove the videos 3 and 3-2 by asking pod 3', function (done) {
492 videosUtils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, next)
495 videosUtils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id, next)
499 setTimeout(done, 11000)
504 it('Should have videos 1 and 3 on each pod', function (done) {
505 each(servers, function (server, callback) {
506 videosUtils.getVideosList(server.url, function (err, res) {
509 const videos = res.body.data
510 expect(videos).to.be.an('array')
511 expect(videos.length).to.equal(2)
512 expect(videos[0].name).not.to.equal(videos[1].name)
513 expect(videos[0].name).not.to.equal(toRemove[0].name)
514 expect(videos[1].name).not.to.equal(toRemove[0].name)
515 expect(videos[0].name).not.to.equal(toRemove[1].name)
516 expect(videos[1].name).not.to.equal(toRemove[1].name)
524 after(function (done
) {
525 servers
.forEach(function (server
) {
526 process
.kill(-server
.app
.pid
)
529 // Keep the logs if the test failed
531 serversUtils
.flushTests(done
)