]>
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 series
= require('async/series')
7 const webtorrent
= new (require('webtorrent'))()
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')
15 describe('Test multiple pods', function () {
19 before(function (done
) {
25 serversUtils
.flushAndRunMultipleServers(3, function (serversRun
) {
30 // Get the access tokens
32 each(servers
, function (server
, callbackEach
) {
33 loginUtils
.loginAndGetAccessToken(server
, function (err
, accessToken
) {
34 if (err
) return callbackEach(err
)
36 server
.accessToken
= accessToken
41 // The second pod make friend with the third
43 const server
= servers
[1]
44 podsUtils
.makeFriends(server
.url
, server
.accessToken
, next
)
46 // Wait for the request between pods
48 setTimeout(next
, 10000)
50 // Pod 1 make friends too
52 const server
= servers
[0]
53 podsUtils
.makeFriends(server
.url
, server
.accessToken
, next
)
58 it('Should not have videos for all pods', function (done
) {
59 each(servers
, function (server
, callback
) {
60 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
63 const videos
= res
.body
.data
64 expect(videos
).to
.be
.an('array')
65 expect(videos
.length
).to
.equal(0)
72 describe('Should upload the video and propagate on each pod', function () {
73 it('Should upload the video on pod 1 and propagate on each pod', function (done
) {
78 const name
= 'my super name for pod 1'
79 const description
= 'my super description for pod 1'
80 const tags
= [ 'tag1p1', 'tag2p1' ]
81 const file
= 'video_short1.webm'
82 videosUtils
.uploadVideo(servers
[0].url
, servers
[0].accessToken
, name
, description
, tags
, file
, next
)
85 setTimeout(next
, 11000)
87 // All pods should have this video
91 each(servers
, function (server
, callback
) {
94 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
97 const videos
= res
.body
.data
98 expect(videos
).to
.be
.an('array')
99 expect(videos
.length
).to
.equal(1)
100 const video
= videos
[0]
101 expect(video
.name
).to
.equal('my super name for pod 1')
102 expect(video
.description
).to
.equal('my super description for pod 1')
103 expect(video
.podHost
).to
.equal('localhost:9001')
104 expect(video
.magnetUri
).to
.exist
105 expect(video
.duration
).to
.equal(10)
106 expect(video
.tags
).to
.deep
.equal([ 'tag1p1', 'tag2p1' ])
107 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
108 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
109 expect(video
.author
).to
.equal('root')
111 if (server
.url
!== 'http://localhost:9001') {
112 expect(video
.isLocal
).to
.be
.false
114 expect(video
.isLocal
).to
.be
.true
117 // All pods should have the same magnet Uri
118 if (baseMagnet
=== null) {
119 baseMagnet
= video
.magnetUri
121 expect(video
.magnetUri
).to
.equal
.magnetUri
124 videosUtils
.testVideoImage(server
.url
, 'video_short1.webm', video
.thumbnailPath
, function (err
, test
) {
126 expect(test
).to
.equal(true)
136 it('Should upload the video on pod 2 and propagate on each pod', function (done
) {
141 const name
= 'my super name for pod 2'
142 const description
= 'my super description for pod 2'
143 const tags
= [ 'tag1p2', 'tag2p2', 'tag3p2' ]
144 const file
= 'video_short2.webm'
145 videosUtils
.uploadVideo(servers
[1].url
, servers
[1].accessToken
, name
, description
, tags
, file
, next
)
148 setTimeout(next
, 11000)
150 // All pods should have this video
154 each(servers
, function (server
, callback
) {
155 let baseMagnet
= null
157 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
160 const videos
= res
.body
.data
161 expect(videos
).to
.be
.an('array')
162 expect(videos
.length
).to
.equal(2)
163 const video
= videos
[1]
164 expect(video
.name
).to
.equal('my super name for pod 2')
165 expect(video
.description
).to
.equal('my super description for pod 2')
166 expect(video
.podHost
).to
.equal('localhost:9002')
167 expect(video
.magnetUri
).to
.exist
168 expect(video
.duration
).to
.equal(5)
169 expect(video
.tags
).to
.deep
.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ])
170 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
171 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
172 expect(video
.author
).to
.equal('root')
174 if (server
.url
!== 'http://localhost:9002') {
175 expect(video
.isLocal
).to
.be
.false
177 expect(video
.isLocal
).to
.be
.true
180 // All pods should have the same magnet Uri
181 if (baseMagnet
=== null) {
182 baseMagnet
= video
.magnetUri
184 expect(video
.magnetUri
).to
.equal
.magnetUri
187 videosUtils
.testVideoImage(server
.url
, 'video_short2.webm', video
.thumbnailPath
, function (err
, test
) {
189 expect(test
).to
.equal(true)
199 it('Should upload two videos on pod 3 and propagate on each pod', function (done
) {
204 const name
= 'my super name for pod 3'
205 const description
= 'my super description for pod 3'
206 const tags
= [ 'tag1p3' ]
207 const file
= 'video_short3.webm'
208 videosUtils
.uploadVideo(servers
[2].url
, servers
[2].accessToken
, name
, description
, tags
, file
, next
)
211 const name
= 'my super name for pod 3-2'
212 const description
= 'my super description for pod 3-2'
213 const tags
= [ 'tag2p3', 'tag3p3', 'tag4p3' ]
214 const file
= 'video_short.webm'
215 videosUtils
.uploadVideo(servers
[2].url
, servers
[2].accessToken
, name
, description
, tags
, file
, next
)
218 setTimeout(next
, 22000)
223 let baseMagnet
= null
224 // All pods should have this video
225 each(servers
, function (server
, callback
) {
226 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
229 const videos
= res
.body
.data
230 expect(videos
).to
.be
.an('array')
231 expect(videos
.length
).to
.equal(4)
233 // We not sure about the order of the two last uploads
236 if (videos
[2].name
=== 'my super name for pod 3') {
244 expect(video1
.name
).to
.equal('my super name for pod 3')
245 expect(video1
.description
).to
.equal('my super description for pod 3')
246 expect(video1
.podHost
).to
.equal('localhost:9003')
247 expect(video1
.magnetUri
).to
.exist
248 expect(video1
.duration
).to
.equal(5)
249 expect(video1
.tags
).to
.deep
.equal([ 'tag1p3' ])
250 expect(video1
.author
).to
.equal('root')
251 expect(miscsUtils
.dateIsValid(video1
.createdAt
)).to
.be
.true
252 expect(miscsUtils
.dateIsValid(video1
.updatedAt
)).to
.be
.true
254 expect(video2
.name
).to
.equal('my super name for pod 3-2')
255 expect(video2
.description
).to
.equal('my super description for pod 3-2')
256 expect(video2
.podHost
).to
.equal('localhost:9003')
257 expect(video2
.magnetUri
).to
.exist
258 expect(video2
.duration
).to
.equal(5)
259 expect(video2
.tags
).to
.deep
.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ])
260 expect(video2
.author
).to
.equal('root')
261 expect(miscsUtils
.dateIsValid(video2
.createdAt
)).to
.be
.true
262 expect(miscsUtils
.dateIsValid(video2
.updatedAt
)).to
.be
.true
264 if (server
.url
!== 'http://localhost:9003') {
265 expect(video1
.isLocal
).to
.be
.false
266 expect(video2
.isLocal
).to
.be
.false
268 expect(video1
.isLocal
).to
.be
.true
269 expect(video2
.isLocal
).to
.be
.true
272 // All pods should have the same magnet Uri
273 if (baseMagnet
=== null) {
274 baseMagnet
= video2
.magnetUri
276 expect(video2
.magnetUri
).to
.equal
.magnetUri
279 videosUtils
.testVideoImage(server
.url
, 'video_short3.webm', video1
.thumbnailPath
, function (err
, test
) {
281 expect(test
).to
.equal(true)
283 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video2
.thumbnailPath
, function (err
, test
) {
285 expect(test
).to
.equal(true)
297 describe('Should seed the uploaded video', function () {
298 it('Should add the file 1 by asking pod 3', function (done
) {
299 // Yes, this could be long
302 videosUtils
.getVideosList(servers
[2].url
, function (err
, res
) {
305 const video
= res
.body
.data
[0]
306 toRemove
.push(res
.body
.data
[2])
307 toRemove
.push(res
.body
.data
[3])
309 webtorrent
.add(video
.magnetUri
, function (torrent
) {
310 expect(torrent
.files
).to
.exist
311 expect(torrent
.files
.length
).to
.equal(1)
312 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
319 it('Should add the file 2 by asking pod 1', function (done
) {
320 // Yes, this could be long
323 videosUtils
.getVideosList(servers
[0].url
, function (err
, res
) {
326 const video
= res
.body
.data
[1]
328 webtorrent
.add(video
.magnetUri
, function (torrent
) {
329 expect(torrent
.files
).to
.exist
330 expect(torrent
.files
.length
).to
.equal(1)
331 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
338 it('Should add the file 3 by asking pod 2', function (done
) {
339 // Yes, this could be long
342 videosUtils
.getVideosList(servers
[1].url
, function (err
, res
) {
345 const video
= res
.body
.data
[2]
347 webtorrent
.add(video
.magnetUri
, function (torrent
) {
348 expect(torrent
.files
).to
.exist
349 expect(torrent
.files
.length
).to
.equal(1)
350 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
357 it('Should add the file 3-2 by asking pod 1', function (done
) {
358 // Yes, this could be long
361 videosUtils
.getVideosList(servers
[0].url
, function (err
, res
) {
364 const video
= res
.body
.data
[3]
366 webtorrent
.add(video
.magnetUri
, function (torrent
) {
367 expect(torrent
.files
).to
.exist
368 expect(torrent
.files
.length
).to
.equal(1)
369 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
377 describe('Should manipulate these videos', function () {
378 it('Should update the video 3 by asking pod 3', function (done
) {
381 const name
= 'my super video updated'
382 const description
= 'my super description updated'
383 const tags
= [ 'tagup1', 'tagup2' ]
385 videosUtils
.updateVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[0].id
, name
, description
, tags
, function (err
) {
388 setTimeout(done
, 11000)
392 it('Should have the video 3 updated on each pod', function (done
) {
393 each(servers
, function (server
, callback
) {
394 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
397 const videos
= res
.body
.data
398 const videoUpdated
= videos
.find(function (video
) {
399 return video
.name
=== 'my super video updated'
402 expect(!!videoUpdated
).to
.be
.true
403 expect(videoUpdated
.description
).to
.equal('my super description updated')
404 expect(videoUpdated
.tags
).to
.deep
.equal([ 'tagup1', 'tagup2' ])
405 expect(miscsUtils
.dateIsValid(videoUpdated
.updatedAt
, 20000)).to
.be
.true
412 it('Should remove the videos 3 and 3-2 by asking pod 3', function (done
) {
417 videosUtils
.removeVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[0].id
, next
)
420 videosUtils
.removeVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[1].id
, next
)
424 setTimeout(done
, 11000)
429 it('Should have videos 1 and 3 on each pod', function (done
) {
430 each(servers
, function (server
, callback
) {
431 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
434 const videos
= res
.body
.data
435 expect(videos
).to
.be
.an('array')
436 expect(videos
.length
).to
.equal(2)
437 expect(videos
[0].name
).not
.to
.equal(videos
[1].name
)
438 expect(videos
[0].name
).not
.to
.equal(toRemove
[0].name
)
439 expect(videos
[1].name
).not
.to
.equal(toRemove
[0].name
)
440 expect(videos
[0].name
).not
.to
.equal(toRemove
[1].name
)
441 expect(videos
[1].name
).not
.to
.equal(toRemove
[1].name
)
449 after(function (done
) {
450 servers
.forEach(function (server
) {
451 process
.kill(-server
.app
.pid
)
454 // Keep the logs if the test failed
456 serversUtils
.flushTests(done
)