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