]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/multiplePods.js
Use const/let now we use node 4.2
[github/Chocobozzz/PeerTube.git] / server / tests / api / multiplePods.js
CommitLineData
9f10b292
C
1'use strict'
2
f0f5567b
C
3const async = require('async')
4const chai = require('chai')
5const expect = chai.expect
6const pathUtils = require('path')
9f10b292 7
f0f5567b
C
8const utils = require('./utils')
9const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent'))
9f10b292
C
10webtorrent.silent = true
11
12describe('Test multiple pods', function () {
f0f5567b
C
13 let apps = []
14 let urls = []
15 const to_remove = []
9f10b292
C
16
17 before(function (done) {
18 this.timeout(30000)
19
20 async.series([
21 // Run servers
22 function (next) {
23 utils.flushAndRunMultipleServers(3, function (apps_run, urls_run) {
24 apps = apps_run
25 urls = urls_run
26 next()
27 })
28 },
29 // The second pod make friend with the third
30 function (next) {
31 utils.makeFriends(urls[1], next)
32 },
33 // Wait for the request between pods
34 function (next) {
35 setTimeout(next, 10000)
36 },
37 // Pod 1 make friends too
38 function (next) {
39 utils.makeFriends(urls[0], next)
40 },
41 function (next) {
42 webtorrent.create({ host: 'client', port: '1' }, next)
43 }
44 ], done)
45 })
8c308c2b 46
9f10b292
C
47 it('Should not have videos for all pods', function (done) {
48 async.each(urls, function (url, callback) {
49 utils.getVideosList(url, function (err, res) {
50 if (err) throw err
8c308c2b 51
9f10b292
C
52 expect(res.body).to.be.an('array')
53 expect(res.body.length).to.equal(0)
8c308c2b 54
9f10b292
C
55 callback()
56 })
57 }, done)
58 })
8c308c2b 59
9f10b292
C
60 describe('Should upload the video and propagate on each pod', function () {
61 it('Should upload the video on pod 1 and propagate on each pod', function (done) {
62 this.timeout(15000)
8c308c2b 63
ee66c593 64 async.series([
ee66c593 65 function (next) {
9f10b292 66 utils.uploadVideo(urls[0], 'my super name for pod 1', 'my super description for pod 1', 'video_short1.webm', next)
ee66c593 67 },
ee66c593 68 function (next) {
9f10b292
C
69 setTimeout(next, 11000)
70 }],
71 // All pods should have this video
72 function (err) {
73 if (err) throw err
74
75 async.each(urls, function (url, callback) {
f0f5567b 76 let base_magnet = null
9f10b292
C
77
78 utils.getVideosList(url, function (err, res) {
79 if (err) throw err
80
f0f5567b 81 const videos = res.body
9f10b292
C
82 expect(videos).to.be.an('array')
83 expect(videos.length).to.equal(1)
f0f5567b 84 const video = videos[0]
9f10b292
C
85 expect(video.name).to.equal('my super name for pod 1')
86 expect(video.description).to.equal('my super description for pod 1')
87 expect(video.podUrl).to.equal('http://localhost:9001')
88 expect(video.magnetUri).to.exist
89
90 // All pods should have the same magnet Uri
91 if (base_magnet === null) {
92 base_magnet = video.magnetUri
93 } else {
94 expect(video.magnetUri).to.equal.magnetUri
95 }
96
97 callback()
98 })
99 }, done)
100 }
101 )
102 })
103
104 it('Should upload the video on pod 2 and propagate on each pod', function (done) {
105 this.timeout(15000)
106
107 async.series([
ee66c593 108 function (next) {
9f10b292 109 utils.uploadVideo(urls[1], 'my super name for pod 2', 'my super description for pod 2', 'video_short2.webm', next)
ee66c593
C
110 },
111 function (next) {
9f10b292
C
112 setTimeout(next, 11000)
113 }],
114 // All pods should have this video
115 function (err) {
116 if (err) throw err
117
118 async.each(urls, function (url, callback) {
f0f5567b 119 let base_magnet = null
9f10b292
C
120
121 utils.getVideosList(url, function (err, res) {
122 if (err) throw err
123
f0f5567b 124 const videos = res.body
9f10b292
C
125 expect(videos).to.be.an('array')
126 expect(videos.length).to.equal(2)
f0f5567b 127 const video = videos[1]
9f10b292
C
128 expect(video.name).to.equal('my super name for pod 2')
129 expect(video.description).to.equal('my super description for pod 2')
130 expect(video.podUrl).to.equal('http://localhost:9002')
131 expect(video.magnetUri).to.exist
132
133 // All pods should have the same magnet Uri
134 if (base_magnet === null) {
135 base_magnet = video.magnetUri
136 } else {
137 expect(video.magnetUri).to.equal.magnetUri
138 }
139
140 callback()
141 })
142 }, done)
ee66c593 143 }
9f10b292 144 )
8c308c2b
C
145 })
146
9f10b292
C
147 it('Should upload two videos on pod 3 and propagate on each pod', function (done) {
148 this.timeout(30000)
8c308c2b 149
9f10b292
C
150 async.series([
151 function (next) {
152 utils.uploadVideo(urls[2], 'my super name for pod 3', 'my super description for pod 3', 'video_short3.webm', next)
153 },
154 function (next) {
155 utils.uploadVideo(urls[2], 'my super name for pod 3-2', 'my super description for pod 3-2', 'video_short.webm', next)
156 },
157 function (next) {
158 setTimeout(next, 22000)
159 }],
160 function (err) {
161 if (err) throw err
8c308c2b 162
f0f5567b 163 let base_magnet = null
9f10b292
C
164 // All pods should have this video
165 async.each(urls, function (url, callback) {
166 utils.getVideosList(url, function (err, res) {
167 if (err) throw err
168
f0f5567b 169 const videos = res.body
9f10b292
C
170 expect(videos).to.be.an('array')
171 expect(videos.length).to.equal(4)
f0f5567b 172 let video = videos[2]
9f10b292
C
173 expect(video.name).to.equal('my super name for pod 3')
174 expect(video.description).to.equal('my super description for pod 3')
175 expect(video.podUrl).to.equal('http://localhost:9003')
176 expect(video.magnetUri).to.exist
177
178 video = videos[3]
179 expect(video.name).to.equal('my super name for pod 3-2')
180 expect(video.description).to.equal('my super description for pod 3-2')
181 expect(video.podUrl).to.equal('http://localhost:9003')
182 expect(video.magnetUri).to.exist
183
184 // All pods should have the same magnet Uri
185 if (base_magnet === null) {
186 base_magnet = video.magnetUri
187 } else {
188 expect(video.magnetUri).to.equal.magnetUri
189 }
190
191 callback()
192 })
193 }, done)
194 }
195 )
8c308c2b 196 })
9f10b292 197 })
8c308c2b 198
9f10b292
C
199 describe('Should seed the uploaded video', function () {
200 it('Should add the file 1 by asking pod 3', function (done) {
201 // Yes, this could be long
202 this.timeout(200000)
8c308c2b 203
9f10b292
C
204 utils.getVideosList(urls[2], function (err, res) {
205 if (err) throw err
8c308c2b 206
f0f5567b 207 const video = res.body[0]
9f10b292
C
208 to_remove.push(res.body[2]._id)
209 to_remove.push(res.body[3]._id)
8c308c2b 210
9f10b292
C
211 webtorrent.add(video.magnetUri, function (torrent) {
212 expect(torrent.files).to.exist
213 expect(torrent.files.length).to.equal(1)
214 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
8c308c2b 215
9f10b292
C
216 done()
217 })
8c308c2b
C
218 })
219 })
220
9f10b292
C
221 it('Should add the file 2 by asking pod 1', function (done) {
222 // Yes, this could be long
223 this.timeout(200000)
8c308c2b 224
9f10b292
C
225 utils.getVideosList(urls[0], function (err, res) {
226 if (err) throw err
8c308c2b 227
f0f5567b 228 const video = res.body[1]
0b697522 229
9f10b292
C
230 webtorrent.add(video.magnetUri, function (torrent) {
231 expect(torrent.files).to.exist
232 expect(torrent.files.length).to.equal(1)
233 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
8c308c2b 234
9f10b292 235 done()
8c308c2b
C
236 })
237 })
9f10b292 238 })
8c308c2b 239
9f10b292
C
240 it('Should add the file 3 by asking pod 2', function (done) {
241 // Yes, this could be long
242 this.timeout(200000)
8c308c2b 243
9f10b292
C
244 utils.getVideosList(urls[1], function (err, res) {
245 if (err) throw err
8c308c2b 246
f0f5567b 247 const video = res.body[2]
8c308c2b 248
9f10b292
C
249 webtorrent.add(video.magnetUri, function (torrent) {
250 expect(torrent.files).to.exist
251 expect(torrent.files.length).to.equal(1)
252 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
8c308c2b 253
9f10b292 254 done()
8c308c2b
C
255 })
256 })
9f10b292 257 })
8c308c2b 258
9f10b292
C
259 it('Should add the file 3-2 by asking pod 1', function (done) {
260 // Yes, this could be long
261 this.timeout(200000)
8c308c2b 262
9f10b292
C
263 utils.getVideosList(urls[0], function (err, res) {
264 if (err) throw err
8c308c2b 265
f0f5567b 266 const video = res.body[3]
8c308c2b 267
9f10b292
C
268 webtorrent.add(video.magnetUri, function (torrent) {
269 expect(torrent.files).to.exist
270 expect(torrent.files.length).to.equal(1)
271 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
8c308c2b 272
9f10b292 273 done()
8c308c2b
C
274 })
275 })
9f10b292 276 })
8c308c2b 277
9f10b292
C
278 it('Should remove the file 3 and 3-2 by asking pod 3', function (done) {
279 this.timeout(15000)
0b697522 280
9f10b292
C
281 async.series([
282 function (next) {
283 utils.removeVideo(urls[2], to_remove[0], next)
284 },
285 function (next) {
286 utils.removeVideo(urls[2], to_remove[1], next)
287 }],
288 function (err) {
0b697522 289 if (err) throw err
9f10b292
C
290 setTimeout(done, 11000)
291 }
292 )
293 })
0b697522 294
9f10b292
C
295 it('Should have videos 1 and 3 on each pod', function (done) {
296 async.each(urls, function (url, callback) {
297 utils.getVideosList(url, function (err, res) {
298 if (err) throw err
0b697522 299
f0f5567b 300 const videos = res.body
9f10b292
C
301 expect(videos).to.be.an('array')
302 expect(videos.length).to.equal(2)
303 expect(videos[0]._id).not.to.equal(videos[1]._id)
304 expect(videos[0]._id).not.to.equal(to_remove[0])
305 expect(videos[1]._id).not.to.equal(to_remove[0])
306 expect(videos[0]._id).not.to.equal(to_remove[1])
307 expect(videos[1]._id).not.to.equal(to_remove[1])
0b697522 308
9f10b292 309 callback()
0b697522 310 })
9f10b292 311 }, done)
8c308c2b 312 })
9f10b292 313 })
8c308c2b 314
9f10b292
C
315 after(function (done) {
316 apps.forEach(function (app) {
317 process.kill(-app.pid)
8c308c2b 318 })
9f10b292
C
319 process.kill(-webtorrent.app.pid)
320
321 // Keep the logs if the test failed
322 if (this.ok) {
323 utils.flushTests(done)
324 } else {
325 done()
326 }
8c308c2b 327 })
9f10b292 328})