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