Fix tests

pull/3679/head
Chocobozzz 2021-02-01 11:57:21 +01:00
parent 56df7815b5
commit 6949a1a111
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
3 changed files with 49 additions and 41 deletions

View File

@ -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'

View File

@ -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)

View File

@ -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 () {