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