aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/redundancy
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-02-11 14:09:23 +0100
committerChocobozzz <me@florianbigard.com>2019-02-11 14:09:23 +0100
commitb718fd22374d64534bcfe69932cf562894abed6a (patch)
tree311d3c67e2a4d1f33ebdd1dc163527de9d33d0f7 /server/tests/api/redundancy
parentadb115f5522bea4d52456a9fc5eb4140bb064476 (diff)
parent501e961199578129629cf0567033d13efced9904 (diff)
downloadPeerTube-b718fd22374d64534bcfe69932cf562894abed6a.tar.gz
PeerTube-b718fd22374d64534bcfe69932cf562894abed6a.tar.zst
PeerTube-b718fd22374d64534bcfe69932cf562894abed6a.zip
Merge branch 'develop' into pr/1285
Diffstat (limited to 'server/tests/api/redundancy')
-rw-r--r--server/tests/api/redundancy/redundancy.ts216
1 files changed, 151 insertions, 65 deletions
diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts
index 9d3ce8153..778611fff 100644
--- a/server/tests/api/redundancy/redundancy.ts
+++ b/server/tests/api/redundancy/redundancy.ts
@@ -17,7 +17,7 @@ import {
17 viewVideo, 17 viewVideo,
18 wait, 18 wait,
19 waitUntilLog, 19 waitUntilLog,
20 checkVideoFilesWereRemoved, removeVideo, getVideoWithToken 20 checkVideoFilesWereRemoved, removeVideo, getVideoWithToken, reRunServer, checkSegmentHash
21} from '../../../../shared/utils' 21} from '../../../../shared/utils'
22import { waitJobs } from '../../../../shared/utils/server/jobs' 22import { waitJobs } from '../../../../shared/utils/server/jobs'
23 23
@@ -48,6 +48,11 @@ function checkMagnetWebseeds (file: { magnetUri: string, resolution: { id: numbe
48 48
49async function runServers (strategy: VideoRedundancyStrategy, additionalParams: any = {}) { 49async function runServers (strategy: VideoRedundancyStrategy, additionalParams: any = {}) {
50 const config = { 50 const config = {
51 transcoding: {
52 hls: {
53 enabled: true
54 }
55 },
51 redundancy: { 56 redundancy: {
52 videos: { 57 videos: {
53 check_interval: '5 seconds', 58 check_interval: '5 seconds',
@@ -85,7 +90,7 @@ async function runServers (strategy: VideoRedundancyStrategy, additionalParams:
85 await waitJobs(servers) 90 await waitJobs(servers)
86} 91}
87 92
88async function check1WebSeed (strategy: VideoRedundancyStrategy, videoUUID?: string) { 93async function check1WebSeed (videoUUID?: string) {
89 if (!videoUUID) videoUUID = video1Server2UUID 94 if (!videoUUID) videoUUID = video1Server2UUID
90 95
91 const webseeds = [ 96 const webseeds = [
@@ -93,47 +98,17 @@ async function check1WebSeed (strategy: VideoRedundancyStrategy, videoUUID?: str
93 ] 98 ]
94 99
95 for (const server of servers) { 100 for (const server of servers) {
96 { 101 // With token to avoid issues with video follow constraints
97 // With token to avoid issues with video follow constraints 102 const res = await getVideoWithToken(server.url, server.accessToken, videoUUID)
98 const res = await getVideoWithToken(server.url, server.accessToken, videoUUID)
99 103
100 const video: VideoDetails = res.body 104 const video: VideoDetails = res.body
101 for (const f of video.files) { 105 for (const f of video.files) {
102 checkMagnetWebseeds(f, webseeds, server) 106 checkMagnetWebseeds(f, webseeds, server)
103 }
104 } 107 }
105 } 108 }
106} 109}
107 110
108async function checkStatsWith2Webseed (strategy: VideoRedundancyStrategy) { 111async function check2Webseeds (videoUUID?: string) {
109 const res = await getStats(servers[0].url)
110 const data: ServerStats = res.body
111
112 expect(data.videosRedundancy).to.have.lengthOf(1)
113 const stat = data.videosRedundancy[0]
114
115 expect(stat.strategy).to.equal(strategy)
116 expect(stat.totalSize).to.equal(204800)
117 expect(stat.totalUsed).to.be.at.least(1).and.below(204801)
118 expect(stat.totalVideoFiles).to.equal(4)
119 expect(stat.totalVideos).to.equal(1)
120}
121
122async function checkStatsWith1Webseed (strategy: VideoRedundancyStrategy) {
123 const res = await getStats(servers[0].url)
124 const data: ServerStats = res.body
125
126 expect(data.videosRedundancy).to.have.lengthOf(1)
127
128 const stat = data.videosRedundancy[0]
129 expect(stat.strategy).to.equal(strategy)
130 expect(stat.totalSize).to.equal(204800)
131 expect(stat.totalUsed).to.equal(0)
132 expect(stat.totalVideoFiles).to.equal(0)
133 expect(stat.totalVideos).to.equal(0)
134}
135
136async function check2Webseeds (strategy: VideoRedundancyStrategy, videoUUID?: string) {
137 if (!videoUUID) videoUUID = video1Server2UUID 112 if (!videoUUID) videoUUID = video1Server2UUID
138 113
139 const webseeds = [ 114 const webseeds = [
@@ -158,7 +133,7 @@ async function check2Webseeds (strategy: VideoRedundancyStrategy, videoUUID?: st
158 await makeGetRequest({ 133 await makeGetRequest({
159 url: servers[1].url, 134 url: servers[1].url,
160 statusCodeExpected: 200, 135 statusCodeExpected: 200,
161 path: '/static/webseed/' + `${videoUUID}-${file.resolution.id}.mp4`, 136 path: `/static/webseed/${videoUUID}-${file.resolution.id}.mp4`,
162 contentType: null 137 contentType: null
163 }) 138 })
164 } 139 }
@@ -174,6 +149,85 @@ async function check2Webseeds (strategy: VideoRedundancyStrategy, videoUUID?: st
174 } 149 }
175} 150}
176 151
152async function check0PlaylistRedundancies (videoUUID?: string) {
153 if (!videoUUID) videoUUID = video1Server2UUID
154
155 for (const server of servers) {
156 // With token to avoid issues with video follow constraints
157 const res = await getVideoWithToken(server.url, server.accessToken, videoUUID)
158 const video: VideoDetails = res.body
159
160 expect(video.streamingPlaylists).to.be.an('array')
161 expect(video.streamingPlaylists).to.have.lengthOf(1)
162 expect(video.streamingPlaylists[0].redundancies).to.have.lengthOf(0)
163 }
164}
165
166async function check1PlaylistRedundancies (videoUUID?: string) {
167 if (!videoUUID) videoUUID = video1Server2UUID
168
169 for (const server of servers) {
170 const res = await getVideo(server.url, videoUUID)
171 const video: VideoDetails = res.body
172
173 expect(video.streamingPlaylists).to.have.lengthOf(1)
174 expect(video.streamingPlaylists[0].redundancies).to.have.lengthOf(1)
175
176 const redundancy = video.streamingPlaylists[0].redundancies[0]
177
178 expect(redundancy.baseUrl).to.equal(servers[0].url + '/static/redundancy/hls/' + videoUUID)
179 }
180
181 const baseUrlPlaylist = servers[1].url + '/static/playlists/hls'
182 const baseUrlSegment = servers[0].url + '/static/redundancy/hls'
183
184 const res = await getVideo(servers[0].url, videoUUID)
185 const hlsPlaylist = (res.body as VideoDetails).streamingPlaylists[0]
186
187 for (const resolution of [ 240, 360, 480, 720 ]) {
188 await checkSegmentHash(baseUrlPlaylist, baseUrlSegment, videoUUID, resolution, hlsPlaylist)
189 }
190
191 for (const directory of [ 'test1/redundancy/hls', 'test2/playlists/hls' ]) {
192 const files = await readdir(join(root(), directory, videoUUID))
193 expect(files).to.have.length.at.least(4)
194
195 for (const resolution of [ 240, 360, 480, 720 ]) {
196 const filename = `${videoUUID}-${resolution}-fragmented.mp4`
197
198 expect(files.find(f => f === filename)).to.not.be.undefined
199 }
200 }
201}
202
203async function checkStatsWith2Webseed (strategy: VideoRedundancyStrategy) {
204 const res = await getStats(servers[0].url)
205 const data: ServerStats = res.body
206
207 expect(data.videosRedundancy).to.have.lengthOf(1)
208 const stat = data.videosRedundancy[0]
209
210 expect(stat.strategy).to.equal(strategy)
211 expect(stat.totalSize).to.equal(204800)
212 expect(stat.totalUsed).to.be.at.least(1).and.below(204801)
213 expect(stat.totalVideoFiles).to.equal(4)
214 expect(stat.totalVideos).to.equal(1)
215}
216
217async function checkStatsWith1Webseed (strategy: VideoRedundancyStrategy) {
218 const res = await getStats(servers[0].url)
219 const data: ServerStats = res.body
220
221 expect(data.videosRedundancy).to.have.lengthOf(1)
222
223 const stat = data.videosRedundancy[0]
224 expect(stat.strategy).to.equal(strategy)
225 expect(stat.totalSize).to.equal(204800)
226 expect(stat.totalUsed).to.equal(0)
227 expect(stat.totalVideoFiles).to.equal(0)
228 expect(stat.totalVideos).to.equal(0)
229}
230
177async function enableRedundancyOnServer1 () { 231async function enableRedundancyOnServer1 () {
178 await updateRedundancy(servers[ 0 ].url, servers[ 0 ].accessToken, servers[ 1 ].host, true) 232 await updateRedundancy(servers[ 0 ].url, servers[ 0 ].accessToken, servers[ 1 ].host, true)
179 233
@@ -220,7 +274,8 @@ describe('Test videos redundancy', function () {
220 }) 274 })
221 275
222 it('Should have 1 webseed on the first video', async function () { 276 it('Should have 1 webseed on the first video', async function () {
223 await check1WebSeed(strategy) 277 await check1WebSeed()
278 await check0PlaylistRedundancies()
224 await checkStatsWith1Webseed(strategy) 279 await checkStatsWith1Webseed(strategy)
225 }) 280 })
226 281
@@ -229,27 +284,29 @@ describe('Test videos redundancy', function () {
229 }) 284 })
230 285
231 it('Should have 2 webseeds on the first video', async function () { 286 it('Should have 2 webseeds on the first video', async function () {
232 this.timeout(40000) 287 this.timeout(80000)
233 288
234 await waitJobs(servers) 289 await waitJobs(servers)
235 await waitUntilLog(servers[0], 'Duplicated ', 4) 290 await waitUntilLog(servers[0], 'Duplicated ', 5)
236 await waitJobs(servers) 291 await waitJobs(servers)
237 292
238 await check2Webseeds(strategy) 293 await check2Webseeds()
294 await check1PlaylistRedundancies()
239 await checkStatsWith2Webseed(strategy) 295 await checkStatsWith2Webseed(strategy)
240 }) 296 })
241 297
242 it('Should undo redundancy on server 1 and remove duplicated videos', async function () { 298 it('Should undo redundancy on server 1 and remove duplicated videos', async function () {
243 this.timeout(40000) 299 this.timeout(80000)
244 300
245 await disableRedundancyOnServer1() 301 await disableRedundancyOnServer1()
246 302
247 await waitJobs(servers) 303 await waitJobs(servers)
248 await wait(5000) 304 await wait(5000)
249 305
250 await check1WebSeed(strategy) 306 await check1WebSeed()
307 await check0PlaylistRedundancies()
251 308
252 await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ 'videos' ]) 309 await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ 'videos', join('playlists', 'hls') ])
253 }) 310 })
254 311
255 after(function () { 312 after(function () {
@@ -267,7 +324,8 @@ describe('Test videos redundancy', function () {
267 }) 324 })
268 325
269 it('Should have 1 webseed on the first video', async function () { 326 it('Should have 1 webseed on the first video', async function () {
270 await check1WebSeed(strategy) 327 await check1WebSeed()
328 await check0PlaylistRedundancies()
271 await checkStatsWith1Webseed(strategy) 329 await checkStatsWith1Webseed(strategy)
272 }) 330 })
273 331
@@ -276,25 +334,27 @@ describe('Test videos redundancy', function () {
276 }) 334 })
277 335
278 it('Should have 2 webseeds on the first video', async function () { 336 it('Should have 2 webseeds on the first video', async function () {
279 this.timeout(40000) 337 this.timeout(80000)
280 338
281 await waitJobs(servers) 339 await waitJobs(servers)
282 await waitUntilLog(servers[0], 'Duplicated ', 4) 340 await waitUntilLog(servers[0], 'Duplicated ', 5)
283 await waitJobs(servers) 341 await waitJobs(servers)
284 342
285 await check2Webseeds(strategy) 343 await check2Webseeds()
344 await check1PlaylistRedundancies()
286 await checkStatsWith2Webseed(strategy) 345 await checkStatsWith2Webseed(strategy)
287 }) 346 })
288 347
289 it('Should unfollow on server 1 and remove duplicated videos', async function () { 348 it('Should unfollow on server 1 and remove duplicated videos', async function () {
290 this.timeout(40000) 349 this.timeout(80000)
291 350
292 await unfollow(servers[0].url, servers[0].accessToken, servers[1]) 351 await unfollow(servers[0].url, servers[0].accessToken, servers[1])
293 352
294 await waitJobs(servers) 353 await waitJobs(servers)
295 await wait(5000) 354 await wait(5000)
296 355
297 await check1WebSeed(strategy) 356 await check1WebSeed()
357 await check0PlaylistRedundancies()
298 358
299 await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ 'videos' ]) 359 await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ 'videos' ])
300 }) 360 })
@@ -314,7 +374,8 @@ describe('Test videos redundancy', function () {
314 }) 374 })
315 375
316 it('Should have 1 webseed on the first video', async function () { 376 it('Should have 1 webseed on the first video', async function () {
317 await check1WebSeed(strategy) 377 await check1WebSeed()
378 await check0PlaylistRedundancies()
318 await checkStatsWith1Webseed(strategy) 379 await checkStatsWith1Webseed(strategy)
319 }) 380 })
320 381
@@ -323,18 +384,19 @@ describe('Test videos redundancy', function () {
323 }) 384 })
324 385
325 it('Should still have 1 webseed on the first video', async function () { 386 it('Should still have 1 webseed on the first video', async function () {
326 this.timeout(40000) 387 this.timeout(80000)
327 388
328 await waitJobs(servers) 389 await waitJobs(servers)
329 await wait(15000) 390 await wait(15000)
330 await waitJobs(servers) 391 await waitJobs(servers)
331 392
332 await check1WebSeed(strategy) 393 await check1WebSeed()
394 await check0PlaylistRedundancies()
333 await checkStatsWith1Webseed(strategy) 395 await checkStatsWith1Webseed(strategy)
334 }) 396 })
335 397
336 it('Should view 2 times the first video to have > min_views config', async function () { 398 it('Should view 2 times the first video to have > min_views config', async function () {
337 this.timeout(40000) 399 this.timeout(80000)
338 400
339 await viewVideo(servers[ 0 ].url, video1Server2UUID) 401 await viewVideo(servers[ 0 ].url, video1Server2UUID)
340 await viewVideo(servers[ 2 ].url, video1Server2UUID) 402 await viewVideo(servers[ 2 ].url, video1Server2UUID)
@@ -344,13 +406,14 @@ describe('Test videos redundancy', function () {
344 }) 406 })
345 407
346 it('Should have 2 webseeds on the first video', async function () { 408 it('Should have 2 webseeds on the first video', async function () {
347 this.timeout(40000) 409 this.timeout(80000)
348 410
349 await waitJobs(servers) 411 await waitJobs(servers)
350 await waitUntilLog(servers[0], 'Duplicated ', 4) 412 await waitUntilLog(servers[0], 'Duplicated ', 5)
351 await waitJobs(servers) 413 await waitJobs(servers)
352 414
353 await check2Webseeds(strategy) 415 await check2Webseeds()
416 await check1PlaylistRedundancies()
354 await checkStatsWith2Webseed(strategy) 417 await checkStatsWith2Webseed(strategy)
355 }) 418 })
356 419
@@ -405,7 +468,7 @@ describe('Test videos redundancy', function () {
405 }) 468 })
406 469
407 it('Should still have 2 webseeds after 10 seconds', async function () { 470 it('Should still have 2 webseeds after 10 seconds', async function () {
408 this.timeout(40000) 471 this.timeout(80000)
409 472
410 await wait(10000) 473 await wait(10000)
411 474
@@ -420,7 +483,7 @@ describe('Test videos redundancy', function () {
420 }) 483 })
421 484
422 it('Should stop server 1 and expire video redundancy', async function () { 485 it('Should stop server 1 and expire video redundancy', async function () {
423 this.timeout(40000) 486 this.timeout(80000)
424 487
425 killallServers([ servers[0] ]) 488 killallServers([ servers[0] ])
426 489
@@ -446,10 +509,11 @@ describe('Test videos redundancy', function () {
446 await enableRedundancyOnServer1() 509 await enableRedundancyOnServer1()
447 510
448 await waitJobs(servers) 511 await waitJobs(servers)
449 await waitUntilLog(servers[0], 'Duplicated ', 4) 512 await waitUntilLog(servers[0], 'Duplicated ', 5)
450 await waitJobs(servers) 513 await waitJobs(servers)
451 514
452 await check2Webseeds(strategy) 515 await check2Webseeds()
516 await check1PlaylistRedundancies()
453 await checkStatsWith2Webseed(strategy) 517 await checkStatsWith2Webseed(strategy)
454 518
455 const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, { name: 'video 2 server 2' }) 519 const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, { name: 'video 2 server 2' })
@@ -467,8 +531,10 @@ describe('Test videos redundancy', function () {
467 await wait(1000) 531 await wait(1000)
468 532
469 try { 533 try {
470 await check1WebSeed(strategy, video1Server2UUID) 534 await check1WebSeed(video1Server2UUID)
471 await check2Webseeds(strategy, video2Server2UUID) 535 await check0PlaylistRedundancies(video1Server2UUID)
536 await check2Webseeds(video2Server2UUID)
537 await check1PlaylistRedundancies(video2Server2UUID)
472 538
473 checked = true 539 checked = true
474 } catch { 540 } catch {
@@ -477,6 +543,26 @@ describe('Test videos redundancy', function () {
477 } 543 }
478 }) 544 })
479 545
546 it('Should disable strategy and remove redundancies', async function () {
547 this.timeout(80000)
548
549 await waitJobs(servers)
550
551 killallServers([ servers[ 0 ] ])
552 await reRunServer(servers[ 0 ], {
553 redundancy: {
554 videos: {
555 check_interval: '1 second',
556 strategies: []
557 }
558 }
559 })
560
561 await waitJobs(servers)
562
563 await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ join('redundancy', 'hls') ])
564 })
565
480 after(function () { 566 after(function () {
481 return cleanServers() 567 return cleanServers()
482 }) 568 })