]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - tests/api/multiplePods.js
4 var async
= require('async')
5 var chai
= require('chai')
6 var expect
= chai
.expect
7 var pathUtils
= require('path')
9 var utils
= require('./utils')
10 var webtorrent
= require(pathUtils
.join(__dirname
, '../../lib/webtorrent'))
11 webtorrent
.silent
= true
13 describe('Test multiple pods', function () {
18 before(function (done
) {
24 utils
.flushAndRunMultipleServers(3, function (apps_run
, urls_run
) {
30 // The second pod make friend with the third
32 utils
.makeFriends(urls
[1], next
)
34 // Wait for the request between pods
36 setTimeout(next
, 10000)
38 // Pod 1 make friends too
40 utils
.makeFriends(urls
[0], next
)
43 webtorrent
.create({ host: 'client', port: '1' }, next
)
48 it('Should not have videos for all pods', function (done
) {
49 async
.each(urls
, function (url
, callback
) {
50 utils
.getVideosList(url
, function (err
, res
) {
53 expect(res
.body
).to
.be
.an('array')
54 expect(res
.body
.length
).to
.equal(0)
61 describe('Should upload the video and propagate on each pod', function () {
62 it('Should upload the video on pod 1 and propagate on each pod', function (done
) {
67 utils
.uploadVideo(urls
[0], 'my super name for pod 1', 'my super description for pod 1', 'video_short1.webm', next
)
70 setTimeout(next
, 11000)
72 // All pods should have this video
76 async
.each(urls
, function (url
, callback
) {
77 var base_magnet
= null
79 utils
.getVideosList(url
, function (err
, res
) {
83 expect(videos
).to
.be
.an('array')
84 expect(videos
.length
).to
.equal(1)
86 expect(video
.name
).to
.equal('my super name for pod 1')
87 expect(video
.description
).to
.equal('my super description for pod 1')
88 expect(video
.podUrl
).to
.equal('http://localhost:9001')
89 expect(video
.magnetUri
).to
.exist
91 // All pods should have the same magnet Uri
92 if (base_magnet
=== null) {
93 base_magnet
= video
.magnetUri
95 expect(video
.magnetUri
).to
.equal
.magnetUri
105 it('Should upload the video on pod 2 and propagate on each pod', function (done
) {
110 utils
.uploadVideo(urls
[1], 'my super name for pod 2', 'my super description for pod 2', 'video_short2.webm', next
)
113 setTimeout(next
, 11000)
115 // All pods should have this video
119 async
.each(urls
, function (url
, callback
) {
120 var base_magnet
= null
122 utils
.getVideosList(url
, function (err
, res
) {
125 var videos
= res
.body
126 expect(videos
).to
.be
.an('array')
127 expect(videos
.length
).to
.equal(2)
128 var video
= videos
[1]
129 expect(video
.name
).to
.equal('my super name for pod 2')
130 expect(video
.description
).to
.equal('my super description for pod 2')
131 expect(video
.podUrl
).to
.equal('http://localhost:9002')
132 expect(video
.magnetUri
).to
.exist
134 // All pods should have the same magnet Uri
135 if (base_magnet
=== null) {
136 base_magnet
= video
.magnetUri
138 expect(video
.magnetUri
).to
.equal
.magnetUri
148 it('Should upload two videos on pod 3 and propagate on each pod', function (done
) {
153 utils
.uploadVideo(urls
[2], 'my super name for pod 3', 'my super description for pod 3', 'video_short3.webm', next
)
156 utils
.uploadVideo(urls
[2], 'my super name for pod 3-2', 'my super description for pod 3-2', 'video_short.webm', next
)
159 setTimeout(next
, 22000)
164 var base_magnet
= null
165 // All pods should have this video
166 async
.each(urls
, function (url
, callback
) {
167 utils
.getVideosList(url
, function (err
, res
) {
170 var videos
= res
.body
171 expect(videos
).to
.be
.an('array')
172 expect(videos
.length
).to
.equal(4)
173 var video
= videos
[2]
174 expect(video
.name
).to
.equal('my super name for pod 3')
175 expect(video
.description
).to
.equal('my super description for pod 3')
176 expect(video
.podUrl
).to
.equal('http://localhost:9003')
177 expect(video
.magnetUri
).to
.exist
180 expect(video
.name
).to
.equal('my super name for pod 3-2')
181 expect(video
.description
).to
.equal('my super description for pod 3-2')
182 expect(video
.podUrl
).to
.equal('http://localhost:9003')
183 expect(video
.magnetUri
).to
.exist
185 // All pods should have the same magnet Uri
186 if (base_magnet
=== null) {
187 base_magnet
= video
.magnetUri
189 expect(video
.magnetUri
).to
.equal
.magnetUri
200 describe('Should seed the uploaded video', function () {
201 it('Should add the file 1 by asking pod 3', function (done
) {
202 // Yes, this could be long
205 utils
.getVideosList(urls
[2], function (err
, res
) {
208 var video
= res
.body
[0]
209 to_remove
.push(res
.body
[2]._id
)
210 to_remove
.push(res
.body
[3]._id
)
212 webtorrent
.add(video
.magnetUri
, function (torrent
) {
213 expect(torrent
.files
).to
.exist
214 expect(torrent
.files
.length
).to
.equal(1)
215 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
222 it('Should add the file 2 by asking pod 1', function (done
) {
223 // Yes, this could be long
226 utils
.getVideosList(urls
[0], function (err
, res
) {
229 var video
= res
.body
[1]
231 webtorrent
.add(video
.magnetUri
, function (torrent
) {
232 expect(torrent
.files
).to
.exist
233 expect(torrent
.files
.length
).to
.equal(1)
234 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
241 it('Should add the file 3 by asking pod 2', function (done
) {
242 // Yes, this could be long
245 utils
.getVideosList(urls
[1], function (err
, res
) {
248 var video
= res
.body
[2]
250 webtorrent
.add(video
.magnetUri
, function (torrent
) {
251 expect(torrent
.files
).to
.exist
252 expect(torrent
.files
.length
).to
.equal(1)
253 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
260 it('Should add the file 3-2 by asking pod 1', function (done
) {
261 // Yes, this could be long
264 utils
.getVideosList(urls
[0], function (err
, res
) {
267 var video
= res
.body
[3]
269 webtorrent
.add(video
.magnetUri
, function (torrent
) {
270 expect(torrent
.files
).to
.exist
271 expect(torrent
.files
.length
).to
.equal(1)
272 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
279 it('Should remove the file 3 and 3-2 by asking pod 3', function (done
) {
284 utils
.removeVideo(urls
[2], to_remove
[0], next
)
287 utils
.removeVideo(urls
[2], to_remove
[1], next
)
291 setTimeout(done
, 11000)
296 it('Should have videos 1 and 3 on each pod', function (done
) {
297 async
.each(urls
, function (url
, callback
) {
298 utils
.getVideosList(url
, function (err
, res
) {
301 var videos
= res
.body
302 expect(videos
).to
.be
.an('array')
303 expect(videos
.length
).to
.equal(2)
304 expect(videos
[0]._id
).not
.to
.equal(videos
[1]._id
)
305 expect(videos
[0]._id
).not
.to
.equal(to_remove
[0])
306 expect(videos
[1]._id
).not
.to
.equal(to_remove
[0])
307 expect(videos
[0]._id
).not
.to
.equal(to_remove
[1])
308 expect(videos
[1]._id
).not
.to
.equal(to_remove
[1])
316 after(function (done
) {
317 apps
.forEach(function (app
) {
318 process
.kill(-app
.pid
)
320 process
.kill(-webtorrent
.app
.pid
)
322 // Keep the logs if the test failed
324 utils
.flushTests(done
)