diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/lib/schedulers/videos-redundancy-scheduler.ts | 5 | ||||
-rw-r--r-- | server/models/redundancy/video-redundancy.ts | 5 | ||||
-rw-r--r-- | server/tests/api/server/redundancy.ts | 18 |
3 files changed, 17 insertions, 11 deletions
diff --git a/server/lib/schedulers/videos-redundancy-scheduler.ts b/server/lib/schedulers/videos-redundancy-scheduler.ts index c49a8c89a..8b7f33539 100644 --- a/server/lib/schedulers/videos-redundancy-scheduler.ts +++ b/server/lib/schedulers/videos-redundancy-scheduler.ts | |||
@@ -185,11 +185,12 @@ export class VideosRedundancyScheduler extends AbstractScheduler { | |||
185 | } | 185 | } |
186 | 186 | ||
187 | private async isTooHeavy (redundancy: VideosRedundancy, filesToDuplicate: VideoFileModel[]) { | 187 | private async isTooHeavy (redundancy: VideosRedundancy, filesToDuplicate: VideoFileModel[]) { |
188 | const maxSize = redundancy.size - this.getTotalFileSizes(filesToDuplicate) | 188 | const maxSize = redundancy.size |
189 | 189 | ||
190 | const totalDuplicated = await VideoRedundancyModel.getTotalDuplicated(redundancy.strategy) | 190 | const totalDuplicated = await VideoRedundancyModel.getTotalDuplicated(redundancy.strategy) |
191 | const totalWillDuplicate = totalDuplicated + this.getTotalFileSizes(filesToDuplicate) | ||
191 | 192 | ||
192 | return totalDuplicated > maxSize | 193 | return totalWillDuplicate > maxSize |
193 | } | 194 | } |
194 | 195 | ||
195 | private buildNewExpiration (expiresAfterMs: number) { | 196 | private buildNewExpiration (expiresAfterMs: number) { |
diff --git a/server/models/redundancy/video-redundancy.ts b/server/models/redundancy/video-redundancy.ts index cbfc7f7fa..35e0cd3b1 100644 --- a/server/models/redundancy/video-redundancy.ts +++ b/server/models/redundancy/video-redundancy.ts | |||
@@ -293,6 +293,11 @@ export class VideoRedundancyModel extends Model<VideoRedundancyModel> { | |||
293 | } | 293 | } |
294 | 294 | ||
295 | return VideoFileModel.sum('size', options as any) // FIXME: typings | 295 | return VideoFileModel.sum('size', options as any) // FIXME: typings |
296 | .then(v => { | ||
297 | if (!v || isNaN(v)) return 0 | ||
298 | |||
299 | return v | ||
300 | }) | ||
296 | } | 301 | } |
297 | 302 | ||
298 | static async listLocalExpired () { | 303 | static async listLocalExpired () { |
diff --git a/server/tests/api/server/redundancy.ts b/server/tests/api/server/redundancy.ts index f50d6e3cf..77a2d61a4 100644 --- a/server/tests/api/server/redundancy.ts +++ b/server/tests/api/server/redundancy.ts | |||
@@ -54,7 +54,7 @@ async function runServers (strategy: VideoRedundancyStrategy, additionalParams: | |||
54 | immutableAssign({ | 54 | immutableAssign({ |
55 | min_lifetime: '1 hour', | 55 | min_lifetime: '1 hour', |
56 | strategy: strategy, | 56 | strategy: strategy, |
57 | size: '100KB' | 57 | size: '200KB' |
58 | }, additionalParams) | 58 | }, additionalParams) |
59 | ] | 59 | ] |
60 | } | 60 | } |
@@ -111,8 +111,8 @@ async function checkStatsWith2Webseed (strategy: VideoRedundancyStrategy) { | |||
111 | const stat = data.videosRedundancy[0] | 111 | const stat = data.videosRedundancy[0] |
112 | 112 | ||
113 | expect(stat.strategy).to.equal(strategy) | 113 | expect(stat.strategy).to.equal(strategy) |
114 | expect(stat.totalSize).to.equal(102400) | 114 | expect(stat.totalSize).to.equal(204800) |
115 | expect(stat.totalUsed).to.be.at.least(1).and.below(102401) | 115 | expect(stat.totalUsed).to.be.at.least(1).and.below(204800) |
116 | expect(stat.totalVideoFiles).to.equal(4) | 116 | expect(stat.totalVideoFiles).to.equal(4) |
117 | expect(stat.totalVideos).to.equal(1) | 117 | expect(stat.totalVideos).to.equal(1) |
118 | } | 118 | } |
@@ -125,7 +125,7 @@ async function checkStatsWith1Webseed (strategy: VideoRedundancyStrategy) { | |||
125 | 125 | ||
126 | const stat = data.videosRedundancy[0] | 126 | const stat = data.videosRedundancy[0] |
127 | expect(stat.strategy).to.equal(strategy) | 127 | expect(stat.strategy).to.equal(strategy) |
128 | expect(stat.totalSize).to.equal(102400) | 128 | expect(stat.totalSize).to.equal(204800) |
129 | expect(stat.totalUsed).to.equal(0) | 129 | expect(stat.totalUsed).to.equal(0) |
130 | expect(stat.totalVideoFiles).to.equal(0) | 130 | expect(stat.totalVideoFiles).to.equal(0) |
131 | expect(stat.totalVideos).to.equal(0) | 131 | expect(stat.totalVideos).to.equal(0) |
@@ -223,7 +223,7 @@ describe('Test videos redundancy', function () { | |||
223 | return enableRedundancyOnServer1() | 223 | return enableRedundancyOnServer1() |
224 | }) | 224 | }) |
225 | 225 | ||
226 | it('Should have 2 webseed on the first video', async function () { | 226 | it('Should have 2 webseeds on the first video', async function () { |
227 | this.timeout(40000) | 227 | this.timeout(40000) |
228 | 228 | ||
229 | await waitJobs(servers) | 229 | await waitJobs(servers) |
@@ -270,7 +270,7 @@ describe('Test videos redundancy', function () { | |||
270 | return enableRedundancyOnServer1() | 270 | return enableRedundancyOnServer1() |
271 | }) | 271 | }) |
272 | 272 | ||
273 | it('Should have 2 webseed on the first video', async function () { | 273 | it('Should have 2 webseeds on the first video', async function () { |
274 | this.timeout(40000) | 274 | this.timeout(40000) |
275 | 275 | ||
276 | await waitJobs(servers) | 276 | await waitJobs(servers) |
@@ -338,7 +338,7 @@ describe('Test videos redundancy', function () { | |||
338 | await waitJobs(servers) | 338 | await waitJobs(servers) |
339 | }) | 339 | }) |
340 | 340 | ||
341 | it('Should have 2 webseed on the first video', async function () { | 341 | it('Should have 2 webseeds on the first video', async function () { |
342 | this.timeout(40000) | 342 | this.timeout(40000) |
343 | 343 | ||
344 | await waitJobs(servers) | 344 | await waitJobs(servers) |
@@ -399,7 +399,7 @@ describe('Test videos redundancy', function () { | |||
399 | await enableRedundancyOnServer1() | 399 | await enableRedundancyOnServer1() |
400 | }) | 400 | }) |
401 | 401 | ||
402 | it('Should still have 2 webseeds after 10 seconds', async function () { | 402 | it('Should still have 2 webseedss after 10 seconds', async function () { |
403 | this.timeout(40000) | 403 | this.timeout(40000) |
404 | 404 | ||
405 | await wait(10000) | 405 | await wait(10000) |
@@ -451,7 +451,7 @@ describe('Test videos redundancy', function () { | |||
451 | video2Server2UUID = res.body.video.uuid | 451 | video2Server2UUID = res.body.video.uuid |
452 | }) | 452 | }) |
453 | 453 | ||
454 | it('Should cache video 2 webseed on the first video', async function () { | 454 | it('Should cache video 2 webseeds on the first video', async function () { |
455 | this.timeout(120000) | 455 | this.timeout(120000) |
456 | 456 | ||
457 | await waitJobs(servers) | 457 | await waitJobs(servers) |