]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - test/api/multiplePods.js
4 var async
= require('async')
5 var chai
= require('chai')
6 var expect
= chai
.expect
8 var utils
= require('./utils')
9 var webtorrent
= require(__dirname
+ '/../../src/webTorrentNode')
10 webtorrent
.silent
= true
12 describe('Test multiple pods', function () {
17 before(function (done
) {
20 utils
.runMultipleServers(3, function (apps_run
, urls_run
) {
24 // The second pod make friend with the third
25 utils
.makeFriend(urls
[1], function (err
, res
) {
28 // Wait for the request between pods
29 setTimeout(function () {
30 utils
.makeFriend(urls
[0], function (err
, res
) {
33 webtorrent
.create({ host: 'client', port: '1' }, function () {
42 it('Should not have videos for all pods', function (done
) {
43 async
.each(urls
, function (url
, callback
) {
44 utils
.getVideosList(url
, function (err
, res
) {
47 expect(res
.body
).to
.be
.an('array')
48 expect(res
.body
.length
).to
.equal(0)
59 describe('Should upload the video and propagate on each pod', function () {
60 it('Should upload the video on pod 1 and propagate on each pod', function (done
) {
63 utils
.uploadVideo(urls
[0], 'my super name for pod 1', 'my super description for pod 1', 'video_short1.webm', function (err
) {
66 setTimeout(function () {
67 // All pods should have this video
68 async
.each(urls
, function (url
, callback
) {
69 var base_magnet
= null
71 utils
.getVideosList(url
, function (err
, res
) {
75 expect(videos
).to
.be
.an('array')
76 expect(videos
.length
).to
.equal(1)
78 expect(video
.name
).to
.equal('my super name for pod 1')
79 expect(video
.description
).to
.equal('my super description for pod 1')
80 expect(video
.podUrl
).to
.equal('http://localhost:9001')
81 expect(video
.magnetUri
).to
.exist
83 // All pods should have the same magnet Uri
84 if (base_magnet
=== null) {
85 base_magnet
= video
.magnetUri
87 expect(video
.magnetUri
).to
.equal
.magnetUri
101 it('Should upload the video on pod 2 and propagate on each pod', function (done
) {
104 utils
.uploadVideo(urls
[1], 'my super name for pod 2', 'my super description for pod 2', 'video_short2.webm', function (err
) {
107 setTimeout(function () {
108 // All pods should have this video
109 async
.each(urls
, function (url
, callback
) {
110 var base_magnet
= null
112 utils
.getVideosList(url
, function (err
, res
) {
115 var videos
= res
.body
116 expect(videos
).to
.be
.an('array')
117 expect(videos
.length
).to
.equal(2)
118 var video
= videos
[1]
119 expect(video
.name
).to
.equal('my super name for pod 2')
120 expect(video
.description
).to
.equal('my super description for pod 2')
121 expect(video
.podUrl
).to
.equal('http://localhost:9002')
122 expect(video
.magnetUri
).to
.exist
124 // All pods should have the same magnet Uri
125 if (base_magnet
=== null) {
126 base_magnet
= video
.magnetUri
128 expect(video
.magnetUri
).to
.equal
.magnetUri
142 it('Should upload two videos on pod 3 and propagate on each pod', function (done
) {
145 utils
.uploadVideo(urls
[2], 'my super name for pod 3', 'my super description for pod 3', 'video_short3.webm', function (err
) {
147 utils
.uploadVideo(urls
[2], 'my super name for pod 3-2', 'my super description for pod 3-2', 'video_short.webm', function (err
) {
150 setTimeout(function () {
151 var base_magnet
= null
152 // All pods should have this video
153 async
.each(urls
, function (url
, callback
) {
154 utils
.getVideosList(url
, function (err
, res
) {
157 var videos
= res
.body
158 expect(videos
).to
.be
.an('array')
159 expect(videos
.length
).to
.equal(4)
160 var video
= videos
[2]
161 expect(video
.name
).to
.equal('my super name for pod 3')
162 expect(video
.description
).to
.equal('my super description for pod 3')
163 expect(video
.podUrl
).to
.equal('http://localhost:9003')
164 expect(video
.magnetUri
).to
.exist
167 expect(video
.name
).to
.equal('my super name for pod 3-2')
168 expect(video
.description
).to
.equal('my super description for pod 3-2')
169 expect(video
.podUrl
).to
.equal('http://localhost:9003')
170 expect(video
.magnetUri
).to
.exist
172 // All pods should have the same magnet Uri
173 if (base_magnet
=== null) {
174 base_magnet
= video
.magnetUri
176 expect(video
.magnetUri
).to
.equal
.magnetUri
192 describe('Should seed the uploaded video', function () {
193 it('Should add the file 1 by asking pod 3', function (done
) {
194 // Yes, this could be long
197 utils
.getVideosList(urls
[2], function (err
, res
) {
200 var video
= res
.body
[0]
201 to_remove
.push(res
.body
[2]._id
)
202 to_remove
.push(res
.body
[3]._id
)
204 webtorrent
.add(video
.magnetUri
, function (torrent
) {
205 expect(torrent
.files
).to
.exist
206 expect(torrent
.files
.length
).to
.equal(1)
207 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
214 it('Should add the file 2 by asking pod 1', function (done
) {
215 // Yes, this could be long
218 utils
.getVideosList(urls
[0], function (err
, res
) {
221 var video
= res
.body
[1]
223 webtorrent
.add(video
.magnetUri
, function (torrent
) {
224 expect(torrent
.files
).to
.exist
225 expect(torrent
.files
.length
).to
.equal(1)
226 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
233 it('Should add the file 3 by asking pod 2', function (done
) {
234 // Yes, this could be long
237 utils
.getVideosList(urls
[1], function (err
, res
) {
240 var video
= res
.body
[2]
242 webtorrent
.add(video
.magnetUri
, function (torrent
) {
243 expect(torrent
.files
).to
.exist
244 expect(torrent
.files
.length
).to
.equal(1)
245 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
252 it('Should add the file 3-2 by asking pod 1', function (done
) {
253 // Yes, this could be long
256 utils
.getVideosList(urls
[0], function (err
, res
) {
259 var video
= res
.body
[3]
261 webtorrent
.add(video
.magnetUri
, function (torrent
) {
262 expect(torrent
.files
).to
.exist
263 expect(torrent
.files
.length
).to
.equal(1)
264 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
271 it('Should remove the file 3 and 3-2 by asking pod 3', function (done
) {
274 utils
.removeVideo(urls
[2], to_remove
[0], function (err
) {
276 utils
.removeVideo(urls
[2], to_remove
[1], function (err
) {
279 // Wait the propagation to the other pods
280 setTimeout(function () {
287 it('Should have videos 1 and 3 on each pod', function (done
) {
288 async
.each(urls
, function (url
, callback
) {
289 utils
.getVideosList(url
, function (err
, res
) {
292 var videos
= res
.body
293 expect(videos
).to
.be
.an('array')
294 expect(videos
.length
).to
.equal(2)
295 expect(videos
[0]._id
).not
.to
.equal(videos
[1]._id
)
296 expect(videos
[0]._id
).not
.to
.equal(to_remove
[0])
297 expect(videos
[1]._id
).not
.to
.equal(to_remove
[0])
298 expect(videos
[0]._id
).not
.to
.equal(to_remove
[1])
299 expect(videos
[1]._id
).not
.to
.equal(to_remove
[1])
311 after(function (done
) {
312 apps
.forEach(function (app
) {
313 process
.kill(-app
.pid
)
315 process
.kill(-webtorrent
.app
.pid
)
317 // Keep the logs if the test failed
319 utils
.flushTests(function () {