From 742ddee1f131e6a2d701f2eeeb2851e8e1020cb2 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 15 Nov 2018 10:07:44 +0100 Subject: Fix server redundancy tests --- server/lib/schedulers/videos-redundancy-scheduler.ts | 5 +++-- server/models/redundancy/video-redundancy.ts | 5 +++++ server/tests/api/server/redundancy.ts | 18 +++++++++--------- 3 files changed, 17 insertions(+), 11 deletions(-) (limited to 'server') 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 { } private async isTooHeavy (redundancy: VideosRedundancy, filesToDuplicate: VideoFileModel[]) { - const maxSize = redundancy.size - this.getTotalFileSizes(filesToDuplicate) + const maxSize = redundancy.size const totalDuplicated = await VideoRedundancyModel.getTotalDuplicated(redundancy.strategy) + const totalWillDuplicate = totalDuplicated + this.getTotalFileSizes(filesToDuplicate) - return totalDuplicated > maxSize + return totalWillDuplicate > maxSize } 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 { } return VideoFileModel.sum('size', options as any) // FIXME: typings + .then(v => { + if (!v || isNaN(v)) return 0 + + return v + }) } 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: immutableAssign({ min_lifetime: '1 hour', strategy: strategy, - size: '100KB' + size: '200KB' }, additionalParams) ] } @@ -111,8 +111,8 @@ async function checkStatsWith2Webseed (strategy: VideoRedundancyStrategy) { const stat = data.videosRedundancy[0] expect(stat.strategy).to.equal(strategy) - expect(stat.totalSize).to.equal(102400) - expect(stat.totalUsed).to.be.at.least(1).and.below(102401) + expect(stat.totalSize).to.equal(204800) + expect(stat.totalUsed).to.be.at.least(1).and.below(204800) expect(stat.totalVideoFiles).to.equal(4) expect(stat.totalVideos).to.equal(1) } @@ -125,7 +125,7 @@ async function checkStatsWith1Webseed (strategy: VideoRedundancyStrategy) { const stat = data.videosRedundancy[0] expect(stat.strategy).to.equal(strategy) - expect(stat.totalSize).to.equal(102400) + expect(stat.totalSize).to.equal(204800) expect(stat.totalUsed).to.equal(0) expect(stat.totalVideoFiles).to.equal(0) expect(stat.totalVideos).to.equal(0) @@ -223,7 +223,7 @@ describe('Test videos redundancy', function () { return enableRedundancyOnServer1() }) - it('Should have 2 webseed on the first video', async function () { + it('Should have 2 webseeds on the first video', async function () { this.timeout(40000) await waitJobs(servers) @@ -270,7 +270,7 @@ describe('Test videos redundancy', function () { return enableRedundancyOnServer1() }) - it('Should have 2 webseed on the first video', async function () { + it('Should have 2 webseeds on the first video', async function () { this.timeout(40000) await waitJobs(servers) @@ -338,7 +338,7 @@ describe('Test videos redundancy', function () { await waitJobs(servers) }) - it('Should have 2 webseed on the first video', async function () { + it('Should have 2 webseeds on the first video', async function () { this.timeout(40000) await waitJobs(servers) @@ -399,7 +399,7 @@ describe('Test videos redundancy', function () { await enableRedundancyOnServer1() }) - it('Should still have 2 webseeds after 10 seconds', async function () { + it('Should still have 2 webseedss after 10 seconds', async function () { this.timeout(40000) await wait(10000) @@ -451,7 +451,7 @@ describe('Test videos redundancy', function () { video2Server2UUID = res.body.video.uuid }) - it('Should cache video 2 webseed on the first video', async function () { + it('Should cache video 2 webseeds on the first video', async function () { this.timeout(120000) await waitJobs(servers) -- cgit v1.2.3