]>
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 pathUtils
= require('path')
7 const series
= require('async/series')
9 const loginUtils
= require('../utils/login')
10 const miscsUtils
= require('../utils/miscs')
11 const podsUtils
= require('../utils/pods')
12 const serversUtils
= require('../utils/servers')
13 const videosUtils
= require('../utils/videos')
14 const webtorrent
= require(pathUtils
.join(__dirname
, '../../lib/webtorrent'))
15 webtorrent
.silent
= true
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
)
58 webtorrent
.create({ host: 'client', port: '1' }, 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'
84 const description
= 'my super description for pod 1'
85 const tags
= [ 'tag1p1', 'tag2p1' ]
86 const file
= 'video_short1.webm'
87 videosUtils
.uploadVideo(servers
[0].url
, servers
[0].accessToken
, name
, description
, tags
, file
, next
)
90 setTimeout(next
, 11000)
92 // All pods should have this video
96 each(servers
, function (server
, callback
) {
99 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
102 const videos
= res
.body
.data
103 expect(videos
).to
.be
.an('array')
104 expect(videos
.length
).to
.equal(1)
105 const video
= videos
[0]
106 expect(video
.name
).to
.equal('my super name for pod 1')
107 expect(video
.description
).to
.equal('my super description for pod 1')
108 expect(video
.podUrl
).to
.equal('localhost:9001')
109 expect(video
.magnetUri
).to
.exist
110 expect(video
.duration
).to
.equal(10)
111 expect(video
.tags
).to
.deep
.equal([ 'tag1p1', 'tag2p1' ])
112 expect(miscsUtils
.dateIsValid(video
.createdDate
)).to
.be
.true
113 expect(video
.author
).to
.equal('root')
115 if (server
.url
!== 'http://localhost:9001') {
116 expect(video
.isLocal
).to
.be
.false
118 expect(video
.isLocal
).to
.be
.true
121 // All pods should have the same magnet Uri
122 if (baseMagnet
=== null) {
123 baseMagnet
= video
.magnetUri
125 expect(video
.magnetUri
).to
.equal
.magnetUri
128 videosUtils
.testVideoImage(server
.url
, 'video_short1.webm', video
.thumbnailPath
, function (err
, test
) {
130 expect(test
).to
.equal(true)
140 it('Should upload the video on pod 2 and propagate on each pod', function (done
) {
145 const name
= 'my super name for pod 2'
146 const description
= 'my super description for pod 2'
147 const tags
= [ 'tag1p2', 'tag2p2', 'tag3p2' ]
148 const file
= 'video_short2.webm'
149 videosUtils
.uploadVideo(servers
[1].url
, servers
[1].accessToken
, name
, description
, tags
, file
, next
)
152 setTimeout(next
, 11000)
154 // All pods should have this video
158 each(servers
, function (server
, callback
) {
159 let baseMagnet
= null
161 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
164 const videos
= res
.body
.data
165 expect(videos
).to
.be
.an('array')
166 expect(videos
.length
).to
.equal(2)
167 const video
= videos
[1]
168 expect(video
.name
).to
.equal('my super name for pod 2')
169 expect(video
.description
).to
.equal('my super description for pod 2')
170 expect(video
.podUrl
).to
.equal('localhost:9002')
171 expect(video
.magnetUri
).to
.exist
172 expect(video
.duration
).to
.equal(5)
173 expect(video
.tags
).to
.deep
.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ])
174 expect(miscsUtils
.dateIsValid(video
.createdDate
)).to
.be
.true
175 expect(video
.author
).to
.equal('root')
177 if (server
.url
!== 'http://localhost:9002') {
178 expect(video
.isLocal
).to
.be
.false
180 expect(video
.isLocal
).to
.be
.true
183 // All pods should have the same magnet Uri
184 if (baseMagnet
=== null) {
185 baseMagnet
= video
.magnetUri
187 expect(video
.magnetUri
).to
.equal
.magnetUri
190 videosUtils
.testVideoImage(server
.url
, 'video_short2.webm', video
.thumbnailPath
, function (err
, test
) {
192 expect(test
).to
.equal(true)
202 it('Should upload two videos on pod 3 and propagate on each pod', function (done
) {
207 const name
= 'my super name for pod 3'
208 const description
= 'my super description for pod 3'
209 const tags
= [ 'tag1p3' ]
210 const file
= 'video_short3.webm'
211 videosUtils
.uploadVideo(servers
[2].url
, servers
[2].accessToken
, name
, description
, tags
, file
, next
)
214 const name
= 'my super name for pod 3-2'
215 const description
= 'my super description for pod 3-2'
216 const tags
= [ 'tag2p3', 'tag3p3', 'tag4p3' ]
217 const file
= 'video_short.webm'
218 videosUtils
.uploadVideo(servers
[2].url
, servers
[2].accessToken
, name
, description
, tags
, file
, next
)
221 setTimeout(next
, 22000)
226 let baseMagnet
= null
227 // All pods should have this video
228 each(servers
, function (server
, callback
) {
229 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
232 const videos
= res
.body
.data
233 expect(videos
).to
.be
.an('array')
234 expect(videos
.length
).to
.equal(4)
236 // We not sure about the order of the two last uploads
239 if (videos
[2].name
=== 'my super name for pod 3') {
247 expect(video1
.name
).to
.equal('my super name for pod 3')
248 expect(video1
.description
).to
.equal('my super description for pod 3')
249 expect(video1
.podUrl
).to
.equal('localhost:9003')
250 expect(video1
.magnetUri
).to
.exist
251 expect(video1
.duration
).to
.equal(5)
252 expect(video1
.tags
).to
.deep
.equal([ 'tag1p3' ])
253 expect(video1
.author
).to
.equal('root')
254 expect(miscsUtils
.dateIsValid(video1
.createdDate
)).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
.podUrl
).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
.createdDate
)).to
.be
.true
265 if (server
.url
!== 'http://localhost:9003') {
266 expect(video1
.isLocal
).to
.be
.false
267 expect(video2
.isLocal
).to
.be
.false
269 expect(video1
.isLocal
).to
.be
.true
270 expect(video2
.isLocal
).to
.be
.true
273 // All pods should have the same magnet Uri
274 if (baseMagnet
=== null) {
275 baseMagnet
= video2
.magnetUri
277 expect(video2
.magnetUri
).to
.equal
.magnetUri
280 videosUtils
.testVideoImage(server
.url
, 'video_short3.webm', video1
.thumbnailPath
, function (err
, test
) {
282 expect(test
).to
.equal(true)
284 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video2
.thumbnailPath
, function (err
, test
) {
286 expect(test
).to
.equal(true)
298 describe('Should seed the uploaded video', function () {
299 it('Should add the file 1 by asking pod 3', function (done
) {
300 // Yes, this could be long
303 videosUtils
.getVideosList(servers
[2].url
, function (err
, res
) {
306 const video
= res
.body
.data
[0]
307 toRemove
.push(res
.body
.data
[2].id
)
308 toRemove
.push(res
.body
.data
[3].id
)
310 webtorrent
.add(video
.magnetUri
, function (torrent
) {
311 expect(torrent
.files
).to
.exist
312 expect(torrent
.files
.length
).to
.equal(1)
313 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
320 it('Should add the file 2 by asking pod 1', function (done
) {
321 // Yes, this could be long
324 videosUtils
.getVideosList(servers
[0].url
, function (err
, res
) {
327 const video
= res
.body
.data
[1]
329 webtorrent
.add(video
.magnetUri
, function (torrent
) {
330 expect(torrent
.files
).to
.exist
331 expect(torrent
.files
.length
).to
.equal(1)
332 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
339 it('Should add the file 3 by asking pod 2', function (done
) {
340 // Yes, this could be long
343 videosUtils
.getVideosList(servers
[1].url
, function (err
, res
) {
346 const video
= res
.body
.data
[2]
348 webtorrent
.add(video
.magnetUri
, function (torrent
) {
349 expect(torrent
.files
).to
.exist
350 expect(torrent
.files
.length
).to
.equal(1)
351 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
353 webtorrent
.remove(video
.magnetUri
, done
)
358 it('Should add the file 3-2 by asking pod 1', function (done
) {
359 // Yes, this could be long
362 videosUtils
.getVideosList(servers
[0].url
, function (err
, res
) {
365 const video
= res
.body
.data
[3]
367 webtorrent
.add(video
.magnetUri
, function (torrent
) {
368 expect(torrent
.files
).to
.exist
369 expect(torrent
.files
.length
).to
.equal(1)
370 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
377 it('Should remove the file 3 and 3-2 by asking pod 3', function (done
) {
382 videosUtils
.removeVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[0], next
)
385 videosUtils
.removeVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[1], next
)
389 setTimeout(done
, 11000)
394 it('Should have videos 1 and 3 on each pod', function (done
) {
395 each(servers
, function (server
, callback
) {
396 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
399 const videos
= res
.body
.data
400 expect(videos
).to
.be
.an('array')
401 expect(videos
.length
).to
.equal(2)
402 expect(videos
[0].id
).not
.to
.equal(videos
[1].id
)
403 expect(videos
[0].id
).not
.to
.equal(toRemove
[0])
404 expect(videos
[1].id
).not
.to
.equal(toRemove
[0])
405 expect(videos
[0].id
).not
.to
.equal(toRemove
[1])
406 expect(videos
[1].id
).not
.to
.equal(toRemove
[1])
414 after(function (done
) {
415 servers
.forEach(function (server
) {
416 process
.kill(-server
.app
.pid
)
418 process
.kill(-webtorrent
.app
.pid
)
420 // Keep the logs if the test failed
422 serversUtils
.flushTests(done
)