]>
Commit | Line | Data |
---|---|---|
8c308c2b C |
1 | ;(function () { |
2 | 'use strict' | |
3 | ||
876d1bcf | 4 | var async = require('async') |
8c308c2b C |
5 | var chai = require('chai') |
6 | var expect = chai.expect | |
b3077e41 | 7 | var pathUtils = require('path') |
8c308c2b | 8 | |
876d1bcf | 9 | var utils = require('./utils') |
b3077e41 | 10 | var webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent')) |
8c308c2b C |
11 | webtorrent.silent = true |
12 | ||
13 | describe('Test multiple pods', function () { | |
8c308c2b C |
14 | var apps = [] |
15 | var urls = [] | |
0b697522 | 16 | var to_remove = [] |
8c308c2b | 17 | |
8c308c2b | 18 | before(function (done) { |
88c8d458 | 19 | this.timeout(30000) |
8c308c2b | 20 | |
ee66c593 C |
21 | async.series([ |
22 | // Run servers | |
23 | function (next) { | |
24 | utils.flushAndRunMultipleServers(3, function (apps_run, urls_run) { | |
25 | apps = apps_run | |
26 | urls = urls_run | |
27 | next() | |
28 | }) | |
29 | }, | |
8c308c2b | 30 | // The second pod make friend with the third |
ee66c593 C |
31 | function (next) { |
32 | utils.makeFriends(urls[1], next) | |
33 | }, | |
34 | // Wait for the request between pods | |
35 | function (next) { | |
36 | setTimeout(next, 10000) | |
37 | }, | |
38 | // Pod 1 make friends too | |
39 | function (next) { | |
40 | utils.makeFriends(urls[0], next) | |
41 | }, | |
42 | function (next) { | |
43 | webtorrent.create({ host: 'client', port: '1' }, next) | |
44 | } | |
45 | ], done) | |
8c308c2b C |
46 | }) |
47 | ||
48 | it('Should not have videos for all pods', function (done) { | |
49 | async.each(urls, function (url, callback) { | |
876d1bcf | 50 | utils.getVideosList(url, function (err, res) { |
8c308c2b C |
51 | if (err) throw err |
52 | ||
53 | expect(res.body).to.be.an('array') | |
54 | expect(res.body.length).to.equal(0) | |
55 | ||
56 | callback() | |
57 | }) | |
ee66c593 | 58 | }, done) |
8c308c2b C |
59 | }) |
60 | ||
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) { | |
0b697522 | 63 | this.timeout(15000) |
8c308c2b | 64 | |
ee66c593 C |
65 | async.series([ |
66 | function (next) { | |
67 | utils.uploadVideo(urls[0], 'my super name for pod 1', 'my super description for pod 1', 'video_short1.webm', next) | |
68 | }, | |
69 | function (next) { | |
70 | setTimeout(next, 11000) | |
71 | }], | |
72 | // All pods should have this video | |
73 | function (err) { | |
74 | if (err) throw err | |
8c308c2b | 75 | |
8c308c2b C |
76 | async.each(urls, function (url, callback) { |
77 | var base_magnet = null | |
78 | ||
876d1bcf | 79 | utils.getVideosList(url, function (err, res) { |
8c308c2b C |
80 | if (err) throw err |
81 | ||
82 | var videos = res.body | |
83 | expect(videos).to.be.an('array') | |
84 | expect(videos.length).to.equal(1) | |
85 | var video = videos[0] | |
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 | |
90 | ||
91 | // All pods should have the same magnet Uri | |
92 | if (base_magnet === null) { | |
93 | base_magnet = video.magnetUri | |
94 | } else { | |
95 | expect(video.magnetUri).to.equal.magnetUri | |
96 | } | |
97 | ||
98 | callback() | |
99 | }) | |
ee66c593 C |
100 | }, done) |
101 | } | |
102 | ) | |
8c308c2b C |
103 | }) |
104 | ||
105 | it('Should upload the video on pod 2 and propagate on each pod', function (done) { | |
0b697522 | 106 | this.timeout(15000) |
8c308c2b | 107 | |
ee66c593 C |
108 | async.series([ |
109 | function (next) { | |
110 | utils.uploadVideo(urls[1], 'my super name for pod 2', 'my super description for pod 2', 'video_short2.webm', next) | |
111 | }, | |
112 | function (next) { | |
113 | setTimeout(next, 11000) | |
114 | }], | |
115 | // All pods should have this video | |
116 | function (err) { | |
117 | if (err) throw err | |
8c308c2b | 118 | |
8c308c2b C |
119 | async.each(urls, function (url, callback) { |
120 | var base_magnet = null | |
121 | ||
876d1bcf | 122 | utils.getVideosList(url, function (err, res) { |
8c308c2b C |
123 | if (err) throw err |
124 | ||
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 | |
133 | ||
134 | // All pods should have the same magnet Uri | |
135 | if (base_magnet === null) { | |
136 | base_magnet = video.magnetUri | |
137 | } else { | |
138 | expect(video.magnetUri).to.equal.magnetUri | |
139 | } | |
140 | ||
141 | callback() | |
142 | }) | |
ee66c593 C |
143 | }, done) |
144 | } | |
145 | ) | |
8c308c2b C |
146 | }) |
147 | ||
0b697522 | 148 | it('Should upload two videos on pod 3 and propagate on each pod', function (done) { |
2cc8ebf1 | 149 | this.timeout(30000) |
8c308c2b | 150 | |
ee66c593 C |
151 | async.series([ |
152 | function (next) { | |
153 | utils.uploadVideo(urls[2], 'my super name for pod 3', 'my super description for pod 3', 'video_short3.webm', next) | |
154 | }, | |
155 | function (next) { | |
156 | utils.uploadVideo(urls[2], 'my super name for pod 3-2', 'my super description for pod 3-2', 'video_short.webm', next) | |
157 | }, | |
158 | function (next) { | |
159 | setTimeout(next, 22000) | |
160 | }], | |
161 | function (err) { | |
0b697522 | 162 | if (err) throw err |
8c308c2b | 163 | |
ee66c593 C |
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) { | |
0b697522 | 168 | if (err) throw err |
8c308c2b | 169 | |
ee66c593 C |
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 | |
178 | ||
179 | video = videos[3] | |
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 | |
184 | ||
185 | // All pods should have the same magnet Uri | |
186 | if (base_magnet === null) { | |
187 | base_magnet = video.magnetUri | |
188 | } else { | |
189 | expect(video.magnetUri).to.equal.magnetUri | |
190 | } | |
191 | ||
192 | callback() | |
8c308c2b | 193 | }) |
ee66c593 C |
194 | }, done) |
195 | } | |
196 | ) | |
8c308c2b C |
197 | }) |
198 | }) | |
199 | ||
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 | |
77c2df95 | 203 | this.timeout(200000) |
8c308c2b | 204 | |
876d1bcf | 205 | utils.getVideosList(urls[2], function (err, res) { |
8c308c2b C |
206 | if (err) throw err |
207 | ||
208 | var video = res.body[0] | |
0b697522 C |
209 | to_remove.push(res.body[2]._id) |
210 | to_remove.push(res.body[3]._id) | |
211 | ||
8c308c2b C |
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('') | |
216 | ||
217 | done() | |
218 | }) | |
219 | }) | |
220 | }) | |
221 | ||
222 | it('Should add the file 2 by asking pod 1', function (done) { | |
223 | // Yes, this could be long | |
77c2df95 | 224 | this.timeout(200000) |
8c308c2b | 225 | |
876d1bcf | 226 | utils.getVideosList(urls[0], function (err, res) { |
8c308c2b C |
227 | if (err) throw err |
228 | ||
229 | var video = res.body[1] | |
230 | ||
8c308c2b C |
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('') | |
235 | ||
236 | done() | |
237 | }) | |
238 | }) | |
239 | }) | |
240 | ||
241 | it('Should add the file 3 by asking pod 2', function (done) { | |
242 | // Yes, this could be long | |
77c2df95 | 243 | this.timeout(200000) |
8c308c2b | 244 | |
876d1bcf | 245 | utils.getVideosList(urls[1], function (err, res) { |
8c308c2b C |
246 | if (err) throw err |
247 | ||
248 | var video = res.body[2] | |
249 | ||
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('') | |
254 | ||
255 | done() | |
256 | }) | |
257 | }) | |
258 | }) | |
259 | ||
0b697522 C |
260 | it('Should add the file 3-2 by asking pod 1', function (done) { |
261 | // Yes, this could be long | |
262 | this.timeout(200000) | |
263 | ||
876d1bcf | 264 | utils.getVideosList(urls[0], function (err, res) { |
0b697522 C |
265 | if (err) throw err |
266 | ||
267 | var video = res.body[3] | |
268 | ||
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('') | |
273 | ||
274 | done() | |
275 | }) | |
276 | }) | |
277 | }) | |
278 | ||
279 | it('Should remove the file 3 and 3-2 by asking pod 3', function (done) { | |
280 | this.timeout(15000) | |
281 | ||
ee66c593 C |
282 | async.series([ |
283 | function (next) { | |
284 | utils.removeVideo(urls[2], to_remove[0], next) | |
285 | }, | |
286 | function (next) { | |
287 | utils.removeVideo(urls[2], to_remove[1], next) | |
288 | }], | |
289 | function (err) { | |
8c308c2b | 290 | if (err) throw err |
ee66c593 C |
291 | setTimeout(done, 11000) |
292 | } | |
293 | ) | |
8c308c2b C |
294 | }) |
295 | ||
15e52799 | 296 | it('Should have videos 1 and 3 on each pod', function (done) { |
8c308c2b | 297 | async.each(urls, function (url, callback) { |
876d1bcf | 298 | utils.getVideosList(url, function (err, res) { |
8c308c2b C |
299 | if (err) throw err |
300 | ||
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) | |
0b697522 C |
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]) | |
8c308c2b C |
309 | |
310 | callback() | |
311 | }) | |
ee66c593 | 312 | }, done) |
8c308c2b C |
313 | }) |
314 | }) | |
315 | ||
316 | after(function (done) { | |
317 | apps.forEach(function (app) { | |
318 | process.kill(-app.pid) | |
319 | }) | |
320 | process.kill(-webtorrent.app.pid) | |
321 | ||
322 | // Keep the logs if the test failed | |
323 | if (this.ok) { | |
ee66c593 | 324 | utils.flushTests(done) |
8c308c2b C |
325 | } else { |
326 | done() | |
327 | } | |
328 | }) | |
329 | }) | |
330 | })() |