]>
Commit | Line | Data |
---|---|---|
9f10b292 C |
1 | 'use strict' |
2 | ||
f0f5567b | 3 | const chai = require('chai') |
1a42c9e2 | 4 | const each = require('async/each') |
f0f5567b | 5 | const expect = chai.expect |
1a42c9e2 | 6 | const series = require('async/series') |
7f4e7c36 C |
7 | const WebTorrent = require('webtorrent') |
8 | const webtorrent = new WebTorrent() | |
9f10b292 | 9 | |
8d309058 C |
10 | const loginUtils = require('../utils/login') |
11 | const miscsUtils = require('../utils/miscs') | |
12 | const podsUtils = require('../utils/pods') | |
13 | const serversUtils = require('../utils/servers') | |
14 | const videosUtils = require('../utils/videos') | |
9f10b292 C |
15 | |
16 | describe('Test multiple pods', function () { | |
0c1cbbfe | 17 | let servers = [] |
bc503c2a | 18 | const toRemove = [] |
9f10b292 C |
19 | |
20 | before(function (done) { | |
21 | this.timeout(30000) | |
22 | ||
1a42c9e2 | 23 | series([ |
9f10b292 C |
24 | // Run servers |
25 | function (next) { | |
8d309058 | 26 | serversUtils.flushAndRunMultipleServers(3, function (serversRun) { |
bc503c2a | 27 | servers = serversRun |
9f10b292 C |
28 | next() |
29 | }) | |
30 | }, | |
0c1cbbfe C |
31 | // Get the access tokens |
32 | function (next) { | |
1a42c9e2 | 33 | each(servers, function (server, callbackEach) { |
8d309058 | 34 | loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { |
bc503c2a | 35 | if (err) return callbackEach(err) |
0c1cbbfe | 36 | |
bc503c2a C |
37 | server.accessToken = accessToken |
38 | callbackEach() | |
0c1cbbfe C |
39 | }) |
40 | }, next) | |
41 | }, | |
9f10b292 C |
42 | // The second pod make friend with the third |
43 | function (next) { | |
b3b92647 | 44 | const server = servers[1] |
8d309058 | 45 | podsUtils.makeFriends(server.url, server.accessToken, next) |
9f10b292 C |
46 | }, |
47 | // Wait for the request between pods | |
48 | function (next) { | |
49 | setTimeout(next, 10000) | |
50 | }, | |
51 | // Pod 1 make friends too | |
52 | function (next) { | |
b3b92647 | 53 | const server = servers[0] |
8d309058 | 54 | podsUtils.makeFriends(server.url, server.accessToken, next) |
9f10b292 C |
55 | } |
56 | ], done) | |
57 | }) | |
8c308c2b | 58 | |
9f10b292 | 59 | it('Should not have videos for all pods', function (done) { |
1a42c9e2 | 60 | each(servers, function (server, callback) { |
8d309058 | 61 | videosUtils.getVideosList(server.url, function (err, res) { |
9f10b292 | 62 | if (err) throw err |
8c308c2b | 63 | |
68ce3ae0 C |
64 | const videos = res.body.data |
65 | expect(videos).to.be.an('array') | |
66 | expect(videos.length).to.equal(0) | |
8c308c2b | 67 | |
9f10b292 C |
68 | callback() |
69 | }) | |
70 | }, done) | |
71 | }) | |
8c308c2b | 72 | |
9f10b292 C |
73 | describe('Should upload the video and propagate on each pod', function () { |
74 | it('Should upload the video on pod 1 and propagate on each pod', function (done) { | |
75 | this.timeout(15000) | |
8c308c2b | 76 | |
1a42c9e2 | 77 | series([ |
ee66c593 | 78 | function (next) { |
be587647 C |
79 | const name = 'my super name for pod 1' |
80 | const description = 'my super description for pod 1' | |
81 | const tags = [ 'tag1p1', 'tag2p1' ] | |
82 | const file = 'video_short1.webm' | |
8d309058 | 83 | videosUtils.uploadVideo(servers[0].url, servers[0].accessToken, name, description, tags, file, next) |
ee66c593 | 84 | }, |
ee66c593 | 85 | function (next) { |
9f10b292 C |
86 | setTimeout(next, 11000) |
87 | }], | |
88 | // All pods should have this video | |
89 | function (err) { | |
90 | if (err) throw err | |
91 | ||
1a42c9e2 | 92 | each(servers, function (server, callback) { |
bc503c2a | 93 | let baseMagnet = null |
9f10b292 | 94 | |
8d309058 | 95 | videosUtils.getVideosList(server.url, function (err, res) { |
9f10b292 C |
96 | if (err) throw err |
97 | ||
68ce3ae0 | 98 | const videos = res.body.data |
9f10b292 C |
99 | expect(videos).to.be.an('array') |
100 | expect(videos.length).to.equal(1) | |
f0f5567b | 101 | const video = videos[0] |
9f10b292 C |
102 | expect(video.name).to.equal('my super name for pod 1') |
103 | expect(video.description).to.equal('my super description for pod 1') | |
a4254ea1 | 104 | expect(video.podHost).to.equal('localhost:9001') |
9f10b292 | 105 | expect(video.magnetUri).to.exist |
3a8a8b51 | 106 | expect(video.duration).to.equal(10) |
be587647 | 107 | expect(video.tags).to.deep.equal([ 'tag1p1', 'tag2p1' ]) |
feb4bdfd | 108 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true |
79066fdf | 109 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true |
528a9efa | 110 | expect(video.author).to.equal('root') |
9f10b292 | 111 | |
6d8ada5f C |
112 | if (server.url !== 'http://localhost:9001') { |
113 | expect(video.isLocal).to.be.false | |
114 | } else { | |
115 | expect(video.isLocal).to.be.true | |
116 | } | |
117 | ||
9f10b292 | 118 | // All pods should have the same magnet Uri |
bc503c2a C |
119 | if (baseMagnet === null) { |
120 | baseMagnet = video.magnetUri | |
9f10b292 C |
121 | } else { |
122 | expect(video.magnetUri).to.equal.magnetUri | |
123 | } | |
124 | ||
8d309058 | 125 | videosUtils.testVideoImage(server.url, 'video_short1.webm', video.thumbnailPath, function (err, test) { |
9e5f3740 C |
126 | if (err) throw err |
127 | expect(test).to.equal(true) | |
128 | ||
129 | callback() | |
130 | }) | |
9f10b292 C |
131 | }) |
132 | }, done) | |
133 | } | |
134 | ) | |
135 | }) | |
136 | ||
137 | it('Should upload the video on pod 2 and propagate on each pod', function (done) { | |
138 | this.timeout(15000) | |
139 | ||
1a42c9e2 | 140 | series([ |
ee66c593 | 141 | function (next) { |
be587647 C |
142 | const name = 'my super name for pod 2' |
143 | const description = 'my super description for pod 2' | |
144 | const tags = [ 'tag1p2', 'tag2p2', 'tag3p2' ] | |
145 | const file = 'video_short2.webm' | |
8d309058 | 146 | videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, name, description, tags, file, next) |
ee66c593 C |
147 | }, |
148 | function (next) { | |
9f10b292 C |
149 | setTimeout(next, 11000) |
150 | }], | |
151 | // All pods should have this video | |
152 | function (err) { | |
153 | if (err) throw err | |
154 | ||
1a42c9e2 | 155 | each(servers, function (server, callback) { |
bc503c2a | 156 | let baseMagnet = null |
9f10b292 | 157 | |
8d309058 | 158 | videosUtils.getVideosList(server.url, function (err, res) { |
9f10b292 C |
159 | if (err) throw err |
160 | ||
68ce3ae0 | 161 | const videos = res.body.data |
9f10b292 C |
162 | expect(videos).to.be.an('array') |
163 | expect(videos.length).to.equal(2) | |
f0f5567b | 164 | const video = videos[1] |
9f10b292 C |
165 | expect(video.name).to.equal('my super name for pod 2') |
166 | expect(video.description).to.equal('my super description for pod 2') | |
a4254ea1 | 167 | expect(video.podHost).to.equal('localhost:9002') |
9f10b292 | 168 | expect(video.magnetUri).to.exist |
3a8a8b51 | 169 | expect(video.duration).to.equal(5) |
be587647 | 170 | expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ]) |
feb4bdfd | 171 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true |
79066fdf | 172 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true |
528a9efa | 173 | expect(video.author).to.equal('root') |
9f10b292 | 174 | |
6d8ada5f C |
175 | if (server.url !== 'http://localhost:9002') { |
176 | expect(video.isLocal).to.be.false | |
177 | } else { | |
178 | expect(video.isLocal).to.be.true | |
179 | } | |
180 | ||
9f10b292 | 181 | // All pods should have the same magnet Uri |
bc503c2a C |
182 | if (baseMagnet === null) { |
183 | baseMagnet = video.magnetUri | |
9f10b292 C |
184 | } else { |
185 | expect(video.magnetUri).to.equal.magnetUri | |
186 | } | |
187 | ||
8d309058 | 188 | videosUtils.testVideoImage(server.url, 'video_short2.webm', video.thumbnailPath, function (err, test) { |
9e5f3740 C |
189 | if (err) throw err |
190 | expect(test).to.equal(true) | |
191 | ||
192 | callback() | |
193 | }) | |
9f10b292 C |
194 | }) |
195 | }, done) | |
ee66c593 | 196 | } |
9f10b292 | 197 | ) |
8c308c2b C |
198 | }) |
199 | ||
9f10b292 C |
200 | it('Should upload two videos on pod 3 and propagate on each pod', function (done) { |
201 | this.timeout(30000) | |
8c308c2b | 202 | |
1a42c9e2 | 203 | series([ |
9f10b292 | 204 | function (next) { |
be587647 C |
205 | const name = 'my super name for pod 3' |
206 | const description = 'my super description for pod 3' | |
207 | const tags = [ 'tag1p3' ] | |
208 | const file = 'video_short3.webm' | |
8d309058 | 209 | videosUtils.uploadVideo(servers[2].url, servers[2].accessToken, name, description, tags, file, next) |
9f10b292 C |
210 | }, |
211 | function (next) { | |
be587647 C |
212 | const name = 'my super name for pod 3-2' |
213 | const description = 'my super description for pod 3-2' | |
214 | const tags = [ 'tag2p3', 'tag3p3', 'tag4p3' ] | |
215 | const file = 'video_short.webm' | |
8d309058 | 216 | videosUtils.uploadVideo(servers[2].url, servers[2].accessToken, name, description, tags, file, next) |
9f10b292 C |
217 | }, |
218 | function (next) { | |
219 | setTimeout(next, 22000) | |
220 | }], | |
221 | function (err) { | |
222 | if (err) throw err | |
8c308c2b | 223 | |
bc503c2a | 224 | let baseMagnet = null |
9f10b292 | 225 | // All pods should have this video |
1a42c9e2 | 226 | each(servers, function (server, callback) { |
8d309058 | 227 | videosUtils.getVideosList(server.url, function (err, res) { |
9f10b292 C |
228 | if (err) throw err |
229 | ||
68ce3ae0 | 230 | const videos = res.body.data |
9f10b292 C |
231 | expect(videos).to.be.an('array') |
232 | expect(videos.length).to.equal(4) | |
3a8a8b51 | 233 | |
cbe2f7c3 C |
234 | // We not sure about the order of the two last uploads |
235 | let video1 = null | |
236 | let video2 = null | |
237 | if (videos[2].name === 'my super name for pod 3') { | |
238 | video1 = videos[2] | |
239 | video2 = videos[3] | |
240 | } else { | |
241 | video1 = videos[3] | |
242 | video2 = videos[2] | |
243 | } | |
244 | ||
6d8ada5f C |
245 | expect(video1.name).to.equal('my super name for pod 3') |
246 | expect(video1.description).to.equal('my super description for pod 3') | |
a4254ea1 | 247 | expect(video1.podHost).to.equal('localhost:9003') |
6d8ada5f | 248 | expect(video1.magnetUri).to.exist |
3a8a8b51 | 249 | expect(video1.duration).to.equal(5) |
be587647 | 250 | expect(video1.tags).to.deep.equal([ 'tag1p3' ]) |
528a9efa | 251 | expect(video1.author).to.equal('root') |
feb4bdfd | 252 | expect(miscsUtils.dateIsValid(video1.createdAt)).to.be.true |
79066fdf | 253 | expect(miscsUtils.dateIsValid(video1.updatedAt)).to.be.true |
6d8ada5f | 254 | |
6d8ada5f C |
255 | expect(video2.name).to.equal('my super name for pod 3-2') |
256 | expect(video2.description).to.equal('my super description for pod 3-2') | |
a4254ea1 | 257 | expect(video2.podHost).to.equal('localhost:9003') |
6d8ada5f | 258 | expect(video2.magnetUri).to.exist |
3a8a8b51 | 259 | expect(video2.duration).to.equal(5) |
be587647 | 260 | expect(video2.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ]) |
528a9efa | 261 | expect(video2.author).to.equal('root') |
feb4bdfd | 262 | expect(miscsUtils.dateIsValid(video2.createdAt)).to.be.true |
79066fdf | 263 | expect(miscsUtils.dateIsValid(video2.updatedAt)).to.be.true |
6d8ada5f C |
264 | |
265 | if (server.url !== 'http://localhost:9003') { | |
266 | expect(video1.isLocal).to.be.false | |
267 | expect(video2.isLocal).to.be.false | |
268 | } else { | |
269 | expect(video1.isLocal).to.be.true | |
270 | expect(video2.isLocal).to.be.true | |
271 | } | |
9f10b292 C |
272 | |
273 | // All pods should have the same magnet Uri | |
bc503c2a C |
274 | if (baseMagnet === null) { |
275 | baseMagnet = video2.magnetUri | |
9f10b292 | 276 | } else { |
6d8ada5f | 277 | expect(video2.magnetUri).to.equal.magnetUri |
9f10b292 C |
278 | } |
279 | ||
8d309058 | 280 | videosUtils.testVideoImage(server.url, 'video_short3.webm', video1.thumbnailPath, function (err, test) { |
9e5f3740 C |
281 | if (err) throw err |
282 | expect(test).to.equal(true) | |
283 | ||
8d309058 | 284 | videosUtils.testVideoImage(server.url, 'video_short.webm', video2.thumbnailPath, function (err, test) { |
9e5f3740 C |
285 | if (err) throw err |
286 | expect(test).to.equal(true) | |
287 | ||
288 | callback() | |
289 | }) | |
290 | }) | |
9f10b292 C |
291 | }) |
292 | }, done) | |
293 | } | |
294 | ) | |
8c308c2b | 295 | }) |
9f10b292 | 296 | }) |
8c308c2b | 297 | |
9f10b292 C |
298 | describe('Should seed the uploaded video', function () { |
299 | it('Should add the file 1 by asking pod 3', function (done) { | |
300 | // Yes, this could be long | |
301 | this.timeout(200000) | |
8c308c2b | 302 | |
8d309058 | 303 | videosUtils.getVideosList(servers[2].url, function (err, res) { |
9f10b292 | 304 | if (err) throw err |
8c308c2b | 305 | |
68ce3ae0 | 306 | const video = res.body.data[0] |
3d118fb5 C |
307 | toRemove.push(res.body.data[2]) |
308 | toRemove.push(res.body.data[3]) | |
8c308c2b | 309 | |
9f10b292 C |
310 | webtorrent.add(video.magnetUri, function (torrent) { |
311 | expect(torrent.files).to.exist | |
312 | expect(torrent.files.length).to.equal(1) | |
313 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
8c308c2b | 314 | |
790e65fc | 315 | done() |
9f10b292 | 316 | }) |
8c308c2b C |
317 | }) |
318 | }) | |
319 | ||
9f10b292 C |
320 | it('Should add the file 2 by asking pod 1', function (done) { |
321 | // Yes, this could be long | |
322 | this.timeout(200000) | |
8c308c2b | 323 | |
8d309058 | 324 | videosUtils.getVideosList(servers[0].url, function (err, res) { |
9f10b292 | 325 | if (err) throw err |
8c308c2b | 326 | |
68ce3ae0 | 327 | const video = res.body.data[1] |
0b697522 | 328 | |
9f10b292 C |
329 | webtorrent.add(video.magnetUri, function (torrent) { |
330 | expect(torrent.files).to.exist | |
331 | expect(torrent.files.length).to.equal(1) | |
332 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
8c308c2b | 333 | |
790e65fc | 334 | done() |
8c308c2b C |
335 | }) |
336 | }) | |
9f10b292 | 337 | }) |
8c308c2b | 338 | |
9f10b292 C |
339 | it('Should add the file 3 by asking pod 2', function (done) { |
340 | // Yes, this could be long | |
341 | this.timeout(200000) | |
8c308c2b | 342 | |
8d309058 | 343 | videosUtils.getVideosList(servers[1].url, function (err, res) { |
9f10b292 | 344 | if (err) throw err |
8c308c2b | 345 | |
68ce3ae0 | 346 | const video = res.body.data[2] |
8c308c2b | 347 | |
9f10b292 C |
348 | webtorrent.add(video.magnetUri, function (torrent) { |
349 | expect(torrent.files).to.exist | |
350 | expect(torrent.files.length).to.equal(1) | |
351 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
8c308c2b | 352 | |
790e65fc | 353 | done() |
8c308c2b C |
354 | }) |
355 | }) | |
9f10b292 | 356 | }) |
8c308c2b | 357 | |
9f10b292 C |
358 | it('Should add the file 3-2 by asking pod 1', function (done) { |
359 | // Yes, this could be long | |
360 | this.timeout(200000) | |
8c308c2b | 361 | |
8d309058 | 362 | videosUtils.getVideosList(servers[0].url, function (err, res) { |
9f10b292 | 363 | if (err) throw err |
8c308c2b | 364 | |
68ce3ae0 | 365 | const video = res.body.data[3] |
8c308c2b | 366 | |
9f10b292 C |
367 | webtorrent.add(video.magnetUri, function (torrent) { |
368 | expect(torrent.files).to.exist | |
369 | expect(torrent.files.length).to.equal(1) | |
370 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
8c308c2b | 371 | |
790e65fc | 372 | done() |
8c308c2b C |
373 | }) |
374 | }) | |
9f10b292 | 375 | }) |
3d118fb5 C |
376 | }) |
377 | ||
378 | describe('Should manipulate these videos', function () { | |
379 | it('Should update the video 3 by asking pod 3', function (done) { | |
380 | this.timeout(15000) | |
381 | ||
382 | const name = 'my super video updated' | |
383 | const description = 'my super description updated' | |
384 | const tags = [ 'tagup1', 'tagup2' ] | |
385 | ||
386 | videosUtils.updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, name, description, tags, function (err) { | |
387 | if (err) throw err | |
388 | ||
389 | setTimeout(done, 11000) | |
390 | }) | |
391 | }) | |
392 | ||
393 | it('Should have the video 3 updated on each pod', function (done) { | |
7f4e7c36 C |
394 | this.timeout(200000) |
395 | ||
3d118fb5 | 396 | each(servers, function (server, callback) { |
7f4e7c36 C |
397 | // Avoid "duplicate torrent" errors |
398 | const webtorrent = new WebTorrent() | |
399 | ||
3d118fb5 C |
400 | videosUtils.getVideosList(server.url, function (err, res) { |
401 | if (err) throw err | |
402 | ||
403 | const videos = res.body.data | |
404 | const videoUpdated = videos.find(function (video) { | |
405 | return video.name === 'my super video updated' | |
406 | }) | |
407 | ||
408 | expect(!!videoUpdated).to.be.true | |
409 | expect(videoUpdated.description).to.equal('my super description updated') | |
410 | expect(videoUpdated.tags).to.deep.equal([ 'tagup1', 'tagup2' ]) | |
79066fdf | 411 | expect(miscsUtils.dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true |
3d118fb5 | 412 | |
7f4e7c36 C |
413 | videosUtils.testVideoImage(server.url, 'video_short3.webm', videoUpdated.thumbnailPath, function (err, test) { |
414 | if (err) throw err | |
415 | expect(test).to.equal(true) | |
416 | ||
417 | webtorrent.add(videoUpdated.magnetUri, function (torrent) { | |
418 | expect(torrent.files).to.exist | |
419 | expect(torrent.files.length).to.equal(1) | |
420 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
421 | ||
790e65fc | 422 | callback() |
7f4e7c36 C |
423 | }) |
424 | }) | |
3d118fb5 C |
425 | }) |
426 | }, done) | |
427 | }) | |
8c308c2b | 428 | |
3d118fb5 | 429 | it('Should remove the videos 3 and 3-2 by asking pod 3', function (done) { |
9f10b292 | 430 | this.timeout(15000) |
0b697522 | 431 | |
1a42c9e2 | 432 | series([ |
9f10b292 | 433 | function (next) { |
3d118fb5 | 434 | videosUtils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, next) |
9f10b292 C |
435 | }, |
436 | function (next) { | |
3d118fb5 | 437 | videosUtils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id, next) |
9f10b292 C |
438 | }], |
439 | function (err) { | |
0b697522 | 440 | if (err) throw err |
9f10b292 C |
441 | setTimeout(done, 11000) |
442 | } | |
443 | ) | |
444 | }) | |
0b697522 | 445 | |
9f10b292 | 446 | it('Should have videos 1 and 3 on each pod', function (done) { |
1a42c9e2 | 447 | each(servers, function (server, callback) { |
8d309058 | 448 | videosUtils.getVideosList(server.url, function (err, res) { |
9f10b292 | 449 | if (err) throw err |
0b697522 | 450 | |
68ce3ae0 | 451 | const videos = res.body.data |
9f10b292 C |
452 | expect(videos).to.be.an('array') |
453 | expect(videos.length).to.equal(2) | |
3d118fb5 C |
454 | expect(videos[0].name).not.to.equal(videos[1].name) |
455 | expect(videos[0].name).not.to.equal(toRemove[0].name) | |
456 | expect(videos[1].name).not.to.equal(toRemove[0].name) | |
457 | expect(videos[0].name).not.to.equal(toRemove[1].name) | |
458 | expect(videos[1].name).not.to.equal(toRemove[1].name) | |
0b697522 | 459 | |
9f10b292 | 460 | callback() |
0b697522 | 461 | }) |
9f10b292 | 462 | }, done) |
8c308c2b | 463 | }) |
9f10b292 | 464 | }) |
8c308c2b | 465 | |
9f10b292 | 466 | after(function (done) { |
0c1cbbfe C |
467 | servers.forEach(function (server) { |
468 | process.kill(-server.app.pid) | |
8c308c2b | 469 | }) |
9f10b292 C |
470 | |
471 | // Keep the logs if the test failed | |
472 | if (this.ok) { | |
8d309058 | 473 | serversUtils.flushTests(done) |
9f10b292 C |
474 | } else { |
475 | done() | |
476 | } | |
8c308c2b | 477 | }) |
9f10b292 | 478 | }) |