]>
Commit | Line | Data |
---|---|---|
9f10b292 C |
1 | 'use strict' |
2 | ||
f0f5567b C |
3 | const async = require('async') |
4 | const chai = require('chai') | |
5 | const expect = chai.expect | |
6 | const pathUtils = require('path') | |
9f10b292 | 7 | |
f0f5567b C |
8 | const utils = require('./utils') |
9 | const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent')) | |
9f10b292 C |
10 | webtorrent.silent = true |
11 | ||
12 | describe('Test multiple pods', function () { | |
0c1cbbfe | 13 | let servers = [] |
f0f5567b | 14 | const to_remove = [] |
9f10b292 C |
15 | |
16 | before(function (done) { | |
17 | this.timeout(30000) | |
18 | ||
19 | async.series([ | |
20 | // Run servers | |
21 | function (next) { | |
0c1cbbfe C |
22 | utils.flushAndRunMultipleServers(3, function (servers_run) { |
23 | servers = servers_run | |
9f10b292 C |
24 | next() |
25 | }) | |
26 | }, | |
0c1cbbfe C |
27 | // Get the access tokens |
28 | function (next) { | |
29 | async.each(servers, function (server, callback_each) { | |
30 | utils.loginAndGetAccessToken(server, function (err, access_token) { | |
31 | if (err) return callback_each(err) | |
32 | ||
33 | server.access_token = access_token | |
34 | callback_each() | |
35 | }) | |
36 | }, next) | |
37 | }, | |
9f10b292 C |
38 | // The second pod make friend with the third |
39 | function (next) { | |
0c1cbbfe | 40 | utils.makeFriends(servers[1].url, next) |
9f10b292 C |
41 | }, |
42 | // Wait for the request between pods | |
43 | function (next) { | |
44 | setTimeout(next, 10000) | |
45 | }, | |
46 | // Pod 1 make friends too | |
47 | function (next) { | |
0c1cbbfe | 48 | utils.makeFriends(servers[0].url, next) |
9f10b292 C |
49 | }, |
50 | function (next) { | |
51 | webtorrent.create({ host: 'client', port: '1' }, next) | |
52 | } | |
53 | ], done) | |
54 | }) | |
8c308c2b | 55 | |
9f10b292 | 56 | it('Should not have videos for all pods', function (done) { |
0c1cbbfe C |
57 | async.each(servers, function (server, callback) { |
58 | utils.getVideosList(server.url, function (err, res) { | |
9f10b292 | 59 | if (err) throw err |
8c308c2b | 60 | |
9f10b292 C |
61 | expect(res.body).to.be.an('array') |
62 | expect(res.body.length).to.equal(0) | |
8c308c2b | 63 | |
9f10b292 C |
64 | callback() |
65 | }) | |
66 | }, done) | |
67 | }) | |
8c308c2b | 68 | |
9f10b292 C |
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) { | |
71 | this.timeout(15000) | |
8c308c2b | 72 | |
ee66c593 | 73 | async.series([ |
ee66c593 | 74 | function (next) { |
0c1cbbfe | 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) |
ee66c593 | 76 | }, |
ee66c593 | 77 | function (next) { |
9f10b292 C |
78 | setTimeout(next, 11000) |
79 | }], | |
80 | // All pods should have this video | |
81 | function (err) { | |
82 | if (err) throw err | |
83 | ||
0c1cbbfe | 84 | async.each(servers, function (server, callback) { |
f0f5567b | 85 | let base_magnet = null |
9f10b292 | 86 | |
0c1cbbfe | 87 | utils.getVideosList(server.url, function (err, res) { |
9f10b292 C |
88 | if (err) throw err |
89 | ||
f0f5567b | 90 | const videos = res.body |
9f10b292 C |
91 | expect(videos).to.be.an('array') |
92 | expect(videos.length).to.equal(1) | |
f0f5567b | 93 | const video = videos[0] |
9f10b292 C |
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 | |
3a8a8b51 | 98 | expect(video.duration).to.equal(10) |
9f10b292 | 99 | |
6d8ada5f C |
100 | if (server.url !== 'http://localhost:9001') { |
101 | expect(video.isLocal).to.be.false | |
102 | } else { | |
103 | expect(video.isLocal).to.be.true | |
104 | } | |
105 | ||
9f10b292 C |
106 | // All pods should have the same magnet Uri |
107 | if (base_magnet === null) { | |
108 | base_magnet = video.magnetUri | |
109 | } else { | |
110 | expect(video.magnetUri).to.equal.magnetUri | |
111 | } | |
112 | ||
113 | callback() | |
114 | }) | |
115 | }, done) | |
116 | } | |
117 | ) | |
118 | }) | |
119 | ||
120 | it('Should upload the video on pod 2 and propagate on each pod', function (done) { | |
121 | this.timeout(15000) | |
122 | ||
123 | async.series([ | |
ee66c593 | 124 | function (next) { |
0c1cbbfe | 125 | 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) |
ee66c593 C |
126 | }, |
127 | function (next) { | |
9f10b292 C |
128 | setTimeout(next, 11000) |
129 | }], | |
130 | // All pods should have this video | |
131 | function (err) { | |
132 | if (err) throw err | |
133 | ||
0c1cbbfe | 134 | async.each(servers, function (server, callback) { |
f0f5567b | 135 | let base_magnet = null |
9f10b292 | 136 | |
0c1cbbfe | 137 | utils.getVideosList(server.url, function (err, res) { |
9f10b292 C |
138 | if (err) throw err |
139 | ||
f0f5567b | 140 | const videos = res.body |
9f10b292 C |
141 | expect(videos).to.be.an('array') |
142 | expect(videos.length).to.equal(2) | |
f0f5567b | 143 | const video = videos[1] |
9f10b292 C |
144 | expect(video.name).to.equal('my super name for pod 2') |
145 | expect(video.description).to.equal('my super description for pod 2') | |
146 | expect(video.podUrl).to.equal('http://localhost:9002') | |
147 | expect(video.magnetUri).to.exist | |
3a8a8b51 | 148 | expect(video.duration).to.equal(5) |
9f10b292 | 149 | |
6d8ada5f C |
150 | if (server.url !== 'http://localhost:9002') { |
151 | expect(video.isLocal).to.be.false | |
152 | } else { | |
153 | expect(video.isLocal).to.be.true | |
154 | } | |
155 | ||
9f10b292 C |
156 | // All pods should have the same magnet Uri |
157 | if (base_magnet === null) { | |
158 | base_magnet = video.magnetUri | |
159 | } else { | |
160 | expect(video.magnetUri).to.equal.magnetUri | |
161 | } | |
162 | ||
163 | callback() | |
164 | }) | |
165 | }, done) | |
ee66c593 | 166 | } |
9f10b292 | 167 | ) |
8c308c2b C |
168 | }) |
169 | ||
9f10b292 C |
170 | it('Should upload two videos on pod 3 and propagate on each pod', function (done) { |
171 | this.timeout(30000) | |
8c308c2b | 172 | |
9f10b292 C |
173 | async.series([ |
174 | function (next) { | |
0c1cbbfe | 175 | 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) |
9f10b292 C |
176 | }, |
177 | function (next) { | |
0c1cbbfe | 178 | 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) |
9f10b292 C |
179 | }, |
180 | function (next) { | |
181 | setTimeout(next, 22000) | |
182 | }], | |
183 | function (err) { | |
184 | if (err) throw err | |
8c308c2b | 185 | |
f0f5567b | 186 | let base_magnet = null |
9f10b292 | 187 | // All pods should have this video |
0c1cbbfe C |
188 | async.each(servers, function (server, callback) { |
189 | utils.getVideosList(server.url, function (err, res) { | |
9f10b292 C |
190 | if (err) throw err |
191 | ||
f0f5567b | 192 | const videos = res.body |
9f10b292 C |
193 | expect(videos).to.be.an('array') |
194 | expect(videos.length).to.equal(4) | |
3a8a8b51 | 195 | |
cbe2f7c3 C |
196 | // We not sure about the order of the two last uploads |
197 | let video1 = null | |
198 | let video2 = null | |
199 | if (videos[2].name === 'my super name for pod 3') { | |
200 | video1 = videos[2] | |
201 | video2 = videos[3] | |
202 | } else { | |
203 | video1 = videos[3] | |
204 | video2 = videos[2] | |
205 | } | |
206 | ||
6d8ada5f C |
207 | expect(video1.name).to.equal('my super name for pod 3') |
208 | expect(video1.description).to.equal('my super description for pod 3') | |
209 | expect(video1.podUrl).to.equal('http://localhost:9003') | |
210 | expect(video1.magnetUri).to.exist | |
3a8a8b51 | 211 | expect(video1.duration).to.equal(5) |
6d8ada5f | 212 | |
6d8ada5f C |
213 | expect(video2.name).to.equal('my super name for pod 3-2') |
214 | expect(video2.description).to.equal('my super description for pod 3-2') | |
215 | expect(video2.podUrl).to.equal('http://localhost:9003') | |
216 | expect(video2.magnetUri).to.exist | |
3a8a8b51 | 217 | expect(video2.duration).to.equal(5) |
6d8ada5f C |
218 | |
219 | if (server.url !== 'http://localhost:9003') { | |
220 | expect(video1.isLocal).to.be.false | |
221 | expect(video2.isLocal).to.be.false | |
222 | } else { | |
223 | expect(video1.isLocal).to.be.true | |
224 | expect(video2.isLocal).to.be.true | |
225 | } | |
9f10b292 C |
226 | |
227 | // All pods should have the same magnet Uri | |
228 | if (base_magnet === null) { | |
6d8ada5f | 229 | base_magnet = video2.magnetUri |
9f10b292 | 230 | } else { |
6d8ada5f | 231 | expect(video2.magnetUri).to.equal.magnetUri |
9f10b292 C |
232 | } |
233 | ||
234 | callback() | |
235 | }) | |
236 | }, done) | |
237 | } | |
238 | ) | |
8c308c2b | 239 | }) |
9f10b292 | 240 | }) |
8c308c2b | 241 | |
9f10b292 C |
242 | describe('Should seed the uploaded video', function () { |
243 | it('Should add the file 1 by asking pod 3', function (done) { | |
244 | // Yes, this could be long | |
245 | this.timeout(200000) | |
8c308c2b | 246 | |
0c1cbbfe | 247 | utils.getVideosList(servers[2].url, function (err, res) { |
9f10b292 | 248 | if (err) throw err |
8c308c2b | 249 | |
f0f5567b | 250 | const video = res.body[0] |
2df82d42 C |
251 | to_remove.push(res.body[2].id) |
252 | to_remove.push(res.body[3].id) | |
8c308c2b | 253 | |
9f10b292 C |
254 | webtorrent.add(video.magnetUri, function (torrent) { |
255 | expect(torrent.files).to.exist | |
256 | expect(torrent.files.length).to.equal(1) | |
257 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
8c308c2b | 258 | |
9f10b292 C |
259 | done() |
260 | }) | |
8c308c2b C |
261 | }) |
262 | }) | |
263 | ||
9f10b292 C |
264 | it('Should add the file 2 by asking pod 1', function (done) { |
265 | // Yes, this could be long | |
266 | this.timeout(200000) | |
8c308c2b | 267 | |
0c1cbbfe | 268 | utils.getVideosList(servers[0].url, function (err, res) { |
9f10b292 | 269 | if (err) throw err |
8c308c2b | 270 | |
f0f5567b | 271 | const video = res.body[1] |
0b697522 | 272 | |
9f10b292 C |
273 | webtorrent.add(video.magnetUri, function (torrent) { |
274 | expect(torrent.files).to.exist | |
275 | expect(torrent.files.length).to.equal(1) | |
276 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
8c308c2b | 277 | |
9f10b292 | 278 | done() |
8c308c2b C |
279 | }) |
280 | }) | |
9f10b292 | 281 | }) |
8c308c2b | 282 | |
9f10b292 C |
283 | it('Should add the file 3 by asking pod 2', function (done) { |
284 | // Yes, this could be long | |
285 | this.timeout(200000) | |
8c308c2b | 286 | |
0c1cbbfe | 287 | utils.getVideosList(servers[1].url, function (err, res) { |
9f10b292 | 288 | if (err) throw err |
8c308c2b | 289 | |
f0f5567b | 290 | const video = res.body[2] |
8c308c2b | 291 | |
9f10b292 C |
292 | webtorrent.add(video.magnetUri, function (torrent) { |
293 | expect(torrent.files).to.exist | |
294 | expect(torrent.files.length).to.equal(1) | |
295 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
8c308c2b | 296 | |
9f10b292 | 297 | done() |
8c308c2b C |
298 | }) |
299 | }) | |
9f10b292 | 300 | }) |
8c308c2b | 301 | |
9f10b292 C |
302 | it('Should add the file 3-2 by asking pod 1', function (done) { |
303 | // Yes, this could be long | |
304 | this.timeout(200000) | |
8c308c2b | 305 | |
0c1cbbfe | 306 | utils.getVideosList(servers[0].url, function (err, res) { |
9f10b292 | 307 | if (err) throw err |
8c308c2b | 308 | |
f0f5567b | 309 | const video = res.body[3] |
8c308c2b | 310 | |
9f10b292 C |
311 | webtorrent.add(video.magnetUri, function (torrent) { |
312 | expect(torrent.files).to.exist | |
313 | expect(torrent.files.length).to.equal(1) | |
314 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
8c308c2b | 315 | |
9f10b292 | 316 | done() |
8c308c2b C |
317 | }) |
318 | }) | |
9f10b292 | 319 | }) |
8c308c2b | 320 | |
9f10b292 C |
321 | it('Should remove the file 3 and 3-2 by asking pod 3', function (done) { |
322 | this.timeout(15000) | |
0b697522 | 323 | |
9f10b292 C |
324 | async.series([ |
325 | function (next) { | |
0c1cbbfe | 326 | utils.removeVideo(servers[2].url, servers[2].access_token, to_remove[0], next) |
9f10b292 C |
327 | }, |
328 | function (next) { | |
0c1cbbfe | 329 | utils.removeVideo(servers[2].url, servers[2].access_token, to_remove[1], next) |
9f10b292 C |
330 | }], |
331 | function (err) { | |
0b697522 | 332 | if (err) throw err |
9f10b292 C |
333 | setTimeout(done, 11000) |
334 | } | |
335 | ) | |
336 | }) | |
0b697522 | 337 | |
9f10b292 | 338 | it('Should have videos 1 and 3 on each pod', function (done) { |
0c1cbbfe C |
339 | async.each(servers, function (server, callback) { |
340 | utils.getVideosList(server.url, function (err, res) { | |
9f10b292 | 341 | if (err) throw err |
0b697522 | 342 | |
f0f5567b | 343 | const videos = res.body |
9f10b292 C |
344 | expect(videos).to.be.an('array') |
345 | expect(videos.length).to.equal(2) | |
2df82d42 C |
346 | expect(videos[0].id).not.to.equal(videos[1].id) |
347 | expect(videos[0].id).not.to.equal(to_remove[0]) | |
348 | expect(videos[1].id).not.to.equal(to_remove[0]) | |
349 | expect(videos[0].id).not.to.equal(to_remove[1]) | |
350 | expect(videos[1].id).not.to.equal(to_remove[1]) | |
0b697522 | 351 | |
9f10b292 | 352 | callback() |
0b697522 | 353 | }) |
9f10b292 | 354 | }, done) |
8c308c2b | 355 | }) |
9f10b292 | 356 | }) |
8c308c2b | 357 | |
9f10b292 | 358 | after(function (done) { |
0c1cbbfe C |
359 | servers.forEach(function (server) { |
360 | process.kill(-server.app.pid) | |
8c308c2b | 361 | }) |
9f10b292 C |
362 | process.kill(-webtorrent.app.pid) |
363 | ||
364 | // Keep the logs if the test failed | |
365 | if (this.ok) { | |
366 | utils.flushTests(done) | |
367 | } else { | |
368 | done() | |
369 | } | |
8c308c2b | 370 | }) |
9f10b292 | 371 | }) |