]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/multiplePods.js
Add createdDate to videos
[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 = []
bc503c2a 14 const toRemove = []
9f10b292
C
15
16 before(function (done) {
17 this.timeout(30000)
18
19 async.series([
20 // Run servers
21 function (next) {
bc503c2a
C
22 utils.flushAndRunMultipleServers(3, function (serversRun) {
23 servers = serversRun
9f10b292
C
24 next()
25 })
26 },
0c1cbbfe
C
27 // Get the access tokens
28 function (next) {
bc503c2a
C
29 async.each(servers, function (server, callbackEach) {
30 utils.loginAndGetAccessToken(server, function (err, accessToken) {
31 if (err) return callbackEach(err)
0c1cbbfe 32
bc503c2a
C
33 server.accessToken = accessToken
34 callbackEach()
0c1cbbfe
C
35 })
36 }, next)
37 },
9f10b292
C
38 // The second pod make friend with the third
39 function (next) {
b3b92647
C
40 const server = servers[1]
41 utils.makeFriends(server.url, server.accessToken, next)
9f10b292
C
42 },
43 // Wait for the request between pods
44 function (next) {
45 setTimeout(next, 10000)
46 },
47 // Pod 1 make friends too
48 function (next) {
b3b92647
C
49 const server = servers[0]
50 utils.makeFriends(server.url, server.accessToken, next)
9f10b292
C
51 },
52 function (next) {
53 webtorrent.create({ host: 'client', port: '1' }, next)
54 }
55 ], done)
56 })
8c308c2b 57
9f10b292 58 it('Should not have videos for all pods', function (done) {
0c1cbbfe
C
59 async.each(servers, function (server, callback) {
60 utils.getVideosList(server.url, function (err, res) {
9f10b292 61 if (err) throw err
8c308c2b 62
9f10b292
C
63 expect(res.body).to.be.an('array')
64 expect(res.body.length).to.equal(0)
8c308c2b 65
9f10b292
C
66 callback()
67 })
68 }, done)
69 })
8c308c2b 70
9f10b292
C
71 describe('Should upload the video and propagate on each pod', function () {
72 it('Should upload the video on pod 1 and propagate on each pod', function (done) {
73 this.timeout(15000)
8c308c2b 74
ee66c593 75 async.series([
ee66c593 76 function (next) {
b6c6f935 77 utils.uploadVideo(servers[0].url, servers[0].accessToken, 'my super name for pod 1', 'my super description for pod 1', 'video_short1.webm', next)
ee66c593 78 },
ee66c593 79 function (next) {
9f10b292
C
80 setTimeout(next, 11000)
81 }],
82 // All pods should have this video
83 function (err) {
84 if (err) throw err
85
0c1cbbfe 86 async.each(servers, function (server, callback) {
bc503c2a 87 let baseMagnet = null
9f10b292 88
0c1cbbfe 89 utils.getVideosList(server.url, function (err, res) {
9f10b292
C
90 if (err) throw err
91
f0f5567b 92 const videos = res.body
9f10b292
C
93 expect(videos).to.be.an('array')
94 expect(videos.length).to.equal(1)
f0f5567b 95 const video = videos[0]
9f10b292
C
96 expect(video.name).to.equal('my super name for pod 1')
97 expect(video.description).to.equal('my super description for pod 1')
98 expect(video.podUrl).to.equal('http://localhost:9001')
99 expect(video.magnetUri).to.exist
3a8a8b51 100 expect(video.duration).to.equal(10)
bb10240e 101 expect(utils.dateIsValid(video.createdDate)).to.be.true
9f10b292 102
6d8ada5f
C
103 if (server.url !== 'http://localhost:9001') {
104 expect(video.isLocal).to.be.false
105 } else {
106 expect(video.isLocal).to.be.true
107 }
108
9f10b292 109 // All pods should have the same magnet Uri
bc503c2a
C
110 if (baseMagnet === null) {
111 baseMagnet = video.magnetUri
9f10b292
C
112 } else {
113 expect(video.magnetUri).to.equal.magnetUri
114 }
115
36d56024 116 utils.testImage(server.url, 'video_short1.webm', video.thumbnailPath, function (err, test) {
9e5f3740
C
117 if (err) throw err
118 expect(test).to.equal(true)
119
120 callback()
121 })
9f10b292
C
122 })
123 }, done)
124 }
125 )
126 })
127
128 it('Should upload the video on pod 2 and propagate on each pod', function (done) {
129 this.timeout(15000)
130
131 async.series([
ee66c593 132 function (next) {
b6c6f935 133 utils.uploadVideo(servers[1].url, servers[1].accessToken, 'my super name for pod 2', 'my super description for pod 2', 'video_short2.webm', next)
ee66c593
C
134 },
135 function (next) {
9f10b292
C
136 setTimeout(next, 11000)
137 }],
138 // All pods should have this video
139 function (err) {
140 if (err) throw err
141
0c1cbbfe 142 async.each(servers, function (server, callback) {
bc503c2a 143 let baseMagnet = null
9f10b292 144
0c1cbbfe 145 utils.getVideosList(server.url, function (err, res) {
9f10b292
C
146 if (err) throw err
147
f0f5567b 148 const videos = res.body
9f10b292
C
149 expect(videos).to.be.an('array')
150 expect(videos.length).to.equal(2)
f0f5567b 151 const video = videos[1]
9f10b292
C
152 expect(video.name).to.equal('my super name for pod 2')
153 expect(video.description).to.equal('my super description for pod 2')
154 expect(video.podUrl).to.equal('http://localhost:9002')
155 expect(video.magnetUri).to.exist
3a8a8b51 156 expect(video.duration).to.equal(5)
bb10240e 157 expect(utils.dateIsValid(video.createdDate)).to.be.true
9f10b292 158
6d8ada5f
C
159 if (server.url !== 'http://localhost:9002') {
160 expect(video.isLocal).to.be.false
161 } else {
162 expect(video.isLocal).to.be.true
163 }
164
9f10b292 165 // All pods should have the same magnet Uri
bc503c2a
C
166 if (baseMagnet === null) {
167 baseMagnet = video.magnetUri
9f10b292
C
168 } else {
169 expect(video.magnetUri).to.equal.magnetUri
170 }
171
36d56024 172 utils.testImage(server.url, 'video_short2.webm', video.thumbnailPath, function (err, test) {
9e5f3740
C
173 if (err) throw err
174 expect(test).to.equal(true)
175
176 callback()
177 })
9f10b292
C
178 })
179 }, done)
ee66c593 180 }
9f10b292 181 )
8c308c2b
C
182 })
183
9f10b292
C
184 it('Should upload two videos on pod 3 and propagate on each pod', function (done) {
185 this.timeout(30000)
8c308c2b 186
9f10b292
C
187 async.series([
188 function (next) {
b6c6f935 189 utils.uploadVideo(servers[2].url, servers[2].accessToken, 'my super name for pod 3', 'my super description for pod 3', 'video_short3.webm', next)
9f10b292
C
190 },
191 function (next) {
b6c6f935 192 utils.uploadVideo(servers[2].url, servers[2].accessToken, 'my super name for pod 3-2', 'my super description for pod 3-2', 'video_short.webm', next)
9f10b292
C
193 },
194 function (next) {
195 setTimeout(next, 22000)
196 }],
197 function (err) {
198 if (err) throw err
8c308c2b 199
bc503c2a 200 let baseMagnet = null
9f10b292 201 // All pods should have this video
0c1cbbfe
C
202 async.each(servers, function (server, callback) {
203 utils.getVideosList(server.url, function (err, res) {
9f10b292
C
204 if (err) throw err
205
f0f5567b 206 const videos = res.body
9f10b292
C
207 expect(videos).to.be.an('array')
208 expect(videos.length).to.equal(4)
3a8a8b51 209
cbe2f7c3
C
210 // We not sure about the order of the two last uploads
211 let video1 = null
212 let video2 = null
213 if (videos[2].name === 'my super name for pod 3') {
214 video1 = videos[2]
215 video2 = videos[3]
216 } else {
217 video1 = videos[3]
218 video2 = videos[2]
219 }
220
6d8ada5f
C
221 expect(video1.name).to.equal('my super name for pod 3')
222 expect(video1.description).to.equal('my super description for pod 3')
223 expect(video1.podUrl).to.equal('http://localhost:9003')
224 expect(video1.magnetUri).to.exist
3a8a8b51 225 expect(video1.duration).to.equal(5)
bb10240e 226 expect(utils.dateIsValid(video1.createdDate)).to.be.true
6d8ada5f 227
6d8ada5f
C
228 expect(video2.name).to.equal('my super name for pod 3-2')
229 expect(video2.description).to.equal('my super description for pod 3-2')
230 expect(video2.podUrl).to.equal('http://localhost:9003')
231 expect(video2.magnetUri).to.exist
3a8a8b51 232 expect(video2.duration).to.equal(5)
bb10240e 233 expect(utils.dateIsValid(video2.createdDate)).to.be.true
6d8ada5f
C
234
235 if (server.url !== 'http://localhost:9003') {
236 expect(video1.isLocal).to.be.false
237 expect(video2.isLocal).to.be.false
238 } else {
239 expect(video1.isLocal).to.be.true
240 expect(video2.isLocal).to.be.true
241 }
9f10b292
C
242
243 // All pods should have the same magnet Uri
bc503c2a
C
244 if (baseMagnet === null) {
245 baseMagnet = video2.magnetUri
9f10b292 246 } else {
6d8ada5f 247 expect(video2.magnetUri).to.equal.magnetUri
9f10b292
C
248 }
249
36d56024 250 utils.testImage(server.url, 'video_short3.webm', video1.thumbnailPath, function (err, test) {
9e5f3740
C
251 if (err) throw err
252 expect(test).to.equal(true)
253
36d56024 254 utils.testImage(server.url, 'video_short.webm', video2.thumbnailPath, function (err, test) {
9e5f3740
C
255 if (err) throw err
256 expect(test).to.equal(true)
257
258 callback()
259 })
260 })
9f10b292
C
261 })
262 }, done)
263 }
264 )
8c308c2b 265 })
9f10b292 266 })
8c308c2b 267
9f10b292
C
268 describe('Should seed the uploaded video', function () {
269 it('Should add the file 1 by asking pod 3', function (done) {
270 // Yes, this could be long
271 this.timeout(200000)
8c308c2b 272
0c1cbbfe 273 utils.getVideosList(servers[2].url, function (err, res) {
9f10b292 274 if (err) throw err
8c308c2b 275
f0f5567b 276 const video = res.body[0]
bc503c2a
C
277 toRemove.push(res.body[2].id)
278 toRemove.push(res.body[3].id)
8c308c2b 279
9f10b292
C
280 webtorrent.add(video.magnetUri, function (torrent) {
281 expect(torrent.files).to.exist
282 expect(torrent.files.length).to.equal(1)
283 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
8c308c2b 284
9f10b292
C
285 done()
286 })
8c308c2b
C
287 })
288 })
289
9f10b292
C
290 it('Should add the file 2 by asking pod 1', function (done) {
291 // Yes, this could be long
292 this.timeout(200000)
8c308c2b 293
0c1cbbfe 294 utils.getVideosList(servers[0].url, function (err, res) {
9f10b292 295 if (err) throw err
8c308c2b 296
f0f5567b 297 const video = res.body[1]
0b697522 298
9f10b292
C
299 webtorrent.add(video.magnetUri, function (torrent) {
300 expect(torrent.files).to.exist
301 expect(torrent.files.length).to.equal(1)
302 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
8c308c2b 303
9f10b292 304 done()
8c308c2b
C
305 })
306 })
9f10b292 307 })
8c308c2b 308
9f10b292
C
309 it('Should add the file 3 by asking pod 2', function (done) {
310 // Yes, this could be long
311 this.timeout(200000)
8c308c2b 312
0c1cbbfe 313 utils.getVideosList(servers[1].url, function (err, res) {
9f10b292 314 if (err) throw err
8c308c2b 315
f0f5567b 316 const video = res.body[2]
8c308c2b 317
9f10b292
C
318 webtorrent.add(video.magnetUri, function (torrent) {
319 expect(torrent.files).to.exist
320 expect(torrent.files.length).to.equal(1)
321 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
8c308c2b 322
bc59d9e0 323 webtorrent.remove(video.magnetUri, done)
8c308c2b
C
324 })
325 })
9f10b292 326 })
8c308c2b 327
9f10b292
C
328 it('Should add the file 3-2 by asking pod 1', function (done) {
329 // Yes, this could be long
330 this.timeout(200000)
8c308c2b 331
0c1cbbfe 332 utils.getVideosList(servers[0].url, function (err, res) {
9f10b292 333 if (err) throw err
8c308c2b 334
f0f5567b 335 const video = res.body[3]
8c308c2b 336
9f10b292
C
337 webtorrent.add(video.magnetUri, function (torrent) {
338 expect(torrent.files).to.exist
339 expect(torrent.files.length).to.equal(1)
340 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
8c308c2b 341
9f10b292 342 done()
8c308c2b
C
343 })
344 })
9f10b292 345 })
8c308c2b 346
9f10b292
C
347 it('Should remove the file 3 and 3-2 by asking pod 3', function (done) {
348 this.timeout(15000)
0b697522 349
9f10b292
C
350 async.series([
351 function (next) {
bc503c2a 352 utils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[0], next)
9f10b292
C
353 },
354 function (next) {
bc503c2a 355 utils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[1], next)
9f10b292
C
356 }],
357 function (err) {
0b697522 358 if (err) throw err
9f10b292
C
359 setTimeout(done, 11000)
360 }
361 )
362 })
0b697522 363
9f10b292 364 it('Should have videos 1 and 3 on each pod', function (done) {
0c1cbbfe
C
365 async.each(servers, function (server, callback) {
366 utils.getVideosList(server.url, function (err, res) {
9f10b292 367 if (err) throw err
0b697522 368
f0f5567b 369 const videos = res.body
9f10b292
C
370 expect(videos).to.be.an('array')
371 expect(videos.length).to.equal(2)
2df82d42 372 expect(videos[0].id).not.to.equal(videos[1].id)
bc503c2a
C
373 expect(videos[0].id).not.to.equal(toRemove[0])
374 expect(videos[1].id).not.to.equal(toRemove[0])
375 expect(videos[0].id).not.to.equal(toRemove[1])
376 expect(videos[1].id).not.to.equal(toRemove[1])
0b697522 377
9f10b292 378 callback()
0b697522 379 })
9f10b292 380 }, done)
8c308c2b 381 })
9f10b292 382 })
8c308c2b 383
9f10b292 384 after(function (done) {
0c1cbbfe
C
385 servers.forEach(function (server) {
386 process.kill(-server.app.pid)
8c308c2b 387 })
9f10b292
C
388 process.kill(-webtorrent.app.pid)
389
390 // Keep the logs if the test failed
391 if (this.ok) {
392 utils.flushTests(done)
393 } else {
394 done()
395 }
8c308c2b 396 })
9f10b292 397})