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