]>
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 | |
98 | ||
6d8ada5f C |
99 | if (server.url !== 'http://localhost:9001') { |
100 | expect(video.isLocal).to.be.false | |
101 | } else { | |
102 | expect(video.isLocal).to.be.true | |
103 | } | |
104 | ||
9f10b292 C |
105 | // All pods should have the same magnet Uri |
106 | if (base_magnet === null) { | |
107 | base_magnet = video.magnetUri | |
108 | } else { | |
109 | expect(video.magnetUri).to.equal.magnetUri | |
110 | } | |
111 | ||
112 | callback() | |
113 | }) | |
114 | }, done) | |
115 | } | |
116 | ) | |
117 | }) | |
118 | ||
119 | it('Should upload the video on pod 2 and propagate on each pod', function (done) { | |
120 | this.timeout(15000) | |
121 | ||
122 | async.series([ | |
ee66c593 | 123 | function (next) { |
0c1cbbfe | 124 | 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 |
125 | }, |
126 | function (next) { | |
9f10b292 C |
127 | setTimeout(next, 11000) |
128 | }], | |
129 | // All pods should have this video | |
130 | function (err) { | |
131 | if (err) throw err | |
132 | ||
0c1cbbfe | 133 | async.each(servers, function (server, callback) { |
f0f5567b | 134 | let base_magnet = null |
9f10b292 | 135 | |
0c1cbbfe | 136 | utils.getVideosList(server.url, function (err, res) { |
9f10b292 C |
137 | if (err) throw err |
138 | ||
f0f5567b | 139 | const videos = res.body |
9f10b292 C |
140 | expect(videos).to.be.an('array') |
141 | expect(videos.length).to.equal(2) | |
f0f5567b | 142 | const video = videos[1] |
9f10b292 C |
143 | expect(video.name).to.equal('my super name for pod 2') |
144 | expect(video.description).to.equal('my super description for pod 2') | |
145 | expect(video.podUrl).to.equal('http://localhost:9002') | |
146 | expect(video.magnetUri).to.exist | |
147 | ||
6d8ada5f C |
148 | if (server.url !== 'http://localhost:9002') { |
149 | expect(video.isLocal).to.be.false | |
150 | } else { | |
151 | expect(video.isLocal).to.be.true | |
152 | } | |
153 | ||
9f10b292 C |
154 | // All pods should have the same magnet Uri |
155 | if (base_magnet === null) { | |
156 | base_magnet = video.magnetUri | |
157 | } else { | |
158 | expect(video.magnetUri).to.equal.magnetUri | |
159 | } | |
160 | ||
161 | callback() | |
162 | }) | |
163 | }, done) | |
ee66c593 | 164 | } |
9f10b292 | 165 | ) |
8c308c2b C |
166 | }) |
167 | ||
9f10b292 C |
168 | it('Should upload two videos on pod 3 and propagate on each pod', function (done) { |
169 | this.timeout(30000) | |
8c308c2b | 170 | |
9f10b292 C |
171 | async.series([ |
172 | function (next) { | |
0c1cbbfe | 173 | 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 |
174 | }, |
175 | function (next) { | |
0c1cbbfe | 176 | 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 |
177 | }, |
178 | function (next) { | |
179 | setTimeout(next, 22000) | |
180 | }], | |
181 | function (err) { | |
182 | if (err) throw err | |
8c308c2b | 183 | |
f0f5567b | 184 | let base_magnet = null |
9f10b292 | 185 | // All pods should have this video |
0c1cbbfe C |
186 | async.each(servers, function (server, callback) { |
187 | utils.getVideosList(server.url, function (err, res) { | |
9f10b292 C |
188 | if (err) throw err |
189 | ||
f0f5567b | 190 | const videos = res.body |
9f10b292 C |
191 | expect(videos).to.be.an('array') |
192 | expect(videos.length).to.equal(4) | |
6d8ada5f C |
193 | const video1 = videos[2] |
194 | expect(video1.name).to.equal('my super name for pod 3') | |
195 | expect(video1.description).to.equal('my super description for pod 3') | |
196 | expect(video1.podUrl).to.equal('http://localhost:9003') | |
197 | expect(video1.magnetUri).to.exist | |
198 | ||
199 | const video2 = videos[3] | |
200 | expect(video2.name).to.equal('my super name for pod 3-2') | |
201 | expect(video2.description).to.equal('my super description for pod 3-2') | |
202 | expect(video2.podUrl).to.equal('http://localhost:9003') | |
203 | expect(video2.magnetUri).to.exist | |
204 | ||
205 | if (server.url !== 'http://localhost:9003') { | |
206 | expect(video1.isLocal).to.be.false | |
207 | expect(video2.isLocal).to.be.false | |
208 | } else { | |
209 | expect(video1.isLocal).to.be.true | |
210 | expect(video2.isLocal).to.be.true | |
211 | } | |
9f10b292 C |
212 | |
213 | // All pods should have the same magnet Uri | |
214 | if (base_magnet === null) { | |
6d8ada5f | 215 | base_magnet = video2.magnetUri |
9f10b292 | 216 | } else { |
6d8ada5f | 217 | expect(video2.magnetUri).to.equal.magnetUri |
9f10b292 C |
218 | } |
219 | ||
220 | callback() | |
221 | }) | |
222 | }, done) | |
223 | } | |
224 | ) | |
8c308c2b | 225 | }) |
9f10b292 | 226 | }) |
8c308c2b | 227 | |
9f10b292 C |
228 | describe('Should seed the uploaded video', function () { |
229 | it('Should add the file 1 by asking pod 3', function (done) { | |
230 | // Yes, this could be long | |
231 | this.timeout(200000) | |
8c308c2b | 232 | |
0c1cbbfe | 233 | utils.getVideosList(servers[2].url, function (err, res) { |
9f10b292 | 234 | if (err) throw err |
8c308c2b | 235 | |
f0f5567b | 236 | const video = res.body[0] |
2df82d42 C |
237 | to_remove.push(res.body[2].id) |
238 | to_remove.push(res.body[3].id) | |
8c308c2b | 239 | |
9f10b292 C |
240 | webtorrent.add(video.magnetUri, function (torrent) { |
241 | expect(torrent.files).to.exist | |
242 | expect(torrent.files.length).to.equal(1) | |
243 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
8c308c2b | 244 | |
9f10b292 C |
245 | done() |
246 | }) | |
8c308c2b C |
247 | }) |
248 | }) | |
249 | ||
9f10b292 C |
250 | it('Should add the file 2 by asking pod 1', function (done) { |
251 | // Yes, this could be long | |
252 | this.timeout(200000) | |
8c308c2b | 253 | |
0c1cbbfe | 254 | utils.getVideosList(servers[0].url, function (err, res) { |
9f10b292 | 255 | if (err) throw err |
8c308c2b | 256 | |
f0f5567b | 257 | const video = res.body[1] |
0b697522 | 258 | |
9f10b292 C |
259 | webtorrent.add(video.magnetUri, function (torrent) { |
260 | expect(torrent.files).to.exist | |
261 | expect(torrent.files.length).to.equal(1) | |
262 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
8c308c2b | 263 | |
9f10b292 | 264 | done() |
8c308c2b C |
265 | }) |
266 | }) | |
9f10b292 | 267 | }) |
8c308c2b | 268 | |
9f10b292 C |
269 | it('Should add the file 3 by asking pod 2', function (done) { |
270 | // Yes, this could be long | |
271 | this.timeout(200000) | |
8c308c2b | 272 | |
0c1cbbfe | 273 | utils.getVideosList(servers[1].url, function (err, res) { |
9f10b292 | 274 | if (err) throw err |
8c308c2b | 275 | |
f0f5567b | 276 | const video = res.body[2] |
8c308c2b | 277 | |
9f10b292 C |
278 | webtorrent.add(video.magnetUri, function (torrent) { |
279 | expect(torrent.files).to.exist | |
280 | expect(torrent.files.length).to.equal(1) | |
281 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
8c308c2b | 282 | |
9f10b292 | 283 | done() |
8c308c2b C |
284 | }) |
285 | }) | |
9f10b292 | 286 | }) |
8c308c2b | 287 | |
9f10b292 C |
288 | it('Should add the file 3-2 by asking pod 1', function (done) { |
289 | // Yes, this could be long | |
290 | this.timeout(200000) | |
8c308c2b | 291 | |
0c1cbbfe | 292 | utils.getVideosList(servers[0].url, function (err, res) { |
9f10b292 | 293 | if (err) throw err |
8c308c2b | 294 | |
f0f5567b | 295 | const video = res.body[3] |
8c308c2b | 296 | |
9f10b292 C |
297 | webtorrent.add(video.magnetUri, function (torrent) { |
298 | expect(torrent.files).to.exist | |
299 | expect(torrent.files.length).to.equal(1) | |
300 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
8c308c2b | 301 | |
9f10b292 | 302 | done() |
8c308c2b C |
303 | }) |
304 | }) | |
9f10b292 | 305 | }) |
8c308c2b | 306 | |
9f10b292 C |
307 | it('Should remove the file 3 and 3-2 by asking pod 3', function (done) { |
308 | this.timeout(15000) | |
0b697522 | 309 | |
9f10b292 C |
310 | async.series([ |
311 | function (next) { | |
0c1cbbfe | 312 | utils.removeVideo(servers[2].url, servers[2].access_token, to_remove[0], next) |
9f10b292 C |
313 | }, |
314 | function (next) { | |
0c1cbbfe | 315 | utils.removeVideo(servers[2].url, servers[2].access_token, to_remove[1], next) |
9f10b292 C |
316 | }], |
317 | function (err) { | |
0b697522 | 318 | if (err) throw err |
9f10b292 C |
319 | setTimeout(done, 11000) |
320 | } | |
321 | ) | |
322 | }) | |
0b697522 | 323 | |
9f10b292 | 324 | it('Should have videos 1 and 3 on each pod', function (done) { |
0c1cbbfe C |
325 | async.each(servers, function (server, callback) { |
326 | utils.getVideosList(server.url, function (err, res) { | |
9f10b292 | 327 | if (err) throw err |
0b697522 | 328 | |
f0f5567b | 329 | const videos = res.body |
9f10b292 C |
330 | expect(videos).to.be.an('array') |
331 | expect(videos.length).to.equal(2) | |
2df82d42 C |
332 | expect(videos[0].id).not.to.equal(videos[1].id) |
333 | expect(videos[0].id).not.to.equal(to_remove[0]) | |
334 | expect(videos[1].id).not.to.equal(to_remove[0]) | |
335 | expect(videos[0].id).not.to.equal(to_remove[1]) | |
336 | expect(videos[1].id).not.to.equal(to_remove[1]) | |
0b697522 | 337 | |
9f10b292 | 338 | callback() |
0b697522 | 339 | }) |
9f10b292 | 340 | }, done) |
8c308c2b | 341 | }) |
9f10b292 | 342 | }) |
8c308c2b | 343 | |
9f10b292 | 344 | after(function (done) { |
0c1cbbfe C |
345 | servers.forEach(function (server) { |
346 | process.kill(-server.app.pid) | |
8c308c2b | 347 | }) |
9f10b292 C |
348 | process.kill(-webtorrent.app.pid) |
349 | ||
350 | // Keep the logs if the test failed | |
351 | if (this.ok) { | |
352 | utils.flushTests(done) | |
353 | } else { | |
354 | done() | |
355 | } | |
8c308c2b | 356 | }) |
9f10b292 | 357 | }) |