]>
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 = [] |
bc503c2a | 14 | const toRemove = [] |
9f10b292 C |
15 | |
16 | before(function (done) { | |
17 | this.timeout(30000) | |
18 | ||
19 | async.series([ | |
20 | // Run servers | |
21 | function (next) { | |
bc503c2a C |
22 | utils.flushAndRunMultipleServers(3, function (serversRun) { |
23 | servers = serversRun | |
9f10b292 C |
24 | next() |
25 | }) | |
26 | }, | |
0c1cbbfe C |
27 | // Get the access tokens |
28 | function (next) { | |
bc503c2a C |
29 | async.each(servers, function (server, callbackEach) { |
30 | utils.loginAndGetAccessToken(server, function (err, accessToken) { | |
31 | if (err) return callbackEach(err) | |
0c1cbbfe | 32 | |
bc503c2a C |
33 | server.accessToken = accessToken |
34 | callbackEach() | |
0c1cbbfe C |
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) { |
b6c6f935 | 75 | utils.uploadVideo(servers[0].url, servers[0].accessToken, '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) { |
bc503c2a | 85 | let baseMagnet = 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 | 106 | // All pods should have the same magnet Uri |
bc503c2a C |
107 | if (baseMagnet === null) { |
108 | baseMagnet = video.magnetUri | |
9f10b292 C |
109 | } else { |
110 | expect(video.magnetUri).to.equal.magnetUri | |
111 | } | |
112 | ||
36d56024 | 113 | utils.testImage(server.url, 'video_short1.webm', video.thumbnailPath, function (err, test) { |
9e5f3740 C |
114 | if (err) throw err |
115 | expect(test).to.equal(true) | |
116 | ||
117 | callback() | |
118 | }) | |
9f10b292 C |
119 | }) |
120 | }, done) | |
121 | } | |
122 | ) | |
123 | }) | |
124 | ||
125 | it('Should upload the video on pod 2 and propagate on each pod', function (done) { | |
126 | this.timeout(15000) | |
127 | ||
128 | async.series([ | |
ee66c593 | 129 | function (next) { |
b6c6f935 | 130 | utils.uploadVideo(servers[1].url, servers[1].accessToken, 'my super name for pod 2', 'my super description for pod 2', 'video_short2.webm', next) |
ee66c593 C |
131 | }, |
132 | function (next) { | |
9f10b292 C |
133 | setTimeout(next, 11000) |
134 | }], | |
135 | // All pods should have this video | |
136 | function (err) { | |
137 | if (err) throw err | |
138 | ||
0c1cbbfe | 139 | async.each(servers, function (server, callback) { |
bc503c2a | 140 | let baseMagnet = null |
9f10b292 | 141 | |
0c1cbbfe | 142 | utils.getVideosList(server.url, function (err, res) { |
9f10b292 C |
143 | if (err) throw err |
144 | ||
f0f5567b | 145 | const videos = res.body |
9f10b292 C |
146 | expect(videos).to.be.an('array') |
147 | expect(videos.length).to.equal(2) | |
f0f5567b | 148 | const video = videos[1] |
9f10b292 C |
149 | expect(video.name).to.equal('my super name for pod 2') |
150 | expect(video.description).to.equal('my super description for pod 2') | |
151 | expect(video.podUrl).to.equal('http://localhost:9002') | |
152 | expect(video.magnetUri).to.exist | |
3a8a8b51 | 153 | expect(video.duration).to.equal(5) |
9f10b292 | 154 | |
6d8ada5f C |
155 | if (server.url !== 'http://localhost:9002') { |
156 | expect(video.isLocal).to.be.false | |
157 | } else { | |
158 | expect(video.isLocal).to.be.true | |
159 | } | |
160 | ||
9f10b292 | 161 | // All pods should have the same magnet Uri |
bc503c2a C |
162 | if (baseMagnet === null) { |
163 | baseMagnet = video.magnetUri | |
9f10b292 C |
164 | } else { |
165 | expect(video.magnetUri).to.equal.magnetUri | |
166 | } | |
167 | ||
36d56024 | 168 | utils.testImage(server.url, 'video_short2.webm', video.thumbnailPath, function (err, test) { |
9e5f3740 C |
169 | if (err) throw err |
170 | expect(test).to.equal(true) | |
171 | ||
172 | callback() | |
173 | }) | |
9f10b292 C |
174 | }) |
175 | }, done) | |
ee66c593 | 176 | } |
9f10b292 | 177 | ) |
8c308c2b C |
178 | }) |
179 | ||
9f10b292 C |
180 | it('Should upload two videos on pod 3 and propagate on each pod', function (done) { |
181 | this.timeout(30000) | |
8c308c2b | 182 | |
9f10b292 C |
183 | async.series([ |
184 | function (next) { | |
b6c6f935 | 185 | utils.uploadVideo(servers[2].url, servers[2].accessToken, 'my super name for pod 3', 'my super description for pod 3', 'video_short3.webm', next) |
9f10b292 C |
186 | }, |
187 | function (next) { | |
b6c6f935 | 188 | utils.uploadVideo(servers[2].url, servers[2].accessToken, 'my super name for pod 3-2', 'my super description for pod 3-2', 'video_short.webm', next) |
9f10b292 C |
189 | }, |
190 | function (next) { | |
191 | setTimeout(next, 22000) | |
192 | }], | |
193 | function (err) { | |
194 | if (err) throw err | |
8c308c2b | 195 | |
bc503c2a | 196 | let baseMagnet = null |
9f10b292 | 197 | // All pods should have this video |
0c1cbbfe C |
198 | async.each(servers, function (server, callback) { |
199 | utils.getVideosList(server.url, function (err, res) { | |
9f10b292 C |
200 | if (err) throw err |
201 | ||
f0f5567b | 202 | const videos = res.body |
9f10b292 C |
203 | expect(videos).to.be.an('array') |
204 | expect(videos.length).to.equal(4) | |
3a8a8b51 | 205 | |
cbe2f7c3 C |
206 | // We not sure about the order of the two last uploads |
207 | let video1 = null | |
208 | let video2 = null | |
209 | if (videos[2].name === 'my super name for pod 3') { | |
210 | video1 = videos[2] | |
211 | video2 = videos[3] | |
212 | } else { | |
213 | video1 = videos[3] | |
214 | video2 = videos[2] | |
215 | } | |
216 | ||
6d8ada5f C |
217 | expect(video1.name).to.equal('my super name for pod 3') |
218 | expect(video1.description).to.equal('my super description for pod 3') | |
219 | expect(video1.podUrl).to.equal('http://localhost:9003') | |
220 | expect(video1.magnetUri).to.exist | |
3a8a8b51 | 221 | expect(video1.duration).to.equal(5) |
6d8ada5f | 222 | |
6d8ada5f C |
223 | expect(video2.name).to.equal('my super name for pod 3-2') |
224 | expect(video2.description).to.equal('my super description for pod 3-2') | |
225 | expect(video2.podUrl).to.equal('http://localhost:9003') | |
226 | expect(video2.magnetUri).to.exist | |
3a8a8b51 | 227 | expect(video2.duration).to.equal(5) |
6d8ada5f C |
228 | |
229 | if (server.url !== 'http://localhost:9003') { | |
230 | expect(video1.isLocal).to.be.false | |
231 | expect(video2.isLocal).to.be.false | |
232 | } else { | |
233 | expect(video1.isLocal).to.be.true | |
234 | expect(video2.isLocal).to.be.true | |
235 | } | |
9f10b292 C |
236 | |
237 | // All pods should have the same magnet Uri | |
bc503c2a C |
238 | if (baseMagnet === null) { |
239 | baseMagnet = video2.magnetUri | |
9f10b292 | 240 | } else { |
6d8ada5f | 241 | expect(video2.magnetUri).to.equal.magnetUri |
9f10b292 C |
242 | } |
243 | ||
36d56024 | 244 | utils.testImage(server.url, 'video_short3.webm', video1.thumbnailPath, function (err, test) { |
9e5f3740 C |
245 | if (err) throw err |
246 | expect(test).to.equal(true) | |
247 | ||
36d56024 | 248 | utils.testImage(server.url, 'video_short.webm', video2.thumbnailPath, function (err, test) { |
9e5f3740 C |
249 | if (err) throw err |
250 | expect(test).to.equal(true) | |
251 | ||
252 | callback() | |
253 | }) | |
254 | }) | |
9f10b292 C |
255 | }) |
256 | }, done) | |
257 | } | |
258 | ) | |
8c308c2b | 259 | }) |
9f10b292 | 260 | }) |
8c308c2b | 261 | |
9f10b292 C |
262 | describe('Should seed the uploaded video', function () { |
263 | it('Should add the file 1 by asking pod 3', function (done) { | |
264 | // Yes, this could be long | |
265 | this.timeout(200000) | |
8c308c2b | 266 | |
0c1cbbfe | 267 | utils.getVideosList(servers[2].url, function (err, res) { |
9f10b292 | 268 | if (err) throw err |
8c308c2b | 269 | |
f0f5567b | 270 | const video = res.body[0] |
bc503c2a C |
271 | toRemove.push(res.body[2].id) |
272 | toRemove.push(res.body[3].id) | |
8c308c2b | 273 | |
9f10b292 C |
274 | webtorrent.add(video.magnetUri, function (torrent) { |
275 | expect(torrent.files).to.exist | |
276 | expect(torrent.files.length).to.equal(1) | |
277 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
8c308c2b | 278 | |
9f10b292 C |
279 | done() |
280 | }) | |
8c308c2b C |
281 | }) |
282 | }) | |
283 | ||
9f10b292 C |
284 | it('Should add the file 2 by asking pod 1', function (done) { |
285 | // Yes, this could be long | |
286 | this.timeout(200000) | |
8c308c2b | 287 | |
0c1cbbfe | 288 | utils.getVideosList(servers[0].url, function (err, res) { |
9f10b292 | 289 | if (err) throw err |
8c308c2b | 290 | |
f0f5567b | 291 | const video = res.body[1] |
0b697522 | 292 | |
9f10b292 C |
293 | webtorrent.add(video.magnetUri, function (torrent) { |
294 | expect(torrent.files).to.exist | |
295 | expect(torrent.files.length).to.equal(1) | |
296 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
8c308c2b | 297 | |
9f10b292 | 298 | done() |
8c308c2b C |
299 | }) |
300 | }) | |
9f10b292 | 301 | }) |
8c308c2b | 302 | |
9f10b292 C |
303 | it('Should add the file 3 by asking pod 2', function (done) { |
304 | // Yes, this could be long | |
305 | this.timeout(200000) | |
8c308c2b | 306 | |
0c1cbbfe | 307 | utils.getVideosList(servers[1].url, function (err, res) { |
9f10b292 | 308 | if (err) throw err |
8c308c2b | 309 | |
f0f5567b | 310 | const video = res.body[2] |
8c308c2b | 311 | |
9f10b292 C |
312 | webtorrent.add(video.magnetUri, function (torrent) { |
313 | expect(torrent.files).to.exist | |
314 | expect(torrent.files.length).to.equal(1) | |
315 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
8c308c2b | 316 | |
9f10b292 | 317 | done() |
8c308c2b C |
318 | }) |
319 | }) | |
9f10b292 | 320 | }) |
8c308c2b | 321 | |
9f10b292 C |
322 | it('Should add the file 3-2 by asking pod 1', function (done) { |
323 | // Yes, this could be long | |
324 | this.timeout(200000) | |
8c308c2b | 325 | |
0c1cbbfe | 326 | utils.getVideosList(servers[0].url, function (err, res) { |
9f10b292 | 327 | if (err) throw err |
8c308c2b | 328 | |
f0f5567b | 329 | const video = res.body[3] |
8c308c2b | 330 | |
9f10b292 C |
331 | webtorrent.add(video.magnetUri, function (torrent) { |
332 | expect(torrent.files).to.exist | |
333 | expect(torrent.files.length).to.equal(1) | |
334 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
8c308c2b | 335 | |
9f10b292 | 336 | done() |
8c308c2b C |
337 | }) |
338 | }) | |
9f10b292 | 339 | }) |
8c308c2b | 340 | |
9f10b292 C |
341 | it('Should remove the file 3 and 3-2 by asking pod 3', function (done) { |
342 | this.timeout(15000) | |
0b697522 | 343 | |
9f10b292 C |
344 | async.series([ |
345 | function (next) { | |
bc503c2a | 346 | utils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[0], next) |
9f10b292 C |
347 | }, |
348 | function (next) { | |
bc503c2a | 349 | utils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[1], next) |
9f10b292 C |
350 | }], |
351 | function (err) { | |
0b697522 | 352 | if (err) throw err |
9f10b292 C |
353 | setTimeout(done, 11000) |
354 | } | |
355 | ) | |
356 | }) | |
0b697522 | 357 | |
9f10b292 | 358 | it('Should have videos 1 and 3 on each pod', function (done) { |
0c1cbbfe C |
359 | async.each(servers, function (server, callback) { |
360 | utils.getVideosList(server.url, function (err, res) { | |
9f10b292 | 361 | if (err) throw err |
0b697522 | 362 | |
f0f5567b | 363 | const videos = res.body |
9f10b292 C |
364 | expect(videos).to.be.an('array') |
365 | expect(videos.length).to.equal(2) | |
2df82d42 | 366 | expect(videos[0].id).not.to.equal(videos[1].id) |
bc503c2a C |
367 | expect(videos[0].id).not.to.equal(toRemove[0]) |
368 | expect(videos[1].id).not.to.equal(toRemove[0]) | |
369 | expect(videos[0].id).not.to.equal(toRemove[1]) | |
370 | expect(videos[1].id).not.to.equal(toRemove[1]) | |
0b697522 | 371 | |
9f10b292 | 372 | callback() |
0b697522 | 373 | }) |
9f10b292 | 374 | }, done) |
8c308c2b | 375 | }) |
9f10b292 | 376 | }) |
8c308c2b | 377 | |
9f10b292 | 378 | after(function (done) { |
0c1cbbfe C |
379 | servers.forEach(function (server) { |
380 | process.kill(-server.app.pid) | |
8c308c2b | 381 | }) |
9f10b292 C |
382 | process.kill(-webtorrent.app.pid) |
383 | ||
384 | // Keep the logs if the test failed | |
385 | if (this.ok) { | |
386 | utils.flushTests(done) | |
387 | } else { | |
388 | done() | |
389 | } | |
8c308c2b | 390 | }) |
9f10b292 | 391 | }) |