]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/multiplePods.js
3 const async
= require('async')
4 const chai
= require('chai')
5 const expect
= chai
.expect
6 const pathUtils
= require('path')
8 const utils
= require('./utils')
9 const webtorrent
= require(pathUtils
.join(__dirname
, '../../lib/webtorrent'))
10 webtorrent
.silent
= true
12 describe('Test multiple pods', function () {
16 before(function (done
) {
22 utils
.flushAndRunMultipleServers(3, function (servers_run
) {
27 // Get the access tokens
29 async
.each(servers
, function (server
, callback_each
) {
30 utils
.loginAndGetAccessToken(server
, function (err
, access_token
) {
31 if (err
) return callback_each(err
)
33 server
.access_token
= access_token
38 // The second pod make friend with the third
40 utils
.makeFriends(servers
[1].url
, next
)
42 // Wait for the request between pods
44 setTimeout(next
, 10000)
46 // Pod 1 make friends too
48 utils
.makeFriends(servers
[0].url
, next
)
51 webtorrent
.create({ host: 'client', port: '1' }, next
)
56 it('Should not have videos for all pods', function (done
) {
57 async
.each(servers
, function (server
, callback
) {
58 utils
.getVideosList(server
.url
, function (err
, res
) {
61 expect(res
.body
).to
.be
.an('array')
62 expect(res
.body
.length
).to
.equal(0)
69 describe('Should upload the video and propagate on each pod', function () {
70 it('Should upload the video on pod 1 and propagate on each pod', function (done
) {
75 utils
.uploadVideo(servers
[0].url
, servers
[0].access_token
, 'my super name for pod 1', 'my super description for pod 1', 'video_short1.webm', next
)
78 setTimeout(next
, 11000)
80 // All pods should have this video
84 async
.each(servers
, function (server
, callback
) {
85 let base_magnet
= null
87 utils
.getVideosList(server
.url
, function (err
, res
) {
90 const videos
= res
.body
91 expect(videos
).to
.be
.an('array')
92 expect(videos
.length
).to
.equal(1)
93 const video
= videos
[0]
94 expect(video
.name
).to
.equal('my super name for pod 1')
95 expect(video
.description
).to
.equal('my super description for pod 1')
96 expect(video
.podUrl
).to
.equal('http://localhost:9001')
97 expect(video
.magnetUri
).to
.exist
99 if (server
.url
!== 'http://localhost:9001') {
100 expect(video
.isLocal
).to
.be
.false
102 expect(video
.isLocal
).to
.be
.true
105 // All pods should have the same magnet Uri
106 if (base_magnet
=== null) {
107 base_magnet
= video
.magnetUri
109 expect(video
.magnetUri
).to
.equal
.magnetUri
119 it('Should upload the video on pod 2 and propagate on each pod', function (done
) {
124 utils
.uploadVideo(servers
[1].url
, servers
[1].access_token
, 'my super name for pod 2', 'my super description for pod 2', 'video_short2.webm', next
)
127 setTimeout(next
, 11000)
129 // All pods should have this video
133 async
.each(servers
, function (server
, callback
) {
134 let base_magnet
= null
136 utils
.getVideosList(server
.url
, function (err
, res
) {
139 const videos
= res
.body
140 expect(videos
).to
.be
.an('array')
141 expect(videos
.length
).to
.equal(2)
142 const video
= videos
[1]
143 expect(video
.name
).to
.equal('my super name for pod 2')
144 expect(video
.description
).to
.equal('my super description for pod 2')
145 expect(video
.podUrl
).to
.equal('http://localhost:9002')
146 expect(video
.magnetUri
).to
.exist
148 if (server
.url
!== 'http://localhost:9002') {
149 expect(video
.isLocal
).to
.be
.false
151 expect(video
.isLocal
).to
.be
.true
154 // All pods should have the same magnet Uri
155 if (base_magnet
=== null) {
156 base_magnet
= video
.magnetUri
158 expect(video
.magnetUri
).to
.equal
.magnetUri
168 it('Should upload two videos on pod 3 and propagate on each pod', function (done
) {
173 utils
.uploadVideo(servers
[2].url
, servers
[2].access_token
, 'my super name for pod 3', 'my super description for pod 3', 'video_short3.webm', next
)
176 utils
.uploadVideo(servers
[2].url
, servers
[2].access_token
, 'my super name for pod 3-2', 'my super description for pod 3-2', 'video_short.webm', next
)
179 setTimeout(next
, 22000)
184 let base_magnet
= null
185 // All pods should have this video
186 async
.each(servers
, function (server
, callback
) {
187 utils
.getVideosList(server
.url
, function (err
, res
) {
190 const videos
= res
.body
191 expect(videos
).to
.be
.an('array')
192 expect(videos
.length
).to
.equal(4)
193 const video1
= videos
[2]
194 expect(video1
.name
).to
.equal('my super name for pod 3')
195 expect(video1
.description
).to
.equal('my super description for pod 3')
196 expect(video1
.podUrl
).to
.equal('http://localhost:9003')
197 expect(video1
.magnetUri
).to
.exist
199 const video2
= videos
[3]
200 expect(video2
.name
).to
.equal('my super name for pod 3-2')
201 expect(video2
.description
).to
.equal('my super description for pod 3-2')
202 expect(video2
.podUrl
).to
.equal('http://localhost:9003')
203 expect(video2
.magnetUri
).to
.exist
205 if (server
.url
!== 'http://localhost:9003') {
206 expect(video1
.isLocal
).to
.be
.false
207 expect(video2
.isLocal
).to
.be
.false
209 expect(video1
.isLocal
).to
.be
.true
210 expect(video2
.isLocal
).to
.be
.true
213 // All pods should have the same magnet Uri
214 if (base_magnet
=== null) {
215 base_magnet
= video2
.magnetUri
217 expect(video2
.magnetUri
).to
.equal
.magnetUri
228 describe('Should seed the uploaded video', function () {
229 it('Should add the file 1 by asking pod 3', function (done
) {
230 // Yes, this could be long
233 utils
.getVideosList(servers
[2].url
, function (err
, res
) {
236 const video
= res
.body
[0]
237 to_remove
.push(res
.body
[2].id
)
238 to_remove
.push(res
.body
[3].id
)
240 webtorrent
.add(video
.magnetUri
, function (torrent
) {
241 expect(torrent
.files
).to
.exist
242 expect(torrent
.files
.length
).to
.equal(1)
243 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
250 it('Should add the file 2 by asking pod 1', function (done
) {
251 // Yes, this could be long
254 utils
.getVideosList(servers
[0].url
, function (err
, res
) {
257 const video
= res
.body
[1]
259 webtorrent
.add(video
.magnetUri
, function (torrent
) {
260 expect(torrent
.files
).to
.exist
261 expect(torrent
.files
.length
).to
.equal(1)
262 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
269 it('Should add the file 3 by asking pod 2', function (done
) {
270 // Yes, this could be long
273 utils
.getVideosList(servers
[1].url
, function (err
, res
) {
276 const video
= res
.body
[2]
278 webtorrent
.add(video
.magnetUri
, function (torrent
) {
279 expect(torrent
.files
).to
.exist
280 expect(torrent
.files
.length
).to
.equal(1)
281 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
288 it('Should add the file 3-2 by asking pod 1', function (done
) {
289 // Yes, this could be long
292 utils
.getVideosList(servers
[0].url
, function (err
, res
) {
295 const video
= res
.body
[3]
297 webtorrent
.add(video
.magnetUri
, function (torrent
) {
298 expect(torrent
.files
).to
.exist
299 expect(torrent
.files
.length
).to
.equal(1)
300 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
307 it('Should remove the file 3 and 3-2 by asking pod 3', function (done
) {
312 utils
.removeVideo(servers
[2].url
, servers
[2].access_token
, to_remove
[0], next
)
315 utils
.removeVideo(servers
[2].url
, servers
[2].access_token
, to_remove
[1], next
)
319 setTimeout(done
, 11000)
324 it('Should have videos 1 and 3 on each pod', function (done
) {
325 async
.each(servers
, function (server
, callback
) {
326 utils
.getVideosList(server
.url
, function (err
, res
) {
329 const videos
= res
.body
330 expect(videos
).to
.be
.an('array')
331 expect(videos
.length
).to
.equal(2)
332 expect(videos
[0].id
).not
.to
.equal(videos
[1].id
)
333 expect(videos
[0].id
).not
.to
.equal(to_remove
[0])
334 expect(videos
[1].id
).not
.to
.equal(to_remove
[0])
335 expect(videos
[0].id
).not
.to
.equal(to_remove
[1])
336 expect(videos
[1].id
).not
.to
.equal(to_remove
[1])
344 after(function (done
) {
345 servers
.forEach(function (server
) {
346 process
.kill(-server
.app
.pid
)
348 process
.kill(-webtorrent
.app
.pid
)
350 // Keep the logs if the test failed
352 utils
.flushTests(done
)