diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-21 15:51:30 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-21 15:51:30 +0200 |
commit | a24bd1ed41b43790bab6ba789580bb4e85f07d85 (patch) | |
tree | a54b0f6c921ba83a6e909cd0ced325b2d4b8863c /server/tests/api/redundancy/redundancy.ts | |
parent | 5f26f13b3c16ac5ae0a3b0a7142d84a9528cf565 (diff) | |
parent | c63830f15403ac4e750829f27d8bbbdc9a59282c (diff) | |
download | PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.gz PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.zst PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.zip |
Merge branch 'next' into develop
Diffstat (limited to 'server/tests/api/redundancy/redundancy.ts')
-rw-r--r-- | server/tests/api/redundancy/redundancy.ts | 201 |
1 files changed, 82 insertions, 119 deletions
diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index 0e0a73b9d..a6559d304 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts | |||
@@ -5,51 +5,29 @@ import * as chai from 'chai' | |||
5 | import { readdir } from 'fs-extra' | 5 | import { readdir } from 'fs-extra' |
6 | import * as magnetUtil from 'magnet-uri' | 6 | import * as magnetUtil from 'magnet-uri' |
7 | import { join } from 'path' | 7 | import { join } from 'path' |
8 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
9 | import { | 8 | import { |
10 | checkSegmentHash, | 9 | checkSegmentHash, |
11 | checkVideoFilesWereRemoved, | 10 | checkVideoFilesWereRemoved, |
12 | cleanupTests, | 11 | cleanupTests, |
12 | createMultipleServers, | ||
13 | doubleFollow, | 13 | doubleFollow, |
14 | flushAndRunMultipleServers, | ||
15 | getFollowingListPaginationAndSort, | ||
16 | getVideo, | ||
17 | getVideoWithToken, | ||
18 | immutableAssign, | ||
19 | killallServers, | 14 | killallServers, |
20 | makeGetRequest, | 15 | makeGetRequest, |
21 | removeVideo, | 16 | PeerTubeServer, |
22 | reRunServer, | ||
23 | root, | 17 | root, |
24 | ServerInfo, | ||
25 | setAccessTokensToServers, | 18 | setAccessTokensToServers, |
26 | unfollow, | ||
27 | updateVideo, | ||
28 | uploadVideo, | ||
29 | viewVideo, | ||
30 | wait, | 19 | wait, |
31 | waitUntilLog | 20 | waitJobs |
32 | } from '../../../../shared/extra-utils' | 21 | } from '@shared/extra-utils' |
33 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | 22 | import { HttpStatusCode, VideoPrivacy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '@shared/models' |
34 | import { | ||
35 | addVideoRedundancy, | ||
36 | listVideoRedundancies, | ||
37 | removeVideoRedundancy, | ||
38 | updateRedundancy | ||
39 | } from '../../../../shared/extra-utils/server/redundancy' | ||
40 | import { getStats } from '../../../../shared/extra-utils/server/stats' | ||
41 | import { ActorFollow } from '../../../../shared/models/actors' | ||
42 | import { VideoRedundancy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '../../../../shared/models/redundancy' | ||
43 | import { ServerStats } from '../../../../shared/models/server/server-stats.model' | ||
44 | import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos' | ||
45 | 23 | ||
46 | const expect = chai.expect | 24 | const expect = chai.expect |
47 | 25 | ||
48 | let servers: ServerInfo[] = [] | 26 | let servers: PeerTubeServer[] = [] |
49 | let video1Server2UUID: string | 27 | let video1Server2UUID: string |
50 | let video1Server2Id: number | 28 | let video1Server2Id: number |
51 | 29 | ||
52 | function checkMagnetWebseeds (file: { magnetUri: string, resolution: { id: number } }, baseWebseeds: string[], server: ServerInfo) { | 30 | function checkMagnetWebseeds (file: { magnetUri: string, resolution: { id: number } }, baseWebseeds: string[], server: PeerTubeServer) { |
53 | const parsed = magnetUtil.decode(file.magnetUri) | 31 | const parsed = magnetUtil.decode(file.magnetUri) |
54 | 32 | ||
55 | for (const ws of baseWebseeds) { | 33 | for (const ws of baseWebseeds) { |
@@ -60,16 +38,18 @@ function checkMagnetWebseeds (file: { magnetUri: string, resolution: { id: numbe | |||
60 | expect(parsed.urlList).to.have.lengthOf(baseWebseeds.length) | 38 | expect(parsed.urlList).to.have.lengthOf(baseWebseeds.length) |
61 | } | 39 | } |
62 | 40 | ||
63 | async function flushAndRunServers (strategy: VideoRedundancyStrategy | null, additionalParams: any = {}, withWebtorrent = true) { | 41 | async function createSingleServers (strategy: VideoRedundancyStrategy | null, additionalParams: any = {}, withWebtorrent = true) { |
64 | const strategies: any[] = [] | 42 | const strategies: any[] = [] |
65 | 43 | ||
66 | if (strategy !== null) { | 44 | if (strategy !== null) { |
67 | strategies.push( | 45 | strategies.push( |
68 | immutableAssign({ | 46 | { |
69 | min_lifetime: '1 hour', | 47 | min_lifetime: '1 hour', |
70 | strategy: strategy, | 48 | strategy: strategy, |
71 | size: '400KB' | 49 | size: '400KB', |
72 | }, additionalParams) | 50 | |
51 | ...additionalParams | ||
52 | } | ||
73 | ) | 53 | ) |
74 | } | 54 | } |
75 | 55 | ||
@@ -90,17 +70,17 @@ async function flushAndRunServers (strategy: VideoRedundancyStrategy | null, add | |||
90 | } | 70 | } |
91 | } | 71 | } |
92 | 72 | ||
93 | servers = await flushAndRunMultipleServers(3, config) | 73 | servers = await createMultipleServers(3, config) |
94 | 74 | ||
95 | // Get the access tokens | 75 | // Get the access tokens |
96 | await setAccessTokensToServers(servers) | 76 | await setAccessTokensToServers(servers) |
97 | 77 | ||
98 | { | 78 | { |
99 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' }) | 79 | const { uuid, id } = await servers[1].videos.upload({ attributes: { name: 'video 1 server 2' } }) |
100 | video1Server2UUID = res.body.video.uuid | 80 | video1Server2UUID = uuid |
101 | video1Server2Id = res.body.video.id | 81 | video1Server2Id = id |
102 | 82 | ||
103 | await viewVideo(servers[1].url, video1Server2UUID) | 83 | await servers[1].videos.view({ id: video1Server2UUID }) |
104 | } | 84 | } |
105 | 85 | ||
106 | await waitJobs(servers) | 86 | await waitJobs(servers) |
@@ -124,9 +104,8 @@ async function check1WebSeed (videoUUID?: string) { | |||
124 | 104 | ||
125 | for (const server of servers) { | 105 | for (const server of servers) { |
126 | // With token to avoid issues with video follow constraints | 106 | // With token to avoid issues with video follow constraints |
127 | const res = await getVideoWithToken(server.url, server.accessToken, videoUUID) | 107 | const video = await server.videos.getWithToken({ id: videoUUID }) |
128 | 108 | ||
129 | const video: VideoDetails = res.body | ||
130 | for (const f of video.files) { | 109 | for (const f of video.files) { |
131 | checkMagnetWebseeds(f, webseeds, server) | 110 | checkMagnetWebseeds(f, webseeds, server) |
132 | } | 111 | } |
@@ -142,22 +121,20 @@ async function check2Webseeds (videoUUID?: string) { | |||
142 | ] | 121 | ] |
143 | 122 | ||
144 | for (const server of servers) { | 123 | for (const server of servers) { |
145 | const res = await getVideo(server.url, videoUUID) | 124 | const video = await server.videos.get({ id: videoUUID }) |
146 | |||
147 | const video: VideoDetails = res.body | ||
148 | 125 | ||
149 | for (const file of video.files) { | 126 | for (const file of video.files) { |
150 | checkMagnetWebseeds(file, webseeds, server) | 127 | checkMagnetWebseeds(file, webseeds, server) |
151 | 128 | ||
152 | await makeGetRequest({ | 129 | await makeGetRequest({ |
153 | url: servers[0].url, | 130 | url: servers[0].url, |
154 | statusCodeExpected: HttpStatusCode.OK_200, | 131 | expectedStatus: HttpStatusCode.OK_200, |
155 | path: '/static/redundancy/' + `${videoUUID}-${file.resolution.id}.mp4`, | 132 | path: '/static/redundancy/' + `${videoUUID}-${file.resolution.id}.mp4`, |
156 | contentType: null | 133 | contentType: null |
157 | }) | 134 | }) |
158 | await makeGetRequest({ | 135 | await makeGetRequest({ |
159 | url: servers[1].url, | 136 | url: servers[1].url, |
160 | statusCodeExpected: HttpStatusCode.OK_200, | 137 | expectedStatus: HttpStatusCode.OK_200, |
161 | path: `/static/webseed/${videoUUID}-${file.resolution.id}.mp4`, | 138 | path: `/static/webseed/${videoUUID}-${file.resolution.id}.mp4`, |
162 | contentType: null | 139 | contentType: null |
163 | }) | 140 | }) |
@@ -184,8 +161,7 @@ async function check0PlaylistRedundancies (videoUUID?: string) { | |||
184 | 161 | ||
185 | for (const server of servers) { | 162 | for (const server of servers) { |
186 | // With token to avoid issues with video follow constraints | 163 | // With token to avoid issues with video follow constraints |
187 | const res = await getVideoWithToken(server.url, server.accessToken, videoUUID) | 164 | const video = await server.videos.getWithToken({ id: videoUUID }) |
188 | const video: VideoDetails = res.body | ||
189 | 165 | ||
190 | expect(video.streamingPlaylists).to.be.an('array') | 166 | expect(video.streamingPlaylists).to.be.an('array') |
191 | expect(video.streamingPlaylists).to.have.lengthOf(1) | 167 | expect(video.streamingPlaylists).to.have.lengthOf(1) |
@@ -197,8 +173,7 @@ async function check1PlaylistRedundancies (videoUUID?: string) { | |||
197 | if (!videoUUID) videoUUID = video1Server2UUID | 173 | if (!videoUUID) videoUUID = video1Server2UUID |
198 | 174 | ||
199 | for (const server of servers) { | 175 | for (const server of servers) { |
200 | const res = await getVideo(server.url, videoUUID) | 176 | const video = await server.videos.get({ id: videoUUID }) |
201 | const video: VideoDetails = res.body | ||
202 | 177 | ||
203 | expect(video.streamingPlaylists).to.have.lengthOf(1) | 178 | expect(video.streamingPlaylists).to.have.lengthOf(1) |
204 | expect(video.streamingPlaylists[0].redundancies).to.have.lengthOf(1) | 179 | expect(video.streamingPlaylists[0].redundancies).to.have.lengthOf(1) |
@@ -211,11 +186,11 @@ async function check1PlaylistRedundancies (videoUUID?: string) { | |||
211 | const baseUrlPlaylist = servers[1].url + '/static/streaming-playlists/hls' | 186 | const baseUrlPlaylist = servers[1].url + '/static/streaming-playlists/hls' |
212 | const baseUrlSegment = servers[0].url + '/static/redundancy/hls' | 187 | const baseUrlSegment = servers[0].url + '/static/redundancy/hls' |
213 | 188 | ||
214 | const res = await getVideo(servers[0].url, videoUUID) | 189 | const video = await servers[0].videos.get({ id: videoUUID }) |
215 | const hlsPlaylist = (res.body as VideoDetails).streamingPlaylists[0] | 190 | const hlsPlaylist = video.streamingPlaylists[0] |
216 | 191 | ||
217 | for (const resolution of [ 240, 360, 480, 720 ]) { | 192 | for (const resolution of [ 240, 360, 480, 720 ]) { |
218 | await checkSegmentHash(baseUrlPlaylist, baseUrlSegment, videoUUID, resolution, hlsPlaylist) | 193 | await checkSegmentHash({ server: servers[1], baseUrlPlaylist, baseUrlSegment, videoUUID, resolution, hlsPlaylist }) |
219 | } | 194 | } |
220 | 195 | ||
221 | const directories = [ | 196 | const directories = [ |
@@ -244,9 +219,7 @@ async function checkStatsGlobal (strategy: VideoRedundancyStrategyWithManual) { | |||
244 | statsLength = 2 | 219 | statsLength = 2 |
245 | } | 220 | } |
246 | 221 | ||
247 | const res = await getStats(servers[0].url) | 222 | const data = await servers[0].stats.get() |
248 | const data: ServerStats = res.body | ||
249 | |||
250 | expect(data.videosRedundancy).to.have.lengthOf(statsLength) | 223 | expect(data.videosRedundancy).to.have.lengthOf(statsLength) |
251 | 224 | ||
252 | const stat = data.videosRedundancy[0] | 225 | const stat = data.videosRedundancy[0] |
@@ -272,14 +245,20 @@ async function checkStatsWithoutRedundancy (strategy: VideoRedundancyStrategyWit | |||
272 | expect(stat.totalVideos).to.equal(0) | 245 | expect(stat.totalVideos).to.equal(0) |
273 | } | 246 | } |
274 | 247 | ||
275 | async function enableRedundancyOnServer1 () { | 248 | async function findServerFollows () { |
276 | await updateRedundancy(servers[0].url, servers[0].accessToken, servers[1].host, true) | 249 | const body = await servers[0].follows.getFollowings({ start: 0, count: 5, sort: '-createdAt' }) |
277 | 250 | const follows = body.data | |
278 | const res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 5, sort: '-createdAt' }) | ||
279 | const follows: ActorFollow[] = res.body.data | ||
280 | const server2 = follows.find(f => f.following.host === `localhost:${servers[1].port}`) | 251 | 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}`) | 252 | const server3 = follows.find(f => f.following.host === `localhost:${servers[2].port}`) |
282 | 253 | ||
254 | return { server2, server3 } | ||
255 | } | ||
256 | |||
257 | async function enableRedundancyOnServer1 () { | ||
258 | await servers[0].redundancy.updateRedundancy({ host: servers[1].host, redundancyAllowed: true }) | ||
259 | |||
260 | const { server2, server3 } = await findServerFollows() | ||
261 | |||
283 | expect(server3).to.not.be.undefined | 262 | expect(server3).to.not.be.undefined |
284 | expect(server3.following.hostRedundancyAllowed).to.be.false | 263 | expect(server3.following.hostRedundancyAllowed).to.be.false |
285 | 264 | ||
@@ -288,12 +267,9 @@ async function enableRedundancyOnServer1 () { | |||
288 | } | 267 | } |
289 | 268 | ||
290 | async function disableRedundancyOnServer1 () { | 269 | async function disableRedundancyOnServer1 () { |
291 | await updateRedundancy(servers[0].url, servers[0].accessToken, servers[1].host, false) | 270 | await servers[0].redundancy.updateRedundancy({ host: servers[1].host, redundancyAllowed: false }) |
292 | 271 | ||
293 | const res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 5, sort: '-createdAt' }) | 272 | const { server2, server3 } = await findServerFollows() |
294 | const follows: ActorFollow[] = res.body.data | ||
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}`) | ||
297 | 273 | ||
298 | expect(server3).to.not.be.undefined | 274 | expect(server3).to.not.be.undefined |
299 | expect(server3.following.hostRedundancyAllowed).to.be.false | 275 | expect(server3.following.hostRedundancyAllowed).to.be.false |
@@ -310,7 +286,7 @@ describe('Test videos redundancy', function () { | |||
310 | before(function () { | 286 | before(function () { |
311 | this.timeout(120000) | 287 | this.timeout(120000) |
312 | 288 | ||
313 | return flushAndRunServers(strategy) | 289 | return createSingleServers(strategy) |
314 | }) | 290 | }) |
315 | 291 | ||
316 | it('Should have 1 webseed on the first video', async function () { | 292 | it('Should have 1 webseed on the first video', async function () { |
@@ -327,7 +303,7 @@ describe('Test videos redundancy', function () { | |||
327 | this.timeout(80000) | 303 | this.timeout(80000) |
328 | 304 | ||
329 | await waitJobs(servers) | 305 | await waitJobs(servers) |
330 | await waitUntilLog(servers[0], 'Duplicated ', 5) | 306 | await servers[0].servers.waitUntilLog('Duplicated ', 5) |
331 | await waitJobs(servers) | 307 | await waitJobs(servers) |
332 | 308 | ||
333 | await check2Webseeds() | 309 | await check2Webseeds() |
@@ -346,7 +322,7 @@ describe('Test videos redundancy', function () { | |||
346 | await check1WebSeed() | 322 | await check1WebSeed() |
347 | await check0PlaylistRedundancies() | 323 | await check0PlaylistRedundancies() |
348 | 324 | ||
349 | await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].internalServerNumber, [ 'videos', join('playlists', 'hls') ]) | 325 | await checkVideoFilesWereRemoved(video1Server2UUID, servers[0], [ 'videos', join('playlists', 'hls') ]) |
350 | }) | 326 | }) |
351 | 327 | ||
352 | after(async function () { | 328 | after(async function () { |
@@ -360,7 +336,7 @@ describe('Test videos redundancy', function () { | |||
360 | before(function () { | 336 | before(function () { |
361 | this.timeout(120000) | 337 | this.timeout(120000) |
362 | 338 | ||
363 | return flushAndRunServers(strategy) | 339 | return createSingleServers(strategy) |
364 | }) | 340 | }) |
365 | 341 | ||
366 | it('Should have 1 webseed on the first video', async function () { | 342 | it('Should have 1 webseed on the first video', async function () { |
@@ -377,7 +353,7 @@ describe('Test videos redundancy', function () { | |||
377 | this.timeout(80000) | 353 | this.timeout(80000) |
378 | 354 | ||
379 | await waitJobs(servers) | 355 | await waitJobs(servers) |
380 | await waitUntilLog(servers[0], 'Duplicated ', 5) | 356 | await servers[0].servers.waitUntilLog('Duplicated ', 5) |
381 | await waitJobs(servers) | 357 | await waitJobs(servers) |
382 | 358 | ||
383 | await check2Webseeds() | 359 | await check2Webseeds() |
@@ -388,7 +364,7 @@ describe('Test videos redundancy', function () { | |||
388 | it('Should unfollow on server 1 and remove duplicated videos', async function () { | 364 | it('Should unfollow on server 1 and remove duplicated videos', async function () { |
389 | this.timeout(80000) | 365 | this.timeout(80000) |
390 | 366 | ||
391 | await unfollow(servers[0].url, servers[0].accessToken, servers[1]) | 367 | await servers[0].follows.unfollow({ target: servers[1] }) |
392 | 368 | ||
393 | await waitJobs(servers) | 369 | await waitJobs(servers) |
394 | await wait(5000) | 370 | await wait(5000) |
@@ -396,7 +372,7 @@ describe('Test videos redundancy', function () { | |||
396 | await check1WebSeed() | 372 | await check1WebSeed() |
397 | await check0PlaylistRedundancies() | 373 | await check0PlaylistRedundancies() |
398 | 374 | ||
399 | await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].internalServerNumber, [ 'videos' ]) | 375 | await checkVideoFilesWereRemoved(video1Server2UUID, servers[0], [ 'videos' ]) |
400 | }) | 376 | }) |
401 | 377 | ||
402 | after(async function () { | 378 | after(async function () { |
@@ -410,7 +386,7 @@ describe('Test videos redundancy', function () { | |||
410 | before(function () { | 386 | before(function () { |
411 | this.timeout(120000) | 387 | this.timeout(120000) |
412 | 388 | ||
413 | return flushAndRunServers(strategy, { min_views: 3 }) | 389 | return createSingleServers(strategy, { min_views: 3 }) |
414 | }) | 390 | }) |
415 | 391 | ||
416 | it('Should have 1 webseed on the first video', async function () { | 392 | it('Should have 1 webseed on the first video', async function () { |
@@ -438,8 +414,8 @@ describe('Test videos redundancy', function () { | |||
438 | it('Should view 2 times the first video to have > min_views config', async function () { | 414 | it('Should view 2 times the first video to have > min_views config', async function () { |
439 | this.timeout(80000) | 415 | this.timeout(80000) |
440 | 416 | ||
441 | await viewVideo(servers[0].url, video1Server2UUID) | 417 | await servers[0].videos.view({ id: video1Server2UUID }) |
442 | await viewVideo(servers[2].url, video1Server2UUID) | 418 | await servers[2].videos.view({ id: video1Server2UUID }) |
443 | 419 | ||
444 | await wait(10000) | 420 | await wait(10000) |
445 | await waitJobs(servers) | 421 | await waitJobs(servers) |
@@ -449,7 +425,7 @@ describe('Test videos redundancy', function () { | |||
449 | this.timeout(80000) | 425 | this.timeout(80000) |
450 | 426 | ||
451 | await waitJobs(servers) | 427 | await waitJobs(servers) |
452 | await waitUntilLog(servers[0], 'Duplicated ', 5) | 428 | await servers[0].servers.waitUntilLog('Duplicated ', 5) |
453 | await waitJobs(servers) | 429 | await waitJobs(servers) |
454 | 430 | ||
455 | await check2Webseeds() | 431 | await check2Webseeds() |
@@ -460,12 +436,12 @@ describe('Test videos redundancy', function () { | |||
460 | it('Should remove the video and the redundancy files', async function () { | 436 | it('Should remove the video and the redundancy files', async function () { |
461 | this.timeout(20000) | 437 | this.timeout(20000) |
462 | 438 | ||
463 | await removeVideo(servers[1].url, servers[1].accessToken, video1Server2UUID) | 439 | await servers[1].videos.remove({ id: video1Server2UUID }) |
464 | 440 | ||
465 | await waitJobs(servers) | 441 | await waitJobs(servers) |
466 | 442 | ||
467 | for (const server of servers) { | 443 | for (const server of servers) { |
468 | await checkVideoFilesWereRemoved(video1Server2UUID, server.internalServerNumber) | 444 | await checkVideoFilesWereRemoved(video1Server2UUID, server) |
469 | } | 445 | } |
470 | }) | 446 | }) |
471 | 447 | ||
@@ -480,7 +456,7 @@ describe('Test videos redundancy', function () { | |||
480 | before(async function () { | 456 | before(async function () { |
481 | this.timeout(120000) | 457 | this.timeout(120000) |
482 | 458 | ||
483 | await flushAndRunServers(strategy, { min_views: 3 }, false) | 459 | await createSingleServers(strategy, { min_views: 3 }, false) |
484 | }) | 460 | }) |
485 | 461 | ||
486 | it('Should have 0 playlist redundancy on the first video', async function () { | 462 | it('Should have 0 playlist redundancy on the first video', async function () { |
@@ -506,14 +482,14 @@ describe('Test videos redundancy', function () { | |||
506 | it('Should have 1 redundancy on the first video', async function () { | 482 | it('Should have 1 redundancy on the first video', async function () { |
507 | this.timeout(160000) | 483 | this.timeout(160000) |
508 | 484 | ||
509 | await viewVideo(servers[0].url, video1Server2UUID) | 485 | await servers[0].videos.view({ id: video1Server2UUID }) |
510 | await viewVideo(servers[2].url, video1Server2UUID) | 486 | await servers[2].videos.view({ id: video1Server2UUID }) |
511 | 487 | ||
512 | await wait(10000) | 488 | await wait(10000) |
513 | await waitJobs(servers) | 489 | await waitJobs(servers) |
514 | 490 | ||
515 | await waitJobs(servers) | 491 | await waitJobs(servers) |
516 | await waitUntilLog(servers[0], 'Duplicated ', 1) | 492 | await servers[0].servers.waitUntilLog('Duplicated ', 1) |
517 | await waitJobs(servers) | 493 | await waitJobs(servers) |
518 | 494 | ||
519 | await check1PlaylistRedundancies() | 495 | await check1PlaylistRedundancies() |
@@ -523,12 +499,12 @@ describe('Test videos redundancy', function () { | |||
523 | it('Should remove the video and the redundancy files', async function () { | 499 | it('Should remove the video and the redundancy files', async function () { |
524 | this.timeout(20000) | 500 | this.timeout(20000) |
525 | 501 | ||
526 | await removeVideo(servers[1].url, servers[1].accessToken, video1Server2UUID) | 502 | await servers[1].videos.remove({ id: video1Server2UUID }) |
527 | 503 | ||
528 | await waitJobs(servers) | 504 | await waitJobs(servers) |
529 | 505 | ||
530 | for (const server of servers) { | 506 | for (const server of servers) { |
531 | await checkVideoFilesWereRemoved(video1Server2UUID, server.internalServerNumber) | 507 | await checkVideoFilesWereRemoved(video1Server2UUID, server) |
532 | } | 508 | } |
533 | }) | 509 | }) |
534 | 510 | ||
@@ -541,7 +517,7 @@ describe('Test videos redundancy', function () { | |||
541 | before(function () { | 517 | before(function () { |
542 | this.timeout(120000) | 518 | this.timeout(120000) |
543 | 519 | ||
544 | return flushAndRunServers(null) | 520 | return createSingleServers(null) |
545 | }) | 521 | }) |
546 | 522 | ||
547 | it('Should have 1 webseed on the first video', async function () { | 523 | it('Should have 1 webseed on the first video', async function () { |
@@ -551,18 +527,14 @@ describe('Test videos redundancy', function () { | |||
551 | }) | 527 | }) |
552 | 528 | ||
553 | it('Should create a redundancy on first video', async function () { | 529 | it('Should create a redundancy on first video', async function () { |
554 | await addVideoRedundancy({ | 530 | await servers[0].redundancy.addVideo({ videoId: video1Server2Id }) |
555 | url: servers[0].url, | ||
556 | accessToken: servers[0].accessToken, | ||
557 | videoId: video1Server2Id | ||
558 | }) | ||
559 | }) | 531 | }) |
560 | 532 | ||
561 | it('Should have 2 webseeds on the first video', async function () { | 533 | it('Should have 2 webseeds on the first video', async function () { |
562 | this.timeout(80000) | 534 | this.timeout(80000) |
563 | 535 | ||
564 | await waitJobs(servers) | 536 | await waitJobs(servers) |
565 | await waitUntilLog(servers[0], 'Duplicated ', 5) | 537 | await servers[0].servers.waitUntilLog('Duplicated ', 5) |
566 | await waitJobs(servers) | 538 | await waitJobs(servers) |
567 | 539 | ||
568 | await check2Webseeds() | 540 | await check2Webseeds() |
@@ -573,22 +545,15 @@ describe('Test videos redundancy', function () { | |||
573 | it('Should manually remove redundancies on server 1 and remove duplicated videos', async function () { | 545 | it('Should manually remove redundancies on server 1 and remove duplicated videos', async function () { |
574 | this.timeout(80000) | 546 | this.timeout(80000) |
575 | 547 | ||
576 | const res = await listVideoRedundancies({ | 548 | const body = await servers[0].redundancy.listVideos({ target: 'remote-videos' }) |
577 | url: servers[0].url, | ||
578 | accessToken: servers[0].accessToken, | ||
579 | target: 'remote-videos' | ||
580 | }) | ||
581 | 549 | ||
582 | const videos = res.body.data as VideoRedundancy[] | 550 | const videos = body.data |
583 | expect(videos).to.have.lengthOf(1) | 551 | expect(videos).to.have.lengthOf(1) |
584 | 552 | ||
585 | const video = videos[0] | 553 | const video = videos[0] |
554 | |||
586 | for (const r of video.redundancies.files.concat(video.redundancies.streamingPlaylists)) { | 555 | for (const r of video.redundancies.files.concat(video.redundancies.streamingPlaylists)) { |
587 | await removeVideoRedundancy({ | 556 | await servers[0].redundancy.removeVideo({ redundancyId: r.id }) |
588 | url: servers[0].url, | ||
589 | accessToken: servers[0].accessToken, | ||
590 | redundancyId: r.id | ||
591 | }) | ||
592 | } | 557 | } |
593 | 558 | ||
594 | await waitJobs(servers) | 559 | await waitJobs(servers) |
@@ -597,7 +562,7 @@ describe('Test videos redundancy', function () { | |||
597 | await check1WebSeed() | 562 | await check1WebSeed() |
598 | await check0PlaylistRedundancies() | 563 | await check0PlaylistRedundancies() |
599 | 564 | ||
600 | await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ 'videos' ]) | 565 | await checkVideoFilesWereRemoved(video1Server2UUID, servers[0], [ 'videos' ]) |
601 | }) | 566 | }) |
602 | 567 | ||
603 | after(async function () { | 568 | after(async function () { |
@@ -608,10 +573,9 @@ describe('Test videos redundancy', function () { | |||
608 | describe('Test expiration', function () { | 573 | describe('Test expiration', function () { |
609 | const strategy = 'recently-added' | 574 | const strategy = 'recently-added' |
610 | 575 | ||
611 | async function checkContains (servers: ServerInfo[], str: string) { | 576 | async function checkContains (servers: PeerTubeServer[], str: string) { |
612 | for (const server of servers) { | 577 | for (const server of servers) { |
613 | const res = await getVideo(server.url, video1Server2UUID) | 578 | const video = await server.videos.get({ id: video1Server2UUID }) |
614 | const video: VideoDetails = res.body | ||
615 | 579 | ||
616 | for (const f of video.files) { | 580 | for (const f of video.files) { |
617 | expect(f.magnetUri).to.contain(str) | 581 | expect(f.magnetUri).to.contain(str) |
@@ -619,10 +583,9 @@ describe('Test videos redundancy', function () { | |||
619 | } | 583 | } |
620 | } | 584 | } |
621 | 585 | ||
622 | async function checkNotContains (servers: ServerInfo[], str: string) { | 586 | async function checkNotContains (servers: PeerTubeServer[], str: string) { |
623 | for (const server of servers) { | 587 | for (const server of servers) { |
624 | const res = await getVideo(server.url, video1Server2UUID) | 588 | const video = await server.videos.get({ id: video1Server2UUID }) |
625 | const video: VideoDetails = res.body | ||
626 | 589 | ||
627 | for (const f of video.files) { | 590 | for (const f of video.files) { |
628 | expect(f.magnetUri).to.not.contain(str) | 591 | expect(f.magnetUri).to.not.contain(str) |
@@ -633,7 +596,7 @@ describe('Test videos redundancy', function () { | |||
633 | before(async function () { | 596 | before(async function () { |
634 | this.timeout(120000) | 597 | this.timeout(120000) |
635 | 598 | ||
636 | await flushAndRunServers(strategy, { min_lifetime: '7 seconds', min_views: 0 }) | 599 | await createSingleServers(strategy, { min_lifetime: '7 seconds', min_views: 0 }) |
637 | 600 | ||
638 | await enableRedundancyOnServer1() | 601 | await enableRedundancyOnServer1() |
639 | }) | 602 | }) |
@@ -656,7 +619,7 @@ describe('Test videos redundancy', function () { | |||
656 | it('Should stop server 1 and expire video redundancy', async function () { | 619 | it('Should stop server 1 and expire video redundancy', async function () { |
657 | this.timeout(80000) | 620 | this.timeout(80000) |
658 | 621 | ||
659 | killallServers([ servers[0] ]) | 622 | await killallServers([ servers[0] ]) |
660 | 623 | ||
661 | await wait(15000) | 624 | await wait(15000) |
662 | 625 | ||
@@ -675,25 +638,25 @@ describe('Test videos redundancy', function () { | |||
675 | before(async function () { | 638 | before(async function () { |
676 | this.timeout(120000) | 639 | this.timeout(120000) |
677 | 640 | ||
678 | await flushAndRunServers(strategy, { min_lifetime: '7 seconds', min_views: 0 }) | 641 | await createSingleServers(strategy, { min_lifetime: '7 seconds', min_views: 0 }) |
679 | 642 | ||
680 | await enableRedundancyOnServer1() | 643 | await enableRedundancyOnServer1() |
681 | 644 | ||
682 | await waitJobs(servers) | 645 | await waitJobs(servers) |
683 | await waitUntilLog(servers[0], 'Duplicated ', 5) | 646 | await servers[0].servers.waitUntilLog('Duplicated ', 5) |
684 | await waitJobs(servers) | 647 | await waitJobs(servers) |
685 | 648 | ||
686 | await check2Webseeds(video1Server2UUID) | 649 | await check2Webseeds(video1Server2UUID) |
687 | await check1PlaylistRedundancies(video1Server2UUID) | 650 | await check1PlaylistRedundancies(video1Server2UUID) |
688 | await checkStatsWith1Redundancy(strategy) | 651 | await checkStatsWith1Redundancy(strategy) |
689 | 652 | ||
690 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 2 server 2', privacy: VideoPrivacy.PRIVATE }) | 653 | const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video 2 server 2', privacy: VideoPrivacy.PRIVATE } }) |
691 | video2Server2UUID = res.body.video.uuid | 654 | video2Server2UUID = uuid |
692 | 655 | ||
693 | // Wait transcoding before federation | 656 | // Wait transcoding before federation |
694 | await waitJobs(servers) | 657 | await waitJobs(servers) |
695 | 658 | ||
696 | await updateVideo(servers[1].url, servers[1].accessToken, video2Server2UUID, { privacy: VideoPrivacy.PUBLIC }) | 659 | await servers[1].videos.update({ id: video2Server2UUID, attributes: { privacy: VideoPrivacy.PUBLIC } }) |
697 | }) | 660 | }) |
698 | 661 | ||
699 | it('Should cache video 2 webseeds on the first video', async function () { | 662 | it('Should cache video 2 webseeds on the first video', async function () { |
@@ -725,8 +688,8 @@ describe('Test videos redundancy', function () { | |||
725 | 688 | ||
726 | await waitJobs(servers) | 689 | await waitJobs(servers) |
727 | 690 | ||
728 | killallServers([ servers[0] ]) | 691 | await killallServers([ servers[0] ]) |
729 | await reRunServer(servers[0], { | 692 | await servers[0].run({ |
730 | redundancy: { | 693 | redundancy: { |
731 | videos: { | 694 | videos: { |
732 | check_interval: '1 second', | 695 | check_interval: '1 second', |
@@ -737,7 +700,7 @@ describe('Test videos redundancy', function () { | |||
737 | 700 | ||
738 | await waitJobs(servers) | 701 | await waitJobs(servers) |
739 | 702 | ||
740 | await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].internalServerNumber, [ join('redundancy', 'hls') ]) | 703 | await checkVideoFilesWereRemoved(video1Server2UUID, servers[0], [ join('redundancy', 'hls') ]) |
741 | }) | 704 | }) |
742 | 705 | ||
743 | after(async function () { | 706 | after(async function () { |