]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/redundancy/redundancy.ts
fix missing title attribute on <iframe> tag suggested for embedding (#3901)
[github/Chocobozzz/PeerTube.git] / server / tests / api / redundancy / redundancy.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
26370ce4 2
26370ce4 3import 'mocha'
6949a1a1
C
4import * as chai from 'chai'
5import { readdir } from 'fs-extra'
6import * as magnetUtil from 'magnet-uri'
7import { join } from 'path'
8import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
26370ce4 9import {
07b1a18a 10 checkSegmentHash,
b764380a
C
11 checkVideoFilesWereRemoved,
12 cleanupTests,
26370ce4
C
13 doubleFollow,
14 flushAndRunMultipleServers,
15 getFollowingListPaginationAndSort,
16 getVideo,
07b1a18a 17 getVideoWithToken,
26370ce4 18 immutableAssign,
07b1a18a
C
19 killallServers,
20 makeGetRequest,
21 removeVideo,
22 reRunServer,
26370ce4
C
23 root,
24 ServerInfo,
07b1a18a
C
25 setAccessTokensToServers,
26 unfollow,
5e8dd6e0 27 updateVideo,
26370ce4
C
28 uploadVideo,
29 viewVideo,
30 wait,
07b1a18a 31 waitUntilLog
94565d52
C
32} from '../../../../shared/extra-utils'
33import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
b764380a
C
34import {
35 addVideoRedundancy,
36 listVideoRedundancies,
37 removeVideoRedundancy,
38 updateRedundancy
39} from '../../../../shared/extra-utils/server/redundancy'
6949a1a1 40import { getStats } from '../../../../shared/extra-utils/server/stats'
26370ce4 41import { ActorFollow } from '../../../../shared/models/actors'
b764380a 42import { VideoRedundancy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '../../../../shared/models/redundancy'
26370ce4 43import { ServerStats } from '../../../../shared/models/server/server-stats.model'
5e8dd6e0 44import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos'
26370ce4
C
45
46const expect = chai.expect
47
48let servers: ServerInfo[] = []
49let video1Server2UUID: string
b764380a 50let video1Server2Id: number
26370ce4
C
51
52function checkMagnetWebseeds (file: { magnetUri: string, resolution: { id: number } }, baseWebseeds: string[], server: ServerInfo) {
53 const parsed = magnetUtil.decode(file.magnetUri)
54
55 for (const ws of baseWebseeds) {
56 const found = parsed.urlList.find(url => url === `${ws}-${file.resolution.id}.mp4`)
57 expect(found, `Webseed ${ws} not found in ${file.magnetUri} on server ${server.url}`).to.not.be.undefined
58 }
59
60 expect(parsed.urlList).to.have.lengthOf(baseWebseeds.length)
61}
62
7448551f 63async function flushAndRunServers (strategy: VideoRedundancyStrategy | null, additionalParams: any = {}, withWebtorrent = true) {
b764380a
C
64 const strategies: any[] = []
65
66 if (strategy !== null) {
67 strategies.push(
68 immutableAssign({
69 min_lifetime: '1 hour',
70 strategy: strategy,
71 size: '400KB'
72 }, additionalParams)
73 )
74 }
75
26370ce4 76 const config = {
09209296 77 transcoding: {
7448551f
C
78 webtorrent: {
79 enabled: withWebtorrent
80 },
09209296
C
81 hls: {
82 enabled: true
83 }
84 },
26370ce4
C
85 redundancy: {
86 videos: {
87 check_interval: '5 seconds',
b764380a 88 strategies
26370ce4
C
89 }
90 }
91 }
b764380a 92
26370ce4
C
93 servers = await flushAndRunMultipleServers(3, config)
94
95 // Get the access tokens
96 await setAccessTokensToServers(servers)
97
98 {
a1587156 99 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' })
26370ce4 100 video1Server2UUID = res.body.video.uuid
b764380a 101 video1Server2Id = res.body.video.id
26370ce4 102
a1587156 103 await viewVideo(servers[1].url, video1Server2UUID)
26370ce4
C
104 }
105
106 await waitJobs(servers)
107
108 // Server 1 and server 2 follow each other
a1587156 109 await doubleFollow(servers[0], servers[1])
26370ce4 110 // Server 1 and server 3 follow each other
a1587156 111 await doubleFollow(servers[0], servers[2])
26370ce4 112 // Server 2 and server 3 follow each other
a1587156 113 await doubleFollow(servers[1], servers[2])
26370ce4
C
114
115 await waitJobs(servers)
116}
117
09209296 118async function check1WebSeed (videoUUID?: string) {
26370ce4
C
119 if (!videoUUID) videoUUID = video1Server2UUID
120
121 const webseeds = [
a1587156 122 `http://localhost:${servers[1].port}/static/webseed/${videoUUID}`
26370ce4
C
123 ]
124
125 for (const server of servers) {
09209296
C
126 // With token to avoid issues with video follow constraints
127 const res = await getVideoWithToken(server.url, server.accessToken, videoUUID)
26370ce4 128
09209296
C
129 const video: VideoDetails = res.body
130 for (const f of video.files) {
131 checkMagnetWebseeds(f, webseeds, server)
26370ce4
C
132 }
133 }
134}
135
09209296 136async function check2Webseeds (videoUUID?: string) {
26370ce4
C
137 if (!videoUUID) videoUUID = video1Server2UUID
138
139 const webseeds = [
a1587156
C
140 `http://localhost:${servers[0].port}/static/redundancy/${videoUUID}`,
141 `http://localhost:${servers[1].port}/static/webseed/${videoUUID}`
26370ce4
C
142 ]
143
144 for (const server of servers) {
145 const res = await getVideo(server.url, videoUUID)
146
147 const video: VideoDetails = res.body
148
149 for (const file of video.files) {
150 checkMagnetWebseeds(file, webseeds, server)
151
b9fffa29
C
152 await makeGetRequest({
153 url: servers[0].url,
2d53be02 154 statusCodeExpected: HttpStatusCode.OK_200,
b9fffa29
C
155 path: '/static/redundancy/' + `${videoUUID}-${file.resolution.id}.mp4`,
156 contentType: null
157 })
158 await makeGetRequest({
159 url: servers[1].url,
2d53be02 160 statusCodeExpected: HttpStatusCode.OK_200,
09209296 161 path: `/static/webseed/${videoUUID}-${file.resolution.id}.mp4`,
b9fffa29
C
162 contentType: null
163 })
26370ce4
C
164 }
165 }
166
7243f84d
C
167 const directories = [
168 'test' + servers[0].internalServerNumber + '/redundancy',
169 'test' + servers[1].internalServerNumber + '/videos'
170 ]
171
172 for (const directory of directories) {
b9fffa29 173 const files = await readdir(join(root(), directory))
26370ce4
C
174 expect(files).to.have.length.at.least(4)
175
176 for (const resolution of [ 240, 360, 480, 720 ]) {
177 expect(files.find(f => f === `${videoUUID}-${resolution}.mp4`)).to.not.be.undefined
178 }
179 }
180}
181
09209296
C
182async function check0PlaylistRedundancies (videoUUID?: string) {
183 if (!videoUUID) videoUUID = video1Server2UUID
184
185 for (const server of servers) {
186 // With token to avoid issues with video follow constraints
187 const res = await getVideoWithToken(server.url, server.accessToken, videoUUID)
188 const video: VideoDetails = res.body
189
190 expect(video.streamingPlaylists).to.be.an('array')
191 expect(video.streamingPlaylists).to.have.lengthOf(1)
192 expect(video.streamingPlaylists[0].redundancies).to.have.lengthOf(0)
193 }
194}
195
196async function check1PlaylistRedundancies (videoUUID?: string) {
197 if (!videoUUID) videoUUID = video1Server2UUID
198
199 for (const server of servers) {
200 const res = await getVideo(server.url, videoUUID)
201 const video: VideoDetails = res.body
202
203 expect(video.streamingPlaylists).to.have.lengthOf(1)
204 expect(video.streamingPlaylists[0].redundancies).to.have.lengthOf(1)
205
206 const redundancy = video.streamingPlaylists[0].redundancies[0]
207
208 expect(redundancy.baseUrl).to.equal(servers[0].url + '/static/redundancy/hls/' + videoUUID)
209 }
210
0b16f5f2 211 const baseUrlPlaylist = servers[1].url + '/static/streaming-playlists/hls'
4c280004
C
212 const baseUrlSegment = servers[0].url + '/static/redundancy/hls'
213
214 const res = await getVideo(servers[0].url, videoUUID)
215 const hlsPlaylist = (res.body as VideoDetails).streamingPlaylists[0]
216
217 for (const resolution of [ 240, 360, 480, 720 ]) {
218 await checkSegmentHash(baseUrlPlaylist, baseUrlSegment, videoUUID, resolution, hlsPlaylist)
219 }
09209296 220
7243f84d
C
221 const directories = [
222 'test' + servers[0].internalServerNumber + '/redundancy/hls',
223 'test' + servers[1].internalServerNumber + '/streaming-playlists/hls'
224 ]
225
226 for (const directory of directories) {
09209296
C
227 const files = await readdir(join(root(), directory, videoUUID))
228 expect(files).to.have.length.at.least(4)
229
230 for (const resolution of [ 240, 360, 480, 720 ]) {
4c280004
C
231 const filename = `${videoUUID}-${resolution}-fragmented.mp4`
232
233 expect(files.find(f => f === filename)).to.not.be.undefined
09209296
C
234 }
235 }
236}
237
b764380a
C
238async function checkStatsGlobal (strategy: VideoRedundancyStrategyWithManual) {
239 let totalSize: number = null
240 let statsLength = 1
241
242 if (strategy !== 'manual') {
243 totalSize = 409600
244 statsLength = 2
245 }
246
09209296
C
247 const res = await getStats(servers[0].url)
248 const data: ServerStats = res.body
249
b764380a 250 expect(data.videosRedundancy).to.have.lengthOf(statsLength)
09209296 251
b764380a 252 const stat = data.videosRedundancy[0]
09209296 253 expect(stat.strategy).to.equal(strategy)
b764380a
C
254 expect(stat.totalSize).to.equal(totalSize)
255
256 return stat
257}
258
6949a1a1 259async function checkStatsWith1Redundancy (strategy: VideoRedundancyStrategyWithManual, onlyHls = false) {
b764380a
C
260 const stat = await checkStatsGlobal(strategy)
261
9e3e3617 262 expect(stat.totalUsed).to.be.at.least(1).and.below(409601)
6949a1a1 263 expect(stat.totalVideoFiles).to.equal(onlyHls ? 4 : 8)
09209296
C
264 expect(stat.totalVideos).to.equal(1)
265}
266
7448551f 267async function checkStatsWithoutRedundancy (strategy: VideoRedundancyStrategyWithManual) {
b764380a 268 const stat = await checkStatsGlobal(strategy)
09209296 269
09209296
C
270 expect(stat.totalUsed).to.equal(0)
271 expect(stat.totalVideoFiles).to.equal(0)
272 expect(stat.totalVideos).to.equal(0)
273}
274
26370ce4 275async function enableRedundancyOnServer1 () {
a1587156 276 await updateRedundancy(servers[0].url, servers[0].accessToken, servers[1].host, true)
26370ce4 277
a1587156 278 const res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 5, sort: '-createdAt' })
26370ce4 279 const follows: ActorFollow[] = res.body.data
a1587156
C
280 const server2 = follows.find(f => f.following.host === `localhost:${servers[1].port}`)
281 const server3 = follows.find(f => f.following.host === `localhost:${servers[2].port}`)
26370ce4
C
282
283 expect(server3).to.not.be.undefined
284 expect(server3.following.hostRedundancyAllowed).to.be.false
285
286 expect(server2).to.not.be.undefined
287 expect(server2.following.hostRedundancyAllowed).to.be.true
288}
289
290async function disableRedundancyOnServer1 () {
a1587156 291 await updateRedundancy(servers[0].url, servers[0].accessToken, servers[1].host, false)
26370ce4 292
a1587156 293 const res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 5, sort: '-createdAt' })
26370ce4 294 const follows: ActorFollow[] = res.body.data
a1587156
C
295 const server2 = follows.find(f => f.following.host === `localhost:${servers[1].port}`)
296 const server3 = follows.find(f => f.following.host === `localhost:${servers[2].port}`)
26370ce4
C
297
298 expect(server3).to.not.be.undefined
299 expect(server3.following.hostRedundancyAllowed).to.be.false
300
301 expect(server2).to.not.be.undefined
302 expect(server2.following.hostRedundancyAllowed).to.be.false
303}
304
26370ce4
C
305describe('Test videos redundancy', function () {
306
307 describe('With most-views strategy', function () {
308 const strategy = 'most-views'
309
310 before(function () {
311 this.timeout(120000)
312
7c3b7976 313 return flushAndRunServers(strategy)
26370ce4
C
314 })
315
316 it('Should have 1 webseed on the first video', async function () {
09209296
C
317 await check1WebSeed()
318 await check0PlaylistRedundancies()
7448551f 319 await checkStatsWithoutRedundancy(strategy)
26370ce4
C
320 })
321
322 it('Should enable redundancy on server 1', function () {
323 return enableRedundancyOnServer1()
324 })
325
6cb3482c 326 it('Should have 2 webseeds on the first video', async function () {
09209296 327 this.timeout(80000)
26370ce4
C
328
329 await waitJobs(servers)
09209296 330 await waitUntilLog(servers[0], 'Duplicated ', 5)
26370ce4
C
331 await waitJobs(servers)
332
09209296
C
333 await check2Webseeds()
334 await check1PlaylistRedundancies()
7448551f 335 await checkStatsWith1Redundancy(strategy)
26370ce4
C
336 })
337
338 it('Should undo redundancy on server 1 and remove duplicated videos', async function () {
09209296 339 this.timeout(80000)
26370ce4
C
340
341 await disableRedundancyOnServer1()
342
343 await waitJobs(servers)
344 await wait(5000)
345
09209296
C
346 await check1WebSeed()
347 await check0PlaylistRedundancies()
26370ce4 348
ffc65cbd 349 await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].internalServerNumber, [ 'videos', join('playlists', 'hls') ])
26370ce4
C
350 })
351
7c3b7976
C
352 after(async function () {
353 return cleanupTests(servers)
26370ce4
C
354 })
355 })
356
357 describe('With trending strategy', function () {
358 const strategy = 'trending'
359
360 before(function () {
361 this.timeout(120000)
362
7c3b7976 363 return flushAndRunServers(strategy)
26370ce4
C
364 })
365
366 it('Should have 1 webseed on the first video', async function () {
09209296
C
367 await check1WebSeed()
368 await check0PlaylistRedundancies()
7448551f 369 await checkStatsWithoutRedundancy(strategy)
26370ce4
C
370 })
371
372 it('Should enable redundancy on server 1', function () {
373 return enableRedundancyOnServer1()
374 })
375
6cb3482c 376 it('Should have 2 webseeds on the first video', async function () {
09209296 377 this.timeout(80000)
26370ce4
C
378
379 await waitJobs(servers)
09209296 380 await waitUntilLog(servers[0], 'Duplicated ', 5)
26370ce4
C
381 await waitJobs(servers)
382
09209296
C
383 await check2Webseeds()
384 await check1PlaylistRedundancies()
7448551f 385 await checkStatsWith1Redundancy(strategy)
26370ce4
C
386 })
387
388 it('Should unfollow on server 1 and remove duplicated videos', async function () {
09209296 389 this.timeout(80000)
26370ce4
C
390
391 await unfollow(servers[0].url, servers[0].accessToken, servers[1])
392
393 await waitJobs(servers)
394 await wait(5000)
395
09209296
C
396 await check1WebSeed()
397 await check0PlaylistRedundancies()
26370ce4 398
ffc65cbd 399 await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].internalServerNumber, [ 'videos' ])
26370ce4
C
400 })
401
7c3b7976
C
402 after(async function () {
403 await cleanupTests(servers)
26370ce4
C
404 })
405 })
406
407 describe('With recently added strategy', function () {
408 const strategy = 'recently-added'
409
410 before(function () {
411 this.timeout(120000)
412
7c3b7976 413 return flushAndRunServers(strategy, { min_views: 3 })
26370ce4
C
414 })
415
416 it('Should have 1 webseed on the first video', async function () {
09209296
C
417 await check1WebSeed()
418 await check0PlaylistRedundancies()
7448551f 419 await checkStatsWithoutRedundancy(strategy)
26370ce4
C
420 })
421
422 it('Should enable redundancy on server 1', function () {
423 return enableRedundancyOnServer1()
424 })
425
426 it('Should still have 1 webseed on the first video', async function () {
09209296 427 this.timeout(80000)
26370ce4
C
428
429 await waitJobs(servers)
430 await wait(15000)
431 await waitJobs(servers)
432
09209296
C
433 await check1WebSeed()
434 await check0PlaylistRedundancies()
7448551f 435 await checkStatsWithoutRedundancy(strategy)
26370ce4
C
436 })
437
438 it('Should view 2 times the first video to have > min_views config', async function () {
09209296 439 this.timeout(80000)
26370ce4 440
a1587156
C
441 await viewVideo(servers[0].url, video1Server2UUID)
442 await viewVideo(servers[2].url, video1Server2UUID)
26370ce4
C
443
444 await wait(10000)
445 await waitJobs(servers)
446 })
447
6cb3482c 448 it('Should have 2 webseeds on the first video', async function () {
09209296 449 this.timeout(80000)
26370ce4
C
450
451 await waitJobs(servers)
09209296 452 await waitUntilLog(servers[0], 'Duplicated ', 5)
26370ce4
C
453 await waitJobs(servers)
454
09209296
C
455 await check2Webseeds()
456 await check1PlaylistRedundancies()
7448551f 457 await checkStatsWith1Redundancy(strategy)
26370ce4
C
458 })
459
460 it('Should remove the video and the redundancy files', async function () {
461 this.timeout(20000)
462
463 await removeVideo(servers[1].url, servers[1].accessToken, video1Server2UUID)
464
465 await waitJobs(servers)
466
467 for (const server of servers) {
ffc65cbd 468 await checkVideoFilesWereRemoved(video1Server2UUID, server.internalServerNumber)
26370ce4
C
469 }
470 })
471
7c3b7976
C
472 after(async function () {
473 await cleanupTests(servers)
26370ce4
C
474 })
475 })
476
7448551f
C
477 describe('With only HLS files', function () {
478 const strategy = 'recently-added'
479
480 before(async function () {
481 this.timeout(120000)
482
483 await flushAndRunServers(strategy, { min_views: 3 }, false)
484 })
485
486 it('Should have 0 playlist redundancy on the first video', async function () {
487 await check1WebSeed()
488 await check0PlaylistRedundancies()
489 })
490
491 it('Should enable redundancy on server 1', function () {
492 return enableRedundancyOnServer1()
493 })
494
495 it('Should still have 0 redundancy on the first video', async function () {
496 this.timeout(80000)
497
498 await waitJobs(servers)
499 await wait(15000)
500 await waitJobs(servers)
501
502 await check0PlaylistRedundancies()
503 await checkStatsWithoutRedundancy(strategy)
504 })
505
506 it('Should have 1 redundancy on the first video', async function () {
507 this.timeout(160000)
508
509 await viewVideo(servers[0].url, video1Server2UUID)
510 await viewVideo(servers[2].url, video1Server2UUID)
511
512 await wait(10000)
513 await waitJobs(servers)
514
515 await waitJobs(servers)
516 await waitUntilLog(servers[0], 'Duplicated ', 1)
517 await waitJobs(servers)
518
519 await check1PlaylistRedundancies()
6949a1a1 520 await checkStatsWith1Redundancy(strategy, true)
7448551f
C
521 })
522
523 it('Should remove the video and the redundancy files', async function () {
524 this.timeout(20000)
525
526 await removeVideo(servers[1].url, servers[1].accessToken, video1Server2UUID)
527
528 await waitJobs(servers)
529
530 for (const server of servers) {
531 await checkVideoFilesWereRemoved(video1Server2UUID, server.internalServerNumber)
532 }
533 })
6949a1a1
C
534
535 after(async function () {
536 await cleanupTests(servers)
537 })
7448551f
C
538 })
539
b764380a
C
540 describe('With manual strategy', function () {
541 before(function () {
542 this.timeout(120000)
543
544 return flushAndRunServers(null)
545 })
546
547 it('Should have 1 webseed on the first video', async function () {
548 await check1WebSeed()
549 await check0PlaylistRedundancies()
7448551f 550 await checkStatsWithoutRedundancy('manual')
b764380a
C
551 })
552
553 it('Should create a redundancy on first video', async function () {
554 await addVideoRedundancy({
555 url: servers[0].url,
556 accessToken: servers[0].accessToken,
557 videoId: video1Server2Id
558 })
559 })
560
561 it('Should have 2 webseeds on the first video', async function () {
562 this.timeout(80000)
563
564 await waitJobs(servers)
565 await waitUntilLog(servers[0], 'Duplicated ', 5)
566 await waitJobs(servers)
567
568 await check2Webseeds()
569 await check1PlaylistRedundancies()
7448551f 570 await checkStatsWith1Redundancy('manual')
b764380a
C
571 })
572
573 it('Should manually remove redundancies on server 1 and remove duplicated videos', async function () {
574 this.timeout(80000)
575
576 const res = await listVideoRedundancies({
577 url: servers[0].url,
578 accessToken: servers[0].accessToken,
579 target: 'remote-videos'
580 })
581
582 const videos = res.body.data as VideoRedundancy[]
583 expect(videos).to.have.lengthOf(1)
584
585 const video = videos[0]
586 for (const r of video.redundancies.files.concat(video.redundancies.streamingPlaylists)) {
587 await removeVideoRedundancy({
588 url: servers[0].url,
589 accessToken: servers[0].accessToken,
590 redundancyId: r.id
591 })
592 }
593
594 await waitJobs(servers)
595 await wait(5000)
596
597 await check1WebSeed()
598 await check0PlaylistRedundancies()
599
600 await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ 'videos' ])
601 })
602
603 after(async function () {
604 await cleanupTests(servers)
605 })
606 })
607
26370ce4
C
608 describe('Test expiration', function () {
609 const strategy = 'recently-added'
610
611 async function checkContains (servers: ServerInfo[], str: string) {
612 for (const server of servers) {
613 const res = await getVideo(server.url, video1Server2UUID)
614 const video: VideoDetails = res.body
615
616 for (const f of video.files) {
617 expect(f.magnetUri).to.contain(str)
618 }
619 }
620 }
621
622 async function checkNotContains (servers: ServerInfo[], str: string) {
623 for (const server of servers) {
624 const res = await getVideo(server.url, video1Server2UUID)
625 const video: VideoDetails = res.body
626
627 for (const f of video.files) {
628 expect(f.magnetUri).to.not.contain(str)
629 }
630 }
631 }
632
633 before(async function () {
634 this.timeout(120000)
635
7c3b7976 636 await flushAndRunServers(strategy, { min_lifetime: '7 seconds', min_views: 0 })
26370ce4
C
637
638 await enableRedundancyOnServer1()
639 })
640
641 it('Should still have 2 webseeds after 10 seconds', async function () {
09209296 642 this.timeout(80000)
26370ce4
C
643
644 await wait(10000)
645
646 try {
7243f84d 647 await checkContains(servers, 'http%3A%2F%2Flocalhost%3A' + servers[0].port)
26370ce4
C
648 } catch {
649 // Maybe a server deleted a redundancy in the scheduler
650 await wait(2000)
651
7243f84d 652 await checkContains(servers, 'http%3A%2F%2Flocalhost%3A' + servers[0].port)
26370ce4
C
653 }
654 })
655
656 it('Should stop server 1 and expire video redundancy', async function () {
09209296 657 this.timeout(80000)
26370ce4
C
658
659 killallServers([ servers[0] ])
660
6cb3482c 661 await wait(15000)
26370ce4 662
7243f84d 663 await checkNotContains([ servers[1], servers[2] ], 'http%3A%2F%2Flocalhost%3A' + servers[0].port)
26370ce4
C
664 })
665
7c3b7976
C
666 after(async function () {
667 await cleanupTests(servers)
26370ce4
C
668 })
669 })
670
671 describe('Test file replacement', function () {
672 let video2Server2UUID: string
673 const strategy = 'recently-added'
674
675 before(async function () {
676 this.timeout(120000)
677
7c3b7976 678 await flushAndRunServers(strategy, { min_lifetime: '7 seconds', min_views: 0 })
26370ce4
C
679
680 await enableRedundancyOnServer1()
681
682 await waitJobs(servers)
09209296 683 await waitUntilLog(servers[0], 'Duplicated ', 5)
26370ce4
C
684 await waitJobs(servers)
685
5e8dd6e0
C
686 await check2Webseeds(video1Server2UUID)
687 await check1PlaylistRedundancies(video1Server2UUID)
7448551f 688 await checkStatsWith1Redundancy(strategy)
26370ce4 689
5e8dd6e0 690 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 2 server 2', privacy: VideoPrivacy.PRIVATE })
26370ce4 691 video2Server2UUID = res.body.video.uuid
5e8dd6e0
C
692
693 // Wait transcoding before federation
694 await waitJobs(servers)
695
696 await updateVideo(servers[1].url, servers[1].accessToken, video2Server2UUID, { privacy: VideoPrivacy.PUBLIC })
26370ce4
C
697 })
698
6cb3482c
C
699 it('Should cache video 2 webseeds on the first video', async function () {
700 this.timeout(120000)
26370ce4
C
701
702 await waitJobs(servers)
703
6cb3482c 704 let checked = false
26370ce4 705
6cb3482c
C
706 while (checked === false) {
707 await wait(1000)
26370ce4
C
708
709 try {
09209296
C
710 await check1WebSeed(video1Server2UUID)
711 await check0PlaylistRedundancies(video1Server2UUID)
5e8dd6e0 712
09209296
C
713 await check2Webseeds(video2Server2UUID)
714 await check1PlaylistRedundancies(video2Server2UUID)
26370ce4 715
6cb3482c
C
716 checked = true
717 } catch {
718 checked = false
26370ce4
C
719 }
720 }
721 })
722
09209296
C
723 it('Should disable strategy and remove redundancies', async function () {
724 this.timeout(80000)
725
726 await waitJobs(servers)
727
a1587156
C
728 killallServers([ servers[0] ])
729 await reRunServer(servers[0], {
09209296
C
730 redundancy: {
731 videos: {
732 check_interval: '1 second',
733 strategies: []
734 }
735 }
736 })
737
738 await waitJobs(servers)
739
ffc65cbd 740 await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].internalServerNumber, [ join('redundancy', 'hls') ])
09209296
C
741 })
742
7c3b7976
C
743 after(async function () {
744 await cleanupTests(servers)
26370ce4
C
745 })
746 })
747})