]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
26370ce4 | 2 | |
26370ce4 | 3 | import 'mocha' |
6949a1a1 C |
4 | import * as chai from 'chai' |
5 | import { readdir } from 'fs-extra' | |
6 | import * as magnetUtil from 'magnet-uri' | |
7 | import { join } from 'path' | |
dab04709 C |
8 | import { removeVideoRedundancy } from '@server/lib/redundancy' |
9 | import { HttpStatusCode } from '@shared/core-utils' | |
26370ce4 | 10 | import { |
07b1a18a | 11 | checkSegmentHash, |
b764380a C |
12 | checkVideoFilesWereRemoved, |
13 | cleanupTests, | |
26370ce4 C |
14 | doubleFollow, |
15 | flushAndRunMultipleServers, | |
26370ce4 | 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 | 25 | setAccessTokensToServers, |
5e8dd6e0 | 26 | updateVideo, |
26370ce4 C |
27 | uploadVideo, |
28 | viewVideo, | |
29 | wait, | |
dab04709 | 30 | waitJobs, |
07b1a18a | 31 | waitUntilLog |
dab04709 C |
32 | } from '@shared/extra-utils' |
33 | import { getStats } from '@shared/extra-utils/server/stats' | |
b764380a | 34 | import { |
dab04709 C |
35 | ServerStats, |
36 | VideoDetails, | |
37 | VideoPrivacy, | |
38 | VideoRedundancy, | |
39 | VideoRedundancyStrategy, | |
40 | VideoRedundancyStrategyWithManual | |
41 | } from '@shared/models' | |
26370ce4 C |
42 | |
43 | const expect = chai.expect | |
44 | ||
45 | let servers: ServerInfo[] = [] | |
46 | let video1Server2UUID: string | |
b764380a | 47 | let video1Server2Id: number |
26370ce4 C |
48 | |
49 | function checkMagnetWebseeds (file: { magnetUri: string, resolution: { id: number } }, baseWebseeds: string[], server: ServerInfo) { | |
50 | const parsed = magnetUtil.decode(file.magnetUri) | |
51 | ||
52 | for (const ws of baseWebseeds) { | |
53 | const found = parsed.urlList.find(url => url === `${ws}-${file.resolution.id}.mp4`) | |
54 | expect(found, `Webseed ${ws} not found in ${file.magnetUri} on server ${server.url}`).to.not.be.undefined | |
55 | } | |
56 | ||
57 | expect(parsed.urlList).to.have.lengthOf(baseWebseeds.length) | |
58 | } | |
59 | ||
7448551f | 60 | async function flushAndRunServers (strategy: VideoRedundancyStrategy | null, additionalParams: any = {}, withWebtorrent = true) { |
b764380a C |
61 | const strategies: any[] = [] |
62 | ||
63 | if (strategy !== null) { | |
64 | strategies.push( | |
65 | immutableAssign({ | |
66 | min_lifetime: '1 hour', | |
67 | strategy: strategy, | |
68 | size: '400KB' | |
69 | }, additionalParams) | |
70 | ) | |
71 | } | |
72 | ||
26370ce4 | 73 | const config = { |
09209296 | 74 | transcoding: { |
7448551f C |
75 | webtorrent: { |
76 | enabled: withWebtorrent | |
77 | }, | |
09209296 C |
78 | hls: { |
79 | enabled: true | |
80 | } | |
81 | }, | |
26370ce4 C |
82 | redundancy: { |
83 | videos: { | |
84 | check_interval: '5 seconds', | |
b764380a | 85 | strategies |
26370ce4 C |
86 | } |
87 | } | |
88 | } | |
b764380a | 89 | |
26370ce4 C |
90 | servers = await flushAndRunMultipleServers(3, config) |
91 | ||
92 | // Get the access tokens | |
93 | await setAccessTokensToServers(servers) | |
94 | ||
95 | { | |
a1587156 | 96 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' }) |
26370ce4 | 97 | video1Server2UUID = res.body.video.uuid |
b764380a | 98 | video1Server2Id = res.body.video.id |
26370ce4 | 99 | |
a1587156 | 100 | await viewVideo(servers[1].url, video1Server2UUID) |
26370ce4 C |
101 | } |
102 | ||
103 | await waitJobs(servers) | |
104 | ||
105 | // Server 1 and server 2 follow each other | |
a1587156 | 106 | await doubleFollow(servers[0], servers[1]) |
26370ce4 | 107 | // Server 1 and server 3 follow each other |
a1587156 | 108 | await doubleFollow(servers[0], servers[2]) |
26370ce4 | 109 | // Server 2 and server 3 follow each other |
a1587156 | 110 | await doubleFollow(servers[1], servers[2]) |
26370ce4 C |
111 | |
112 | await waitJobs(servers) | |
113 | } | |
114 | ||
09209296 | 115 | async function check1WebSeed (videoUUID?: string) { |
26370ce4 C |
116 | if (!videoUUID) videoUUID = video1Server2UUID |
117 | ||
118 | const webseeds = [ | |
a1587156 | 119 | `http://localhost:${servers[1].port}/static/webseed/${videoUUID}` |
26370ce4 C |
120 | ] |
121 | ||
122 | for (const server of servers) { | |
09209296 C |
123 | // With token to avoid issues with video follow constraints |
124 | const res = await getVideoWithToken(server.url, server.accessToken, videoUUID) | |
26370ce4 | 125 | |
09209296 C |
126 | const video: VideoDetails = res.body |
127 | for (const f of video.files) { | |
128 | checkMagnetWebseeds(f, webseeds, server) | |
26370ce4 C |
129 | } |
130 | } | |
131 | } | |
132 | ||
09209296 | 133 | async function check2Webseeds (videoUUID?: string) { |
26370ce4 C |
134 | if (!videoUUID) videoUUID = video1Server2UUID |
135 | ||
136 | const webseeds = [ | |
a1587156 C |
137 | `http://localhost:${servers[0].port}/static/redundancy/${videoUUID}`, |
138 | `http://localhost:${servers[1].port}/static/webseed/${videoUUID}` | |
26370ce4 C |
139 | ] |
140 | ||
141 | for (const server of servers) { | |
142 | const res = await getVideo(server.url, videoUUID) | |
143 | ||
144 | const video: VideoDetails = res.body | |
145 | ||
146 | for (const file of video.files) { | |
147 | checkMagnetWebseeds(file, webseeds, server) | |
148 | ||
b9fffa29 C |
149 | await makeGetRequest({ |
150 | url: servers[0].url, | |
2d53be02 | 151 | statusCodeExpected: HttpStatusCode.OK_200, |
b9fffa29 C |
152 | path: '/static/redundancy/' + `${videoUUID}-${file.resolution.id}.mp4`, |
153 | contentType: null | |
154 | }) | |
155 | await makeGetRequest({ | |
156 | url: servers[1].url, | |
2d53be02 | 157 | statusCodeExpected: HttpStatusCode.OK_200, |
09209296 | 158 | path: `/static/webseed/${videoUUID}-${file.resolution.id}.mp4`, |
b9fffa29 C |
159 | contentType: null |
160 | }) | |
26370ce4 C |
161 | } |
162 | } | |
163 | ||
7243f84d C |
164 | const directories = [ |
165 | 'test' + servers[0].internalServerNumber + '/redundancy', | |
166 | 'test' + servers[1].internalServerNumber + '/videos' | |
167 | ] | |
168 | ||
169 | for (const directory of directories) { | |
b9fffa29 | 170 | const files = await readdir(join(root(), directory)) |
26370ce4 C |
171 | expect(files).to.have.length.at.least(4) |
172 | ||
173 | for (const resolution of [ 240, 360, 480, 720 ]) { | |
174 | expect(files.find(f => f === `${videoUUID}-${resolution}.mp4`)).to.not.be.undefined | |
175 | } | |
176 | } | |
177 | } | |
178 | ||
09209296 C |
179 | async function check0PlaylistRedundancies (videoUUID?: string) { |
180 | if (!videoUUID) videoUUID = video1Server2UUID | |
181 | ||
182 | for (const server of servers) { | |
183 | // With token to avoid issues with video follow constraints | |
184 | const res = await getVideoWithToken(server.url, server.accessToken, videoUUID) | |
185 | const video: VideoDetails = res.body | |
186 | ||
187 | expect(video.streamingPlaylists).to.be.an('array') | |
188 | expect(video.streamingPlaylists).to.have.lengthOf(1) | |
189 | expect(video.streamingPlaylists[0].redundancies).to.have.lengthOf(0) | |
190 | } | |
191 | } | |
192 | ||
193 | async function check1PlaylistRedundancies (videoUUID?: string) { | |
194 | if (!videoUUID) videoUUID = video1Server2UUID | |
195 | ||
196 | for (const server of servers) { | |
197 | const res = await getVideo(server.url, videoUUID) | |
198 | const video: VideoDetails = res.body | |
199 | ||
200 | expect(video.streamingPlaylists).to.have.lengthOf(1) | |
201 | expect(video.streamingPlaylists[0].redundancies).to.have.lengthOf(1) | |
202 | ||
203 | const redundancy = video.streamingPlaylists[0].redundancies[0] | |
204 | ||
205 | expect(redundancy.baseUrl).to.equal(servers[0].url + '/static/redundancy/hls/' + videoUUID) | |
206 | } | |
207 | ||
0b16f5f2 | 208 | const baseUrlPlaylist = servers[1].url + '/static/streaming-playlists/hls' |
4c280004 C |
209 | const baseUrlSegment = servers[0].url + '/static/redundancy/hls' |
210 | ||
211 | const res = await getVideo(servers[0].url, videoUUID) | |
212 | const hlsPlaylist = (res.body as VideoDetails).streamingPlaylists[0] | |
213 | ||
214 | for (const resolution of [ 240, 360, 480, 720 ]) { | |
215 | await checkSegmentHash(baseUrlPlaylist, baseUrlSegment, videoUUID, resolution, hlsPlaylist) | |
216 | } | |
09209296 | 217 | |
7243f84d C |
218 | const directories = [ |
219 | 'test' + servers[0].internalServerNumber + '/redundancy/hls', | |
220 | 'test' + servers[1].internalServerNumber + '/streaming-playlists/hls' | |
221 | ] | |
222 | ||
223 | for (const directory of directories) { | |
09209296 C |
224 | const files = await readdir(join(root(), directory, videoUUID)) |
225 | expect(files).to.have.length.at.least(4) | |
226 | ||
227 | for (const resolution of [ 240, 360, 480, 720 ]) { | |
4c280004 C |
228 | const filename = `${videoUUID}-${resolution}-fragmented.mp4` |
229 | ||
230 | expect(files.find(f => f === filename)).to.not.be.undefined | |
09209296 C |
231 | } |
232 | } | |
233 | } | |
234 | ||
b764380a C |
235 | async function checkStatsGlobal (strategy: VideoRedundancyStrategyWithManual) { |
236 | let totalSize: number = null | |
237 | let statsLength = 1 | |
238 | ||
239 | if (strategy !== 'manual') { | |
240 | totalSize = 409600 | |
241 | statsLength = 2 | |
242 | } | |
243 | ||
09209296 C |
244 | const res = await getStats(servers[0].url) |
245 | const data: ServerStats = res.body | |
246 | ||
b764380a | 247 | expect(data.videosRedundancy).to.have.lengthOf(statsLength) |
09209296 | 248 | |
b764380a | 249 | const stat = data.videosRedundancy[0] |
09209296 | 250 | expect(stat.strategy).to.equal(strategy) |
b764380a C |
251 | expect(stat.totalSize).to.equal(totalSize) |
252 | ||
253 | return stat | |
254 | } | |
255 | ||
6949a1a1 | 256 | async function checkStatsWith1Redundancy (strategy: VideoRedundancyStrategyWithManual, onlyHls = false) { |
b764380a C |
257 | const stat = await checkStatsGlobal(strategy) |
258 | ||
9e3e3617 | 259 | expect(stat.totalUsed).to.be.at.least(1).and.below(409601) |
6949a1a1 | 260 | expect(stat.totalVideoFiles).to.equal(onlyHls ? 4 : 8) |
09209296 C |
261 | expect(stat.totalVideos).to.equal(1) |
262 | } | |
263 | ||
7448551f | 264 | async function checkStatsWithoutRedundancy (strategy: VideoRedundancyStrategyWithManual) { |
b764380a | 265 | const stat = await checkStatsGlobal(strategy) |
09209296 | 266 | |
09209296 C |
267 | expect(stat.totalUsed).to.equal(0) |
268 | expect(stat.totalVideoFiles).to.equal(0) | |
269 | expect(stat.totalVideos).to.equal(0) | |
270 | } | |
271 | ||
c3d29f69 C |
272 | async function findServerFollows () { |
273 | const body = await servers[0].followsCommand.getFollowings({ start: 0, count: 5, sort: '-createdAt' }) | |
274 | const follows = body.data | |
275 | const server2 = follows.find(f => f.following.host === `localhost:${servers[1].port}`) | |
276 | const server3 = follows.find(f => f.following.host === `localhost:${servers[2].port}`) | |
277 | ||
278 | return { server2, server3 } | |
279 | } | |
280 | ||
26370ce4 | 281 | async function enableRedundancyOnServer1 () { |
dab04709 | 282 | await servers[0].redundancyCommand.updateRedundancy({ host: servers[1].host, redundancyAllowed: true }) |
26370ce4 | 283 | |
c3d29f69 | 284 | const { server2, server3 } = await findServerFollows() |
26370ce4 C |
285 | |
286 | expect(server3).to.not.be.undefined | |
287 | expect(server3.following.hostRedundancyAllowed).to.be.false | |
288 | ||
289 | expect(server2).to.not.be.undefined | |
290 | expect(server2.following.hostRedundancyAllowed).to.be.true | |
291 | } | |
292 | ||
293 | async function disableRedundancyOnServer1 () { | |
dab04709 | 294 | await servers[0].redundancyCommand.updateRedundancy({ host: servers[1].host, redundancyAllowed: false }) |
26370ce4 | 295 | |
c3d29f69 | 296 | const { server2, server3 } = await findServerFollows() |
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 |
305 | describe('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 | 390 | |
c3d29f69 | 391 | await servers[0].followsCommand.unfollow({ target: servers[1] }) |
26370ce4 C |
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 () { | |
dab04709 | 554 | await servers[0].redundancyCommand.addVideo({ videoId: video1Server2Id }) |
b764380a C |
555 | }) |
556 | ||
557 | it('Should have 2 webseeds on the first video', async function () { | |
558 | this.timeout(80000) | |
559 | ||
560 | await waitJobs(servers) | |
561 | await waitUntilLog(servers[0], 'Duplicated ', 5) | |
562 | await waitJobs(servers) | |
563 | ||
564 | await check2Webseeds() | |
565 | await check1PlaylistRedundancies() | |
7448551f | 566 | await checkStatsWith1Redundancy('manual') |
b764380a C |
567 | }) |
568 | ||
569 | it('Should manually remove redundancies on server 1 and remove duplicated videos', async function () { | |
570 | this.timeout(80000) | |
571 | ||
dab04709 | 572 | const body = await servers[0].redundancyCommand.listVideos({ target: 'remote-videos' }) |
b764380a | 573 | |
dab04709 | 574 | const videos = body.data |
b764380a C |
575 | expect(videos).to.have.lengthOf(1) |
576 | ||
577 | const video = videos[0] | |
dab04709 | 578 | |
b764380a | 579 | for (const r of video.redundancies.files.concat(video.redundancies.streamingPlaylists)) { |
dab04709 | 580 | await servers[0].redundancyCommand.removeVideo({ redundancyId: r.id }) |
b764380a C |
581 | } |
582 | ||
583 | await waitJobs(servers) | |
584 | await wait(5000) | |
585 | ||
586 | await check1WebSeed() | |
587 | await check0PlaylistRedundancies() | |
588 | ||
589 | await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ 'videos' ]) | |
590 | }) | |
591 | ||
592 | after(async function () { | |
593 | await cleanupTests(servers) | |
594 | }) | |
595 | }) | |
596 | ||
26370ce4 C |
597 | describe('Test expiration', function () { |
598 | const strategy = 'recently-added' | |
599 | ||
600 | async function checkContains (servers: ServerInfo[], str: string) { | |
601 | for (const server of servers) { | |
602 | const res = await getVideo(server.url, video1Server2UUID) | |
603 | const video: VideoDetails = res.body | |
604 | ||
605 | for (const f of video.files) { | |
606 | expect(f.magnetUri).to.contain(str) | |
607 | } | |
608 | } | |
609 | } | |
610 | ||
611 | async function checkNotContains (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.not.contain(str) | |
618 | } | |
619 | } | |
620 | } | |
621 | ||
622 | before(async function () { | |
623 | this.timeout(120000) | |
624 | ||
7c3b7976 | 625 | await flushAndRunServers(strategy, { min_lifetime: '7 seconds', min_views: 0 }) |
26370ce4 C |
626 | |
627 | await enableRedundancyOnServer1() | |
628 | }) | |
629 | ||
630 | it('Should still have 2 webseeds after 10 seconds', async function () { | |
09209296 | 631 | this.timeout(80000) |
26370ce4 C |
632 | |
633 | await wait(10000) | |
634 | ||
635 | try { | |
7243f84d | 636 | await checkContains(servers, 'http%3A%2F%2Flocalhost%3A' + servers[0].port) |
26370ce4 C |
637 | } catch { |
638 | // Maybe a server deleted a redundancy in the scheduler | |
639 | await wait(2000) | |
640 | ||
7243f84d | 641 | await checkContains(servers, 'http%3A%2F%2Flocalhost%3A' + servers[0].port) |
26370ce4 C |
642 | } |
643 | }) | |
644 | ||
645 | it('Should stop server 1 and expire video redundancy', async function () { | |
09209296 | 646 | this.timeout(80000) |
26370ce4 C |
647 | |
648 | killallServers([ servers[0] ]) | |
649 | ||
6cb3482c | 650 | await wait(15000) |
26370ce4 | 651 | |
7243f84d | 652 | await checkNotContains([ servers[1], servers[2] ], 'http%3A%2F%2Flocalhost%3A' + servers[0].port) |
26370ce4 C |
653 | }) |
654 | ||
7c3b7976 C |
655 | after(async function () { |
656 | await cleanupTests(servers) | |
26370ce4 C |
657 | }) |
658 | }) | |
659 | ||
660 | describe('Test file replacement', function () { | |
661 | let video2Server2UUID: string | |
662 | const strategy = 'recently-added' | |
663 | ||
664 | before(async function () { | |
665 | this.timeout(120000) | |
666 | ||
7c3b7976 | 667 | await flushAndRunServers(strategy, { min_lifetime: '7 seconds', min_views: 0 }) |
26370ce4 C |
668 | |
669 | await enableRedundancyOnServer1() | |
670 | ||
671 | await waitJobs(servers) | |
09209296 | 672 | await waitUntilLog(servers[0], 'Duplicated ', 5) |
26370ce4 C |
673 | await waitJobs(servers) |
674 | ||
5e8dd6e0 C |
675 | await check2Webseeds(video1Server2UUID) |
676 | await check1PlaylistRedundancies(video1Server2UUID) | |
7448551f | 677 | await checkStatsWith1Redundancy(strategy) |
26370ce4 | 678 | |
5e8dd6e0 | 679 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 2 server 2', privacy: VideoPrivacy.PRIVATE }) |
26370ce4 | 680 | video2Server2UUID = res.body.video.uuid |
5e8dd6e0 C |
681 | |
682 | // Wait transcoding before federation | |
683 | await waitJobs(servers) | |
684 | ||
685 | await updateVideo(servers[1].url, servers[1].accessToken, video2Server2UUID, { privacy: VideoPrivacy.PUBLIC }) | |
26370ce4 C |
686 | }) |
687 | ||
6cb3482c C |
688 | it('Should cache video 2 webseeds on the first video', async function () { |
689 | this.timeout(120000) | |
26370ce4 C |
690 | |
691 | await waitJobs(servers) | |
692 | ||
6cb3482c | 693 | let checked = false |
26370ce4 | 694 | |
6cb3482c C |
695 | while (checked === false) { |
696 | await wait(1000) | |
26370ce4 C |
697 | |
698 | try { | |
09209296 C |
699 | await check1WebSeed(video1Server2UUID) |
700 | await check0PlaylistRedundancies(video1Server2UUID) | |
5e8dd6e0 | 701 | |
09209296 C |
702 | await check2Webseeds(video2Server2UUID) |
703 | await check1PlaylistRedundancies(video2Server2UUID) | |
26370ce4 | 704 | |
6cb3482c C |
705 | checked = true |
706 | } catch { | |
707 | checked = false | |
26370ce4 C |
708 | } |
709 | } | |
710 | }) | |
711 | ||
09209296 C |
712 | it('Should disable strategy and remove redundancies', async function () { |
713 | this.timeout(80000) | |
714 | ||
715 | await waitJobs(servers) | |
716 | ||
a1587156 C |
717 | killallServers([ servers[0] ]) |
718 | await reRunServer(servers[0], { | |
09209296 C |
719 | redundancy: { |
720 | videos: { | |
721 | check_interval: '1 second', | |
722 | strategies: [] | |
723 | } | |
724 | } | |
725 | }) | |
726 | ||
727 | await waitJobs(servers) | |
728 | ||
ffc65cbd | 729 | await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].internalServerNumber, [ join('redundancy', 'hls') ]) |
09209296 C |
730 | }) |
731 | ||
7c3b7976 C |
732 | after(async function () { |
733 | await cleanupTests(servers) | |
26370ce4 C |
734 | }) |
735 | }) | |
736 | }) |