]>
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
= require('webtorrent')
8 const webtorrent
= new WebTorrent()
10 const loginUtils
= require('../utils/login')
11 const miscsUtils
= require('../utils/miscs')
12 const podsUtils
= require('../utils/pods')
13 const serversUtils
= require('../utils/servers')
14 const videosUtils
= require('../utils/videos')
16 describe('Test multiple pods', function () {
20 before(function (done
) {
26 serversUtils
.flushAndRunMultipleServers(3, function (serversRun
) {
31 // Get the access tokens
33 each(servers
, function (server
, callbackEach
) {
34 loginUtils
.loginAndGetAccessToken(server
, function (err
, accessToken
) {
35 if (err
) return callbackEach(err
)
37 server
.accessToken
= accessToken
42 // The second pod make friend with the third
44 const server
= servers
[1]
45 podsUtils
.makeFriends(server
.url
, server
.accessToken
, next
)
47 // Wait for the request between pods
49 setTimeout(next
, 10000)
51 // Pod 1 make friends too
53 const server
= servers
[0]
54 podsUtils
.makeFriends(server
.url
, server
.accessToken
, next
)
59 it('Should not have videos for all pods', function (done
) {
60 each(servers
, function (server
, callback
) {
61 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
64 const videos
= res
.body
.data
65 expect(videos
).to
.be
.an('array')
66 expect(videos
.length
).to
.equal(0)
73 describe('Should upload the video and propagate on each pod', function () {
74 it('Should upload the video on pod 1 and propagate on each pod', function (done
) {
79 const name
= 'my super name for pod 1'
80 const description
= 'my super description for pod 1'
81 const tags
= [ 'tag1p1', 'tag2p1' ]
82 const file
= 'video_short1.webm'
83 videosUtils
.uploadVideo(servers
[0].url
, servers
[0].accessToken
, name
, description
, tags
, file
, next
)
86 setTimeout(next
, 11000)
88 // All pods should have this video
92 each(servers
, function (server
, callback
) {
95 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
98 const videos
= res
.body
.data
99 expect(videos
).to
.be
.an('array')
100 expect(videos
.length
).to
.equal(1)
101 const video
= videos
[0]
102 expect(video
.name
).to
.equal('my super name for pod 1')
103 expect(video
.description
).to
.equal('my super description for pod 1')
104 expect(video
.podHost
).to
.equal('localhost:9001')
105 expect(video
.magnetUri
).to
.exist
106 expect(video
.duration
).to
.equal(10)
107 expect(video
.tags
).to
.deep
.equal([ 'tag1p1', 'tag2p1' ])
108 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
109 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
110 expect(video
.author
).to
.equal('root')
112 if (server
.url
!== 'http://localhost:9001') {
113 expect(video
.isLocal
).to
.be
.false
115 expect(video
.isLocal
).to
.be
.true
118 // All pods should have the same magnet Uri
119 if (baseMagnet
=== null) {
120 baseMagnet
= video
.magnetUri
122 expect(video
.magnetUri
).to
.equal
.magnetUri
125 videosUtils
.testVideoImage(server
.url
, 'video_short1.webm', video
.thumbnailPath
, function (err
, test
) {
127 expect(test
).to
.equal(true)
137 it('Should upload the video on pod 2 and propagate on each pod', function (done
) {
142 const name
= 'my super name for pod 2'
143 const description
= 'my super description for pod 2'
144 const tags
= [ 'tag1p2', 'tag2p2', 'tag3p2' ]
145 const file
= 'video_short2.webm'
146 videosUtils
.uploadVideo(servers
[1].url
, servers
[1].accessToken
, name
, description
, tags
, file
, next
)
149 setTimeout(next
, 11000)
151 // All pods should have this video
155 each(servers
, function (server
, callback
) {
156 let baseMagnet
= null
158 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
161 const videos
= res
.body
.data
162 expect(videos
).to
.be
.an('array')
163 expect(videos
.length
).to
.equal(2)
164 const video
= videos
[1]
165 expect(video
.name
).to
.equal('my super name for pod 2')
166 expect(video
.description
).to
.equal('my super description for pod 2')
167 expect(video
.podHost
).to
.equal('localhost:9002')
168 expect(video
.magnetUri
).to
.exist
169 expect(video
.duration
).to
.equal(5)
170 expect(video
.tags
).to
.deep
.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ])
171 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
172 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
173 expect(video
.author
).to
.equal('root')
175 if (server
.url
!== 'http://localhost:9002') {
176 expect(video
.isLocal
).to
.be
.false
178 expect(video
.isLocal
).to
.be
.true
181 // All pods should have the same magnet Uri
182 if (baseMagnet
=== null) {
183 baseMagnet
= video
.magnetUri
185 expect(video
.magnetUri
).to
.equal
.magnetUri
188 videosUtils
.testVideoImage(server
.url
, 'video_short2.webm', video
.thumbnailPath
, function (err
, test
) {
190 expect(test
).to
.equal(true)
200 it('Should upload two videos on pod 3 and propagate on each pod', function (done
) {
205 const name
= 'my super name for pod 3'
206 const description
= 'my super description for pod 3'
207 const tags
= [ 'tag1p3' ]
208 const file
= 'video_short3.webm'
209 videosUtils
.uploadVideo(servers
[2].url
, servers
[2].accessToken
, name
, description
, tags
, file
, next
)
212 const name
= 'my super name for pod 3-2'
213 const description
= 'my super description for pod 3-2'
214 const tags
= [ 'tag2p3', 'tag3p3', 'tag4p3' ]
215 const file
= 'video_short.webm'
216 videosUtils
.uploadVideo(servers
[2].url
, servers
[2].accessToken
, name
, description
, tags
, file
, next
)
219 setTimeout(next
, 22000)
224 let baseMagnet
= null
225 // All pods should have this video
226 each(servers
, function (server
, callback
) {
227 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
230 const videos
= res
.body
.data
231 expect(videos
).to
.be
.an('array')
232 expect(videos
.length
).to
.equal(4)
234 // We not sure about the order of the two last uploads
237 if (videos
[2].name
=== 'my super name for pod 3') {
245 expect(video1
.name
).to
.equal('my super name for pod 3')
246 expect(video1
.description
).to
.equal('my super description for pod 3')
247 expect(video1
.podHost
).to
.equal('localhost:9003')
248 expect(video1
.magnetUri
).to
.exist
249 expect(video1
.duration
).to
.equal(5)
250 expect(video1
.tags
).to
.deep
.equal([ 'tag1p3' ])
251 expect(video1
.author
).to
.equal('root')
252 expect(miscsUtils
.dateIsValid(video1
.createdAt
)).to
.be
.true
253 expect(miscsUtils
.dateIsValid(video1
.updatedAt
)).to
.be
.true
255 expect(video2
.name
).to
.equal('my super name for pod 3-2')
256 expect(video2
.description
).to
.equal('my super description for pod 3-2')
257 expect(video2
.podHost
).to
.equal('localhost:9003')
258 expect(video2
.magnetUri
).to
.exist
259 expect(video2
.duration
).to
.equal(5)
260 expect(video2
.tags
).to
.deep
.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ])
261 expect(video2
.author
).to
.equal('root')
262 expect(miscsUtils
.dateIsValid(video2
.createdAt
)).to
.be
.true
263 expect(miscsUtils
.dateIsValid(video2
.updatedAt
)).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])
308 toRemove
.push(res
.body
.data
[3])
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('')
315 webtorrent
.remove(video
.magnetUri
, done
)
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('')
334 webtorrent
.remove(video
.magnetUri
, done
)
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('')
372 webtorrent
.remove(video
.magnetUri
, done
)
378 describe('Should manipulate these videos', function () {
379 it('Should update the video 3 by asking pod 3', function (done
) {
382 const name
= 'my super video updated'
383 const description
= 'my super description updated'
384 const tags
= [ 'tagup1', 'tagup2' ]
386 videosUtils
.updateVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[0].id
, name
, description
, tags
, function (err
) {
389 setTimeout(done
, 11000)
393 it('Should have the video 3 updated on each pod', function (done
) {
396 each(servers
, function (server
, callback
) {
397 // Avoid "duplicate torrent" errors
398 const webtorrent
= new WebTorrent()
400 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
403 const videos
= res
.body
.data
404 const videoUpdated
= videos
.find(function (video
) {
405 return video
.name
=== 'my super video updated'
408 expect(!!videoUpdated
).to
.be
.true
409 expect(videoUpdated
.description
).to
.equal('my super description updated')
410 expect(videoUpdated
.tags
).to
.deep
.equal([ 'tagup1', 'tagup2' ])
411 expect(miscsUtils
.dateIsValid(videoUpdated
.updatedAt
, 20000)).to
.be
.true
413 videosUtils
.testVideoImage(server
.url
, 'video_short3.webm', videoUpdated
.thumbnailPath
, function (err
, test
) {
415 expect(test
).to
.equal(true)
417 webtorrent
.add(videoUpdated
.magnetUri
, function (torrent
) {
418 expect(torrent
.files
).to
.exist
419 expect(torrent
.files
.length
).to
.equal(1)
420 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
422 webtorrent
.remove(videoUpdated
.magnetUri
, callback
)
429 it('Should remove the videos 3 and 3-2 by asking pod 3', function (done
) {
434 videosUtils
.removeVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[0].id
, next
)
437 videosUtils
.removeVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[1].id
, next
)
441 setTimeout(done
, 11000)
446 it('Should have videos 1 and 3 on each pod', function (done
) {
447 each(servers
, function (server
, callback
) {
448 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
451 const videos
= res
.body
.data
452 expect(videos
).to
.be
.an('array')
453 expect(videos
.length
).to
.equal(2)
454 expect(videos
[0].name
).not
.to
.equal(videos
[1].name
)
455 expect(videos
[0].name
).not
.to
.equal(toRemove
[0].name
)
456 expect(videos
[1].name
).not
.to
.equal(toRemove
[0].name
)
457 expect(videos
[0].name
).not
.to
.equal(toRemove
[1].name
)
458 expect(videos
[1].name
).not
.to
.equal(toRemove
[1].name
)
466 after(function (done
) {
467 servers
.forEach(function (server
) {
468 process
.kill(-server
.app
.pid
)
471 // Keep the logs if the test failed
473 serversUtils
.flushTests(done
)