diff options
-rw-r--r-- | server/models/redundancy/video-redundancy.ts | 3 | ||||
-rw-r--r-- | server/tests/api/redundancy/redundancy-constraints.ts | 58 | ||||
-rw-r--r-- | server/tests/api/redundancy/redundancy.ts | 27 |
3 files changed, 48 insertions, 40 deletions
diff --git a/server/models/redundancy/video-redundancy.ts b/server/models/redundancy/video-redundancy.ts index d3b839cfe..98c6ff134 100644 --- a/server/models/redundancy/video-redundancy.ts +++ b/server/models/redundancy/video-redundancy.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { sample } from 'lodash' | 1 | import { sample } from 'lodash' |
2 | import { col, FindOptions, fn, literal, Op, QueryTypes, Transaction, WhereOptions } from 'sequelize' | 2 | import { FindOptions, literal, Op, QueryTypes, Transaction, WhereOptions } from 'sequelize' |
3 | import { | 3 | import { |
4 | AllowNull, | 4 | AllowNull, |
5 | BeforeDestroy, | 5 | BeforeDestroy, |
@@ -36,7 +36,6 @@ import { VideoModel } from '../video/video' | |||
36 | import { VideoChannelModel } from '../video/video-channel' | 36 | import { VideoChannelModel } from '../video/video-channel' |
37 | import { VideoFileModel } from '../video/video-file' | 37 | import { VideoFileModel } from '../video/video-file' |
38 | import { VideoStreamingPlaylistModel } from '../video/video-streaming-playlist' | 38 | import { VideoStreamingPlaylistModel } from '../video/video-streaming-playlist' |
39 | import { forEachSeries } from 'async' | ||
40 | 39 | ||
41 | export enum ScopeNames { | 40 | export enum ScopeNames { |
42 | WITH_VIDEO = 'WITH_VIDEO' | 41 | WITH_VIDEO = 'WITH_VIDEO' |
diff --git a/server/tests/api/redundancy/redundancy-constraints.ts b/server/tests/api/redundancy/redundancy-constraints.ts index 4fd8f065c..1cb1603bc 100644 --- a/server/tests/api/redundancy/redundancy-constraints.ts +++ b/server/tests/api/redundancy/redundancy-constraints.ts | |||
@@ -1,7 +1,9 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | ||
5 | import { listVideoRedundancies, updateRedundancy } from '@shared/extra-utils/server/redundancy' | ||
6 | import { VideoPrivacy } from '@shared/models' | ||
5 | import { | 7 | import { |
6 | cleanupTests, | 8 | cleanupTests, |
7 | flushAndRunServer, | 9 | flushAndRunServer, |
@@ -10,11 +12,11 @@ import { | |||
10 | reRunServer, | 12 | reRunServer, |
11 | ServerInfo, | 13 | ServerInfo, |
12 | setAccessTokensToServers, | 14 | setAccessTokensToServers, |
15 | updateVideo, | ||
13 | uploadVideo, | 16 | uploadVideo, |
14 | waitUntilLog | 17 | waitUntilLog |
15 | } from '../../../../shared/extra-utils' | 18 | } from '../../../../shared/extra-utils' |
16 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | 19 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' |
17 | import { listVideoRedundancies, updateRedundancy } from '@shared/extra-utils/server/redundancy' | ||
18 | 20 | ||
19 | const expect = chai.expect | 21 | const expect = chai.expect |
20 | 22 | ||
@@ -23,6 +25,31 @@ describe('Test redundancy constraints', function () { | |||
23 | let localServer: ServerInfo | 25 | let localServer: ServerInfo |
24 | let servers: ServerInfo[] | 26 | let servers: ServerInfo[] |
25 | 27 | ||
28 | const remoteServerConfig = { | ||
29 | redundancy: { | ||
30 | videos: { | ||
31 | check_interval: '1 second', | ||
32 | strategies: [ | ||
33 | { | ||
34 | strategy: 'recently-added', | ||
35 | min_lifetime: '1 hour', | ||
36 | size: '100MB', | ||
37 | min_views: 0 | ||
38 | } | ||
39 | ] | ||
40 | } | ||
41 | } | ||
42 | } | ||
43 | |||
44 | async function uploadWrapper (videoName: string) { | ||
45 | // Wait for transcoding | ||
46 | const res = await uploadVideo(localServer.url, localServer.accessToken, { name: 'to transcode', privacy: VideoPrivacy.PRIVATE }) | ||
47 | await waitJobs([ localServer ]) | ||
48 | |||
49 | // Update video to schedule a federation | ||
50 | await updateVideo(localServer.url, localServer.accessToken, res.body.video.id, { name: videoName, privacy: VideoPrivacy.PUBLIC }) | ||
51 | } | ||
52 | |||
26 | async function getTotalRedundanciesLocalServer () { | 53 | async function getTotalRedundanciesLocalServer () { |
27 | const res = await listVideoRedundancies({ | 54 | const res = await listVideoRedundancies({ |
28 | url: localServer.url, | 55 | url: localServer.url, |
@@ -47,22 +74,7 @@ describe('Test redundancy constraints', function () { | |||
47 | this.timeout(120000) | 74 | this.timeout(120000) |
48 | 75 | ||
49 | { | 76 | { |
50 | const config = { | 77 | remoteServer = await flushAndRunServer(1, remoteServerConfig) |
51 | redundancy: { | ||
52 | videos: { | ||
53 | check_interval: '1 second', | ||
54 | strategies: [ | ||
55 | { | ||
56 | strategy: 'recently-added', | ||
57 | min_lifetime: '1 hour', | ||
58 | size: '100MB', | ||
59 | min_views: 0 | ||
60 | } | ||
61 | ] | ||
62 | } | ||
63 | } | ||
64 | } | ||
65 | remoteServer = await flushAndRunServer(1, config) | ||
66 | } | 78 | } |
67 | 79 | ||
68 | { | 80 | { |
@@ -124,9 +136,8 @@ describe('Test redundancy constraints', function () { | |||
124 | await killallServers([ localServer ]) | 136 | await killallServers([ localServer ]) |
125 | await reRunServer(localServer, config) | 137 | await reRunServer(localServer, config) |
126 | 138 | ||
127 | await uploadVideo(localServer.url, localServer.accessToken, { name: 'video 2 server 2' }) | 139 | await uploadWrapper('video 2 server 2') |
128 | 140 | ||
129 | await waitJobs(servers) | ||
130 | await waitUntilLog(remoteServer, 'Duplicated ', 10) | 141 | await waitUntilLog(remoteServer, 'Duplicated ', 10) |
131 | await waitJobs(servers) | 142 | await waitJobs(servers) |
132 | 143 | ||
@@ -154,9 +165,8 @@ describe('Test redundancy constraints', function () { | |||
154 | await killallServers([ localServer ]) | 165 | await killallServers([ localServer ]) |
155 | await reRunServer(localServer, config) | 166 | await reRunServer(localServer, config) |
156 | 167 | ||
157 | await uploadVideo(localServer.url, localServer.accessToken, { name: 'video 3 server 2' }) | 168 | await uploadWrapper('video 3 server 2') |
158 | 169 | ||
159 | await waitJobs(servers) | ||
160 | await waitUntilLog(remoteServer, 'Duplicated ', 15) | 170 | await waitUntilLog(remoteServer, 'Duplicated ', 15) |
161 | await waitJobs(servers) | 171 | await waitJobs(servers) |
162 | 172 | ||
@@ -177,9 +187,7 @@ describe('Test redundancy constraints', function () { | |||
177 | await follow(localServer.url, [ remoteServer.url ], localServer.accessToken) | 187 | await follow(localServer.url, [ remoteServer.url ], localServer.accessToken) |
178 | await waitJobs(servers) | 188 | await waitJobs(servers) |
179 | 189 | ||
180 | await uploadVideo(localServer.url, localServer.accessToken, { name: 'video 4 server 2' }) | 190 | await uploadWrapper('video 4 server 2') |
181 | |||
182 | await waitJobs(servers) | ||
183 | await waitUntilLog(remoteServer, 'Duplicated ', 20) | 191 | await waitUntilLog(remoteServer, 'Duplicated ', 20) |
184 | await waitJobs(servers) | 192 | await waitJobs(servers) |
185 | 193 | ||
diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index 8da0ba72a..811dc8c55 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts | |||
@@ -1,8 +1,11 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | 3 | import 'mocha' |
5 | import { VideoDetails } from '../../../../shared/models/videos' | 4 | import * as chai from 'chai' |
5 | import { readdir } from 'fs-extra' | ||
6 | import * as magnetUtil from 'magnet-uri' | ||
7 | import { join } from 'path' | ||
8 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
6 | import { | 9 | import { |
7 | checkSegmentHash, | 10 | checkSegmentHash, |
8 | checkVideoFilesWereRemoved, | 11 | checkVideoFilesWereRemoved, |
@@ -21,29 +24,23 @@ import { | |||
21 | ServerInfo, | 24 | ServerInfo, |
22 | setAccessTokensToServers, | 25 | setAccessTokensToServers, |
23 | unfollow, | 26 | unfollow, |
24 | updateCustomConfig, | ||
25 | updateCustomSubConfig, | ||
26 | uploadVideo, | 27 | uploadVideo, |
27 | viewVideo, | 28 | viewVideo, |
28 | wait, | 29 | wait, |
29 | waitUntilLog | 30 | waitUntilLog |
30 | } from '../../../../shared/extra-utils' | 31 | } from '../../../../shared/extra-utils' |
31 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | 32 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' |
32 | |||
33 | import * as magnetUtil from 'magnet-uri' | ||
34 | import { | 33 | import { |
35 | addVideoRedundancy, | 34 | addVideoRedundancy, |
36 | listVideoRedundancies, | 35 | listVideoRedundancies, |
37 | removeVideoRedundancy, | 36 | removeVideoRedundancy, |
38 | updateRedundancy | 37 | updateRedundancy |
39 | } from '../../../../shared/extra-utils/server/redundancy' | 38 | } from '../../../../shared/extra-utils/server/redundancy' |
39 | import { getStats } from '../../../../shared/extra-utils/server/stats' | ||
40 | import { ActorFollow } from '../../../../shared/models/actors' | 40 | import { ActorFollow } from '../../../../shared/models/actors' |
41 | import { readdir } from 'fs-extra' | ||
42 | import { join } from 'path' | ||
43 | import { VideoRedundancy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '../../../../shared/models/redundancy' | 41 | import { VideoRedundancy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '../../../../shared/models/redundancy' |
44 | import { getStats } from '../../../../shared/extra-utils/server/stats' | ||
45 | import { ServerStats } from '../../../../shared/models/server/server-stats.model' | 42 | import { ServerStats } from '../../../../shared/models/server/server-stats.model' |
46 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 43 | import { VideoDetails } from '../../../../shared/models/videos' |
47 | 44 | ||
48 | const expect = chai.expect | 45 | const expect = chai.expect |
49 | 46 | ||
@@ -258,11 +255,11 @@ async function checkStatsGlobal (strategy: VideoRedundancyStrategyWithManual) { | |||
258 | return stat | 255 | return stat |
259 | } | 256 | } |
260 | 257 | ||
261 | async function checkStatsWith1Redundancy (strategy: VideoRedundancyStrategyWithManual) { | 258 | async function checkStatsWith1Redundancy (strategy: VideoRedundancyStrategyWithManual, onlyHls = false) { |
262 | const stat = await checkStatsGlobal(strategy) | 259 | const stat = await checkStatsGlobal(strategy) |
263 | 260 | ||
264 | expect(stat.totalUsed).to.be.at.least(1).and.below(409601) | 261 | expect(stat.totalUsed).to.be.at.least(1).and.below(409601) |
265 | expect(stat.totalVideoFiles).to.equal(4) | 262 | expect(stat.totalVideoFiles).to.equal(onlyHls ? 4 : 8) |
266 | expect(stat.totalVideos).to.equal(1) | 263 | expect(stat.totalVideos).to.equal(1) |
267 | } | 264 | } |
268 | 265 | ||
@@ -519,7 +516,7 @@ describe('Test videos redundancy', function () { | |||
519 | await waitJobs(servers) | 516 | await waitJobs(servers) |
520 | 517 | ||
521 | await check1PlaylistRedundancies() | 518 | await check1PlaylistRedundancies() |
522 | await checkStatsWith1Redundancy(strategy) | 519 | await checkStatsWith1Redundancy(strategy, true) |
523 | }) | 520 | }) |
524 | 521 | ||
525 | it('Should remove the video and the redundancy files', async function () { | 522 | it('Should remove the video and the redundancy files', async function () { |
@@ -533,6 +530,10 @@ describe('Test videos redundancy', function () { | |||
533 | await checkVideoFilesWereRemoved(video1Server2UUID, server.internalServerNumber) | 530 | await checkVideoFilesWereRemoved(video1Server2UUID, server.internalServerNumber) |
534 | } | 531 | } |
535 | }) | 532 | }) |
533 | |||
534 | after(async function () { | ||
535 | await cleanupTests(servers) | ||
536 | }) | ||
536 | }) | 537 | }) |
537 | 538 | ||
538 | describe('With manual strategy', function () { | 539 | describe('With manual strategy', function () { |