]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - test/api/multiplePods.js
4 var request
= require('supertest')
5 var chai
= require('chai')
6 var expect
= chai
.expect
7 var async
= require('async')
9 var utils
= require('../utils')
10 var webtorrent
= require(__dirname
+ '/../../src/webTorrentNode')
11 webtorrent
.silent
= true
13 describe('Test multiple pods', function () {
14 var path
= '/api/videos'
19 function getVideosList (url
, end
) {
22 .set('Accept', 'application/json')
24 .expect('Content-Type', /json/)
28 function uploadVideo (url
, name
, description
, fixture
, end
) {
31 .set('Accept', 'application/json')
33 .field('description', description
)
34 .attach('input_video', __dirname
+ '/../fixtures/' + fixture
)
39 before(function (done
) {
41 var path_friends
= '/api/pods/makefriends'
43 utils
.runMultipleServers(3, function (apps_run
, urls_run
) {
47 // The second pod make friend with the third
50 .set('Accept', 'application/json')
52 .end(function (err
, res
) {
55 // Wait for the request between pods
56 setTimeout(function () {
59 .set('Accept', 'application/json')
61 .end(function (err
, res
) {
64 webtorrent
.create(function () {
73 it('Should not have videos for all pods', function (done
) {
74 async
.each(urls
, function (url
, callback
) {
75 getVideosList(url
, function (err
, res
) {
78 expect(res
.body
).to
.be
.an('array')
79 expect(res
.body
.length
).to
.equal(0)
90 describe('Should upload the video and propagate on each pod', function () {
91 it('Should upload the video on pod 1 and propagate on each pod', function (done
) {
94 uploadVideo(urls
[0], 'my super name for pod 1', 'my super description for pod 1', 'video_short1.webm', function (err
) {
97 setTimeout(function () {
98 // All pods should have this video
99 async
.each(urls
, function (url
, callback
) {
100 var base_magnet
= null
102 getVideosList(url
, function (err
, res
) {
105 var videos
= res
.body
106 expect(videos
).to
.be
.an('array')
107 expect(videos
.length
).to
.equal(1)
108 var video
= videos
[0]
109 expect(video
.name
).to
.equal('my super name for pod 1')
110 expect(video
.description
).to
.equal('my super description for pod 1')
111 expect(video
.podUrl
).to
.equal('http://localhost:9001')
112 expect(video
.magnetUri
).to
.exist
114 // All pods should have the same magnet Uri
115 if (base_magnet
=== null) {
116 base_magnet
= video
.magnetUri
118 expect(video
.magnetUri
).to
.equal
.magnetUri
132 it('Should upload the video on pod 2 and propagate on each pod', function (done
) {
135 uploadVideo(urls
[1], 'my super name for pod 2', 'my super description for pod 2', 'video_short2.webm', function (err
) {
138 setTimeout(function () {
139 // All pods should have this video
140 async
.each(urls
, function (url
, callback
) {
141 var base_magnet
= null
143 getVideosList(url
, function (err
, res
) {
146 var videos
= res
.body
147 expect(videos
).to
.be
.an('array')
148 expect(videos
.length
).to
.equal(2)
149 var video
= videos
[1]
150 expect(video
.name
).to
.equal('my super name for pod 2')
151 expect(video
.description
).to
.equal('my super description for pod 2')
152 expect(video
.podUrl
).to
.equal('http://localhost:9002')
153 expect(video
.magnetUri
).to
.exist
155 // All pods should have the same magnet Uri
156 if (base_magnet
=== null) {
157 base_magnet
= video
.magnetUri
159 expect(video
.magnetUri
).to
.equal
.magnetUri
173 it('Should upload the video on pod 3 and propagate on each pod', function (done
) {
176 uploadVideo(urls
[2], 'my super name for pod 3', 'my super description for pod 3', 'video_short3.webm', function (err
) {
179 setTimeout(function () {
180 var base_magnet
= null
181 // All pods should have this video
182 async
.each(urls
, function (url
, callback
) {
183 getVideosList(url
, function (err
, res
) {
186 var videos
= res
.body
187 expect(videos
).to
.be
.an('array')
188 expect(videos
.length
).to
.equal(3)
189 var video
= videos
[2]
190 expect(video
.name
).to
.equal('my super name for pod 3')
191 expect(video
.description
).to
.equal('my super description for pod 3')
192 expect(video
.podUrl
).to
.equal('http://localhost:9003')
193 expect(video
.magnetUri
).to
.exist
195 // All pods should have the same magnet Uri
196 if (base_magnet
=== null) {
197 base_magnet
= video
.magnetUri
199 expect(video
.magnetUri
).to
.equal
.magnetUri
214 describe('Should seed the uploaded video', function () {
215 it('Should add the file 1 by asking pod 3', function (done
) {
216 // Yes, this could be long
219 getVideosList(urls
[2], function (err
, res
) {
222 var video
= res
.body
[0]
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 2 by asking pod 1', function (done
) {
234 // Yes, this could be long
237 getVideosList(urls
[0], function (err
, res
) {
240 var video
= res
.body
[1]
244 webtorrent
.add(video
.magnetUri
, function (torrent
) {
245 expect(torrent
.files
).to
.exist
246 expect(torrent
.files
.length
).to
.equal(1)
247 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
254 it('Should add the file 3 by asking pod 2', function (done
) {
255 // Yes, this could be long
258 getVideosList(urls
[1], function (err
, res
) {
261 var video
= res
.body
[2]
263 webtorrent
.add(video
.magnetUri
, function (torrent
) {
264 expect(torrent
.files
).to
.exist
265 expect(torrent
.files
.length
).to
.equal(1)
266 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
273 it('Should remove the file 2 by asking pod 2', function (done
) {
275 .delete(path
+ '/' + video_id
)
276 .set('Accept', 'application/json')
278 .end(function (err
, res
) {
281 // Wait the propagation to the other pods
282 setTimeout(function () {
288 it('Should have videos 1 and 2 on each pod', function (done
) {
289 async
.each(urls
, function (url
, callback
) {
290 getVideosList(url
, function (err
, res
) {
293 var videos
= res
.body
294 expect(videos
).to
.be
.an('array')
295 expect(videos
.length
).to
.equal(2)
296 expect(videos
[0]._id
).not
.to
.equal(videos
[1]._id
)
297 expect(videos
[0]._id
).not
.to
.equal(video_id
)
298 expect(videos
[1]._id
).not
.to
.equal(video_id
)
310 after(function (done
) {
311 apps
.forEach(function (app
) {
312 process
.kill(-app
.pid
)
314 process
.kill(-webtorrent
.app
.pid
)
316 // Keep the logs if the test failed
318 utils
.flushTests(function () {