aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/api/multiplePods.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2015-12-04 16:13:32 +0100
committerChocobozzz <florian.bigard@gmail.com>2015-12-04 16:13:32 +0100
commit0b69752270f1ceea06a29872b3db23660a55d6d3 (patch)
tree42da726633f3e48f4fe592cfd2c1ca14346a159b /test/api/multiplePods.js
parentaf82cae07dc568e3cb10acd70113df56eb8b15a9 (diff)
downloadPeerTube-0b69752270f1ceea06a29872b3db23660a55d6d3.tar.gz
PeerTube-0b69752270f1ceea06a29872b3db23660a55d6d3.tar.zst
PeerTube-0b69752270f1ceea06a29872b3db23660a55d6d3.zip
Add a pool of requests instead of making a request at each action (add
video/remove video) for performance in big networks
Diffstat (limited to 'test/api/multiplePods.js')
-rw-r--r--test/api/multiplePods.js131
1 files changed, 86 insertions, 45 deletions
diff --git a/test/api/multiplePods.js b/test/api/multiplePods.js
index 1edfc1ce3..3ce57afa8 100644
--- a/test/api/multiplePods.js
+++ b/test/api/multiplePods.js
@@ -14,7 +14,7 @@
14 var path = '/api/v1/videos' 14 var path = '/api/v1/videos'
15 var apps = [] 15 var apps = []
16 var urls = [] 16 var urls = []
17 var video_id = -1 17 var to_remove = []
18 18
19 function getVideosList (url, end) { 19 function getVideosList (url, end) {
20 request(url) 20 request(url)
@@ -36,6 +36,14 @@
36 .end(end) 36 .end(end)
37 } 37 }
38 38
39 function removeVideo (url, id, end) {
40 request(url)
41 .delete(path + '/' + id)
42 .set('Accept', 'application/json')
43 .expect(204)
44 .end(end)
45 }
46
39 before(function (done) { 47 before(function (done) {
40 this.timeout(30000) 48 this.timeout(30000)
41 var path_friends = '/api/v1/pods/makefriends' 49 var path_friends = '/api/v1/pods/makefriends'
@@ -89,7 +97,7 @@
89 97
90 describe('Should upload the video and propagate on each pod', function () { 98 describe('Should upload the video and propagate on each pod', function () {
91 it('Should upload the video on pod 1 and propagate on each pod', function (done) { 99 it('Should upload the video on pod 1 and propagate on each pod', function (done) {
92 this.timeout(5000) 100 this.timeout(15000)
93 101
94 uploadVideo(urls[0], 'my super name for pod 1', 'my super description for pod 1', 'video_short1.webm', function (err) { 102 uploadVideo(urls[0], 'my super name for pod 1', 'my super description for pod 1', 'video_short1.webm', function (err) {
95 if (err) throw err 103 if (err) throw err
@@ -125,12 +133,12 @@
125 133
126 done() 134 done()
127 }) 135 })
128 }, 1000) 136 }, 11000)
129 }) 137 })
130 }) 138 })
131 139
132 it('Should upload the video on pod 2 and propagate on each pod', function (done) { 140 it('Should upload the video on pod 2 and propagate on each pod', function (done) {
133 this.timeout(5000) 141 this.timeout(15000)
134 142
135 uploadVideo(urls[1], 'my super name for pod 2', 'my super description for pod 2', 'video_short2.webm', function (err) { 143 uploadVideo(urls[1], 'my super name for pod 2', 'my super description for pod 2', 'video_short2.webm', function (err) {
136 if (err) throw err 144 if (err) throw err
@@ -166,47 +174,56 @@
166 174
167 done() 175 done()
168 }) 176 })
169 }, 1000) 177 }, 11000)
170 }) 178 })
171 }) 179 })
172 180
173 it('Should upload the video on pod 3 and propagate on each pod', function (done) { 181 it('Should upload two videos on pod 3 and propagate on each pod', function (done) {
174 this.timeout(5000) 182 this.timeout(15000)
175 183
176 uploadVideo(urls[2], 'my super name for pod 3', 'my super description for pod 3', 'video_short3.webm', function (err) { 184 uploadVideo(urls[2], 'my super name for pod 3', 'my super description for pod 3', 'video_short3.webm', function (err) {
177 if (err) throw err 185 if (err) throw err
186 uploadVideo(urls[2], 'my super name for pod 3-2', 'my super description for pod 3-2', 'video_short.webm', function (err) {
187 if (err) throw err
178 188
179 setTimeout(function () { 189 setTimeout(function () {
180 var base_magnet = null 190 var base_magnet = null
181 // All pods should have this video 191 // All pods should have this video
182 async.each(urls, function (url, callback) { 192 async.each(urls, function (url, callback) {
183 getVideosList(url, function (err, res) { 193 getVideosList(url, function (err, res) {
184 if (err) throw err 194 if (err) throw err
185
186 var videos = res.body
187 expect(videos).to.be.an('array')
188 expect(videos.length).to.equal(3)
189 var video = videos[2]
190 expect(video.name).to.equal('my super name for pod 3')
191 expect(video.description).to.equal('my super description for pod 3')
192 expect(video.podUrl).to.equal('http://localhost:9003')
193 expect(video.magnetUri).to.exist
194 195
195 // All pods should have the same magnet Uri 196 var videos = res.body
196 if (base_magnet === null) { 197 expect(videos).to.be.an('array')
197 base_magnet = video.magnetUri 198 expect(videos.length).to.equal(4)
198 } else { 199 var video = videos[2]
199 expect(video.magnetUri).to.equal.magnetUri 200 expect(video.name).to.equal('my super name for pod 3')
200 } 201 expect(video.description).to.equal('my super description for pod 3')
202 expect(video.podUrl).to.equal('http://localhost:9003')
203 expect(video.magnetUri).to.exist
204
205 video = videos[3]
206 expect(video.name).to.equal('my super name for pod 3-2')
207 expect(video.description).to.equal('my super description for pod 3-2')
208 expect(video.podUrl).to.equal('http://localhost:9003')
209 expect(video.magnetUri).to.exist
210
211 // All pods should have the same magnet Uri
212 if (base_magnet === null) {
213 base_magnet = video.magnetUri
214 } else {
215 expect(video.magnetUri).to.equal.magnetUri
216 }
217
218 callback()
219 })
220 }, function (err) {
221 if (err) throw err
201 222
202 callback() 223 done()
203 }) 224 })
204 }, function (err) { 225 }, 11000)
205 if (err) throw err 226 })
206
207 done()
208 })
209 }, 1000)
210 }) 227 })
211 }) 228 })
212 }) 229 })
@@ -220,6 +237,9 @@
220 if (err) throw err 237 if (err) throw err
221 238
222 var video = res.body[0] 239 var video = res.body[0]
240 to_remove.push(res.body[2]._id)
241 to_remove.push(res.body[3]._id)
242
223 webtorrent.add(video.magnetUri, function (torrent) { 243 webtorrent.add(video.magnetUri, function (torrent) {
224 expect(torrent.files).to.exist 244 expect(torrent.files).to.exist
225 expect(torrent.files.length).to.equal(1) 245 expect(torrent.files.length).to.equal(1)
@@ -257,7 +277,6 @@
257 if (err) throw err 277 if (err) throw err
258 278
259 var video = res.body[2] 279 var video = res.body[2]
260 video_id = res.body[1]._id
261 280
262 webtorrent.add(video.magnetUri, function (torrent) { 281 webtorrent.add(video.magnetUri, function (torrent) {
263 expect(torrent.files).to.exist 282 expect(torrent.files).to.exist
@@ -269,19 +288,39 @@
269 }) 288 })
270 }) 289 })
271 290
272 it('Should remove the file 2 by asking pod 2', function (done) { 291 it('Should add the file 3-2 by asking pod 1', function (done) {
273 request(urls[1]) 292 // Yes, this could be long
274 .delete(path + '/' + video_id) 293 this.timeout(200000)
275 .set('Accept', 'application/json') 294
276 .expect(204) 295 getVideosList(urls[0], function (err, res) {
277 .end(function (err, res) { 296 if (err) throw err
297
298 var video = res.body[3]
299
300 webtorrent.add(video.magnetUri, function (torrent) {
301 expect(torrent.files).to.exist
302 expect(torrent.files.length).to.equal(1)
303 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
304
305 done()
306 })
307 })
308 })
309
310 it('Should remove the file 3 and 3-2 by asking pod 3', function (done) {
311 this.timeout(15000)
312
313 removeVideo(urls[2], to_remove[0], function (err) {
314 if (err) throw err
315 removeVideo(urls[2], to_remove[1], function (err) {
278 if (err) throw err 316 if (err) throw err
279 317
280 // Wait the propagation to the other pods 318 // Wait the propagation to the other pods
281 setTimeout(function () { 319 setTimeout(function () {
282 done() 320 done()
283 }, 1000) 321 }, 11000)
284 }) 322 })
323 })
285 }) 324 })
286 325
287 it('Should have videos 1 and 3 on each pod', function (done) { 326 it('Should have videos 1 and 3 on each pod', function (done) {
@@ -293,8 +332,10 @@
293 expect(videos).to.be.an('array') 332 expect(videos).to.be.an('array')
294 expect(videos.length).to.equal(2) 333 expect(videos.length).to.equal(2)
295 expect(videos[0]._id).not.to.equal(videos[1]._id) 334 expect(videos[0]._id).not.to.equal(videos[1]._id)
296 expect(videos[0]._id).not.to.equal(video_id) 335 expect(videos[0]._id).not.to.equal(to_remove[0])
297 expect(videos[1]._id).not.to.equal(video_id) 336 expect(videos[1]._id).not.to.equal(to_remove[0])
337 expect(videos[0]._id).not.to.equal(to_remove[1])
338 expect(videos[1]._id).not.to.equal(to_remove[1])
298 339
299 callback() 340 callback()
300 }) 341 })