]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/multiplePods.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 utils
= require('./utils')
10 const webtorrent
= require(pathUtils
.join(__dirname
, '../../lib/webtorrent'))
11 webtorrent
.silent
= true
13 describe('Test multiple pods', function () {
17 before(function (done
) {
23 utils
.flushAndRunMultipleServers(3, function (serversRun
) {
28 // Get the access tokens
30 each(servers
, function (server
, callbackEach
) {
31 utils
.loginAndGetAccessToken(server
, function (err
, accessToken
) {
32 if (err
) return callbackEach(err
)
34 server
.accessToken
= accessToken
39 // The second pod make friend with the third
41 const server
= servers
[1]
42 utils
.makeFriends(server
.url
, server
.accessToken
, next
)
44 // Wait for the request between pods
46 setTimeout(next
, 10000)
48 // Pod 1 make friends too
50 const server
= servers
[0]
51 utils
.makeFriends(server
.url
, server
.accessToken
, next
)
54 webtorrent
.create({ host: 'client', port: '1' }, next
)
59 it('Should not have videos for all pods', function (done
) {
60 each(servers
, function (server
, callback
) {
61 utils
.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 utils
.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 utils
.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
.podUrl
).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(utils
.dateIsValid(video
.createdDate
)).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 utils
.testImage(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 utils
.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 utils
.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
.podUrl
).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(utils
.dateIsValid(video
.createdDate
)).to
.be
.true
171 expect(video
.author
).to
.equal('root')
173 if (server
.url
!== 'http://localhost:9002') {
174 expect(video
.isLocal
).to
.be
.false
176 expect(video
.isLocal
).to
.be
.true
179 // All pods should have the same magnet Uri
180 if (baseMagnet
=== null) {
181 baseMagnet
= video
.magnetUri
183 expect(video
.magnetUri
).to
.equal
.magnetUri
186 utils
.testImage(server
.url
, 'video_short2.webm', video
.thumbnailPath
, function (err
, test
) {
188 expect(test
).to
.equal(true)
198 it('Should upload two videos on pod 3 and propagate on each pod', function (done
) {
203 const name
= 'my super name for pod 3'
204 const description
= 'my super description for pod 3'
205 const tags
= [ 'tag1p3' ]
206 const file
= 'video_short3.webm'
207 utils
.uploadVideo(servers
[2].url
, servers
[2].accessToken
, name
, description
, tags
, file
, next
)
210 const name
= 'my super name for pod 3-2'
211 const description
= 'my super description for pod 3-2'
212 const tags
= [ 'tag2p3', 'tag3p3', 'tag4p3' ]
213 const file
= 'video_short.webm'
214 utils
.uploadVideo(servers
[2].url
, servers
[2].accessToken
, name
, description
, tags
, file
, next
)
217 setTimeout(next
, 22000)
222 let baseMagnet
= null
223 // All pods should have this video
224 each(servers
, function (server
, callback
) {
225 utils
.getVideosList(server
.url
, function (err
, res
) {
228 const videos
= res
.body
.data
229 expect(videos
).to
.be
.an('array')
230 expect(videos
.length
).to
.equal(4)
232 // We not sure about the order of the two last uploads
235 if (videos
[2].name
=== 'my super name for pod 3') {
243 expect(video1
.name
).to
.equal('my super name for pod 3')
244 expect(video1
.description
).to
.equal('my super description for pod 3')
245 expect(video1
.podUrl
).to
.equal('localhost:9003')
246 expect(video1
.magnetUri
).to
.exist
247 expect(video1
.duration
).to
.equal(5)
248 expect(video1
.tags
).to
.deep
.equal([ 'tag1p3' ])
249 expect(video1
.author
).to
.equal('root')
250 expect(utils
.dateIsValid(video1
.createdDate
)).to
.be
.true
252 expect(video2
.name
).to
.equal('my super name for pod 3-2')
253 expect(video2
.description
).to
.equal('my super description for pod 3-2')
254 expect(video2
.podUrl
).to
.equal('localhost:9003')
255 expect(video2
.magnetUri
).to
.exist
256 expect(video2
.duration
).to
.equal(5)
257 expect(video2
.tags
).to
.deep
.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ])
258 expect(video2
.author
).to
.equal('root')
259 expect(utils
.dateIsValid(video2
.createdDate
)).to
.be
.true
261 if (server
.url
!== 'http://localhost:9003') {
262 expect(video1
.isLocal
).to
.be
.false
263 expect(video2
.isLocal
).to
.be
.false
265 expect(video1
.isLocal
).to
.be
.true
266 expect(video2
.isLocal
).to
.be
.true
269 // All pods should have the same magnet Uri
270 if (baseMagnet
=== null) {
271 baseMagnet
= video2
.magnetUri
273 expect(video2
.magnetUri
).to
.equal
.magnetUri
276 utils
.testImage(server
.url
, 'video_short3.webm', video1
.thumbnailPath
, function (err
, test
) {
278 expect(test
).to
.equal(true)
280 utils
.testImage(server
.url
, 'video_short.webm', video2
.thumbnailPath
, function (err
, test
) {
282 expect(test
).to
.equal(true)
294 describe('Should seed the uploaded video', function () {
295 it('Should add the file 1 by asking pod 3', function (done
) {
296 // Yes, this could be long
299 utils
.getVideosList(servers
[2].url
, function (err
, res
) {
302 const video
= res
.body
.data
[0]
303 toRemove
.push(res
.body
.data
[2].id
)
304 toRemove
.push(res
.body
.data
[3].id
)
306 webtorrent
.add(video
.magnetUri
, function (torrent
) {
307 expect(torrent
.files
).to
.exist
308 expect(torrent
.files
.length
).to
.equal(1)
309 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
316 it('Should add the file 2 by asking pod 1', function (done
) {
317 // Yes, this could be long
320 utils
.getVideosList(servers
[0].url
, function (err
, res
) {
323 const video
= res
.body
.data
[1]
325 webtorrent
.add(video
.magnetUri
, function (torrent
) {
326 expect(torrent
.files
).to
.exist
327 expect(torrent
.files
.length
).to
.equal(1)
328 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
335 it('Should add the file 3 by asking pod 2', function (done
) {
336 // Yes, this could be long
339 utils
.getVideosList(servers
[1].url
, function (err
, res
) {
342 const video
= res
.body
.data
[2]
344 webtorrent
.add(video
.magnetUri
, function (torrent
) {
345 expect(torrent
.files
).to
.exist
346 expect(torrent
.files
.length
).to
.equal(1)
347 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
349 webtorrent
.remove(video
.magnetUri
, done
)
354 it('Should add the file 3-2 by asking pod 1', function (done
) {
355 // Yes, this could be long
358 utils
.getVideosList(servers
[0].url
, function (err
, res
) {
361 const video
= res
.body
.data
[3]
363 webtorrent
.add(video
.magnetUri
, function (torrent
) {
364 expect(torrent
.files
).to
.exist
365 expect(torrent
.files
.length
).to
.equal(1)
366 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
373 it('Should remove the file 3 and 3-2 by asking pod 3', function (done
) {
378 utils
.removeVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[0], next
)
381 utils
.removeVideo(servers
[2].url
, servers
[2].accessToken
, toRemove
[1], next
)
385 setTimeout(done
, 11000)
390 it('Should have videos 1 and 3 on each pod', function (done
) {
391 each(servers
, function (server
, callback
) {
392 utils
.getVideosList(server
.url
, function (err
, res
) {
395 const videos
= res
.body
.data
396 expect(videos
).to
.be
.an('array')
397 expect(videos
.length
).to
.equal(2)
398 expect(videos
[0].id
).not
.to
.equal(videos
[1].id
)
399 expect(videos
[0].id
).not
.to
.equal(toRemove
[0])
400 expect(videos
[1].id
).not
.to
.equal(toRemove
[0])
401 expect(videos
[0].id
).not
.to
.equal(toRemove
[1])
402 expect(videos
[1].id
).not
.to
.equal(toRemove
[1])
410 after(function (done
) {
411 servers
.forEach(function (server
) {
412 process
.kill(-server
.app
.pid
)
414 process
.kill(-webtorrent
.app
.pid
)
416 // Keep the logs if the test failed
418 utils
.flushTests(done
)