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