From 6949a1a1113cc6af3442dc3d5446b8fe6143f28e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 1 Feb 2021 11:57:21 +0100 Subject: [PATCH] Fix tests --- server/models/redundancy/video-redundancy.ts | 3 +- .../api/redundancy/redundancy-constraints.ts | 58 +++++++++++-------- server/tests/api/redundancy/redundancy.ts | 29 +++++----- 3 files changed, 49 insertions(+), 41 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 @@ import { sample } from 'lodash' -import { col, FindOptions, fn, literal, Op, QueryTypes, Transaction, WhereOptions } from 'sequelize' +import { FindOptions, literal, Op, QueryTypes, Transaction, WhereOptions } from 'sequelize' import { AllowNull, BeforeDestroy, @@ -36,7 +36,6 @@ import { VideoModel } from '../video/video' import { VideoChannelModel } from '../video/video-channel' import { VideoFileModel } from '../video/video-file' import { VideoStreamingPlaylistModel } from '../video/video-streaming-playlist' -import { forEachSeries } from 'async' export enum ScopeNames { 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 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' +import * as chai from 'chai' +import { listVideoRedundancies, updateRedundancy } from '@shared/extra-utils/server/redundancy' +import { VideoPrivacy } from '@shared/models' import { cleanupTests, flushAndRunServer, @@ -10,11 +12,11 @@ import { reRunServer, ServerInfo, setAccessTokensToServers, + updateVideo, uploadVideo, waitUntilLog } from '../../../../shared/extra-utils' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { listVideoRedundancies, updateRedundancy } from '@shared/extra-utils/server/redundancy' const expect = chai.expect @@ -23,6 +25,31 @@ describe('Test redundancy constraints', function () { let localServer: ServerInfo let servers: ServerInfo[] + const remoteServerConfig = { + redundancy: { + videos: { + check_interval: '1 second', + strategies: [ + { + strategy: 'recently-added', + min_lifetime: '1 hour', + size: '100MB', + min_views: 0 + } + ] + } + } + } + + async function uploadWrapper (videoName: string) { + // Wait for transcoding + const res = await uploadVideo(localServer.url, localServer.accessToken, { name: 'to transcode', privacy: VideoPrivacy.PRIVATE }) + await waitJobs([ localServer ]) + + // Update video to schedule a federation + await updateVideo(localServer.url, localServer.accessToken, res.body.video.id, { name: videoName, privacy: VideoPrivacy.PUBLIC }) + } + async function getTotalRedundanciesLocalServer () { const res = await listVideoRedundancies({ url: localServer.url, @@ -47,22 +74,7 @@ describe('Test redundancy constraints', function () { this.timeout(120000) { - const config = { - redundancy: { - videos: { - check_interval: '1 second', - strategies: [ - { - strategy: 'recently-added', - min_lifetime: '1 hour', - size: '100MB', - min_views: 0 - } - ] - } - } - } - remoteServer = await flushAndRunServer(1, config) + remoteServer = await flushAndRunServer(1, remoteServerConfig) } { @@ -124,9 +136,8 @@ describe('Test redundancy constraints', function () { await killallServers([ localServer ]) await reRunServer(localServer, config) - await uploadVideo(localServer.url, localServer.accessToken, { name: 'video 2 server 2' }) + await uploadWrapper('video 2 server 2') - await waitJobs(servers) await waitUntilLog(remoteServer, 'Duplicated ', 10) await waitJobs(servers) @@ -154,9 +165,8 @@ describe('Test redundancy constraints', function () { await killallServers([ localServer ]) await reRunServer(localServer, config) - await uploadVideo(localServer.url, localServer.accessToken, { name: 'video 3 server 2' }) + await uploadWrapper('video 3 server 2') - await waitJobs(servers) await waitUntilLog(remoteServer, 'Duplicated ', 15) await waitJobs(servers) @@ -177,9 +187,7 @@ describe('Test redundancy constraints', function () { await follow(localServer.url, [ remoteServer.url ], localServer.accessToken) await waitJobs(servers) - await uploadVideo(localServer.url, localServer.accessToken, { name: 'video 4 server 2' }) - - await waitJobs(servers) + await uploadWrapper('video 4 server 2') await waitUntilLog(remoteServer, 'Duplicated ', 20) await waitJobs(servers) 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 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' -import { VideoDetails } from '../../../../shared/models/videos' +import * as chai from 'chai' +import { readdir } from 'fs-extra' +import * as magnetUtil from 'magnet-uri' +import { join } from 'path' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { checkSegmentHash, checkVideoFilesWereRemoved, @@ -21,29 +24,23 @@ import { ServerInfo, setAccessTokensToServers, unfollow, - updateCustomConfig, - updateCustomSubConfig, uploadVideo, viewVideo, wait, waitUntilLog } from '../../../../shared/extra-utils' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' - -import * as magnetUtil from 'magnet-uri' import { addVideoRedundancy, listVideoRedundancies, removeVideoRedundancy, updateRedundancy } from '../../../../shared/extra-utils/server/redundancy' -import { ActorFollow } from '../../../../shared/models/actors' -import { readdir } from 'fs-extra' -import { join } from 'path' -import { VideoRedundancy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '../../../../shared/models/redundancy' import { getStats } from '../../../../shared/extra-utils/server/stats' +import { ActorFollow } from '../../../../shared/models/actors' +import { VideoRedundancy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '../../../../shared/models/redundancy' import { ServerStats } from '../../../../shared/models/server/server-stats.model' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { VideoDetails } from '../../../../shared/models/videos' const expect = chai.expect @@ -258,11 +255,11 @@ async function checkStatsGlobal (strategy: VideoRedundancyStrategyWithManual) { return stat } -async function checkStatsWith1Redundancy (strategy: VideoRedundancyStrategyWithManual) { +async function checkStatsWith1Redundancy (strategy: VideoRedundancyStrategyWithManual, onlyHls = false) { const stat = await checkStatsGlobal(strategy) expect(stat.totalUsed).to.be.at.least(1).and.below(409601) - expect(stat.totalVideoFiles).to.equal(4) + expect(stat.totalVideoFiles).to.equal(onlyHls ? 4 : 8) expect(stat.totalVideos).to.equal(1) } @@ -519,7 +516,7 @@ describe('Test videos redundancy', function () { await waitJobs(servers) await check1PlaylistRedundancies() - await checkStatsWith1Redundancy(strategy) + await checkStatsWith1Redundancy(strategy, true) }) it('Should remove the video and the redundancy files', async function () { @@ -533,6 +530,10 @@ describe('Test videos redundancy', function () { await checkVideoFilesWereRemoved(video1Server2UUID, server.internalServerNumber) } }) + + after(async function () { + await cleanupTests(servers) + }) }) describe('With manual strategy', function () {