PeerTube/server/tests/api/redundancy/redundancy-constraints.ts

194 lines
4.8 KiB
TypeScript
Raw Normal View History

/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha'
2021-07-09 11:21:30 +02:00
import { expect } from 'chai'
import {
cleanupTests,
flushAndRunServer,
killallServers,
reRunServer,
ServerInfo,
setAccessTokensToServers,
2021-07-13 09:43:59 +02:00
waitJobs
2021-07-07 10:56:45 +02:00
} from '@shared/extra-utils'
import { VideoPrivacy } from '@shared/models'
describe('Test redundancy constraints', function () {
let remoteServer: ServerInfo
let localServer: ServerInfo
let servers: ServerInfo[]
2021-02-01 11:57:21 +01:00
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
2021-07-16 09:04:35 +02:00
const { id } = await localServer.videos.upload({ attributes: { name: 'to transcode', privacy: VideoPrivacy.PRIVATE } })
2021-02-01 11:57:21 +01:00
await waitJobs([ localServer ])
// Update video to schedule a federation
2021-07-16 09:04:35 +02:00
await localServer.videos.update({ id, attributes: { name: videoName, privacy: VideoPrivacy.PUBLIC } })
2021-02-01 11:57:21 +01:00
}
async function getTotalRedundanciesLocalServer () {
2021-07-16 09:04:35 +02:00
const body = await localServer.redundancy.listVideos({ target: 'my-videos' })
2021-07-07 10:56:45 +02:00
return body.total
}
async function getTotalRedundanciesRemoteServer () {
2021-07-16 09:04:35 +02:00
const body = await remoteServer.redundancy.listVideos({ target: 'remote-videos' })
2021-07-07 10:56:45 +02:00
return body.total
}
before(async function () {
this.timeout(120000)
{
2021-02-01 11:57:21 +01:00
remoteServer = await flushAndRunServer(1, remoteServerConfig)
}
{
const config = {
remote_redundancy: {
videos: {
accept_from: 'nobody'
}
}
}
localServer = await flushAndRunServer(2, config)
}
servers = [ remoteServer, localServer ]
// Get the access tokens
await setAccessTokensToServers(servers)
2021-07-16 09:04:35 +02:00
await localServer.videos.upload({ attributes: { name: 'video 1 server 2' } })
await waitJobs(servers)
// Server 1 and server 2 follow each other
2021-07-16 09:04:35 +02:00
await remoteServer.follows.follow({ targets: [ localServer.url ] })
await waitJobs(servers)
2021-07-16 09:04:35 +02:00
await remoteServer.redundancy.updateRedundancy({ host: localServer.host, redundancyAllowed: true })
await waitJobs(servers)
})
it('Should have redundancy on server 1 but not on server 2 with a nobody filter', async function () {
this.timeout(120000)
await waitJobs(servers)
2021-07-16 09:04:35 +02:00
await remoteServer.servers.waitUntilLog('Duplicated ', 5)
await waitJobs(servers)
{
const total = await getTotalRedundanciesRemoteServer()
expect(total).to.equal(1)
}
{
const total = await getTotalRedundanciesLocalServer()
expect(total).to.equal(0)
}
})
it('Should have redundancy on server 1 and on server 2 with an anybody filter', async function () {
this.timeout(120000)
const config = {
remote_redundancy: {
videos: {
accept_from: 'anybody'
}
}
}
2021-07-09 15:37:43 +02:00
await await killallServers([ localServer ])
await reRunServer(localServer, config)
2021-02-01 11:57:21 +01:00
await uploadWrapper('video 2 server 2')
2021-07-16 09:04:35 +02:00
await remoteServer.servers.waitUntilLog('Duplicated ', 10)
await waitJobs(servers)
{
const total = await getTotalRedundanciesRemoteServer()
expect(total).to.equal(2)
}
{
const total = await getTotalRedundanciesLocalServer()
expect(total).to.equal(1)
}
})
it('Should have redundancy on server 1 but not on server 2 with a followings filter', async function () {
this.timeout(120000)
const config = {
remote_redundancy: {
videos: {
accept_from: 'followings'
}
}
}
2021-07-09 15:37:43 +02:00
await killallServers([ localServer ])
await reRunServer(localServer, config)
2021-02-01 11:57:21 +01:00
await uploadWrapper('video 3 server 2')
2021-07-16 09:04:35 +02:00
await remoteServer.servers.waitUntilLog('Duplicated ', 15)
await waitJobs(servers)
{
const total = await getTotalRedundanciesRemoteServer()
expect(total).to.equal(3)
}
{
const total = await getTotalRedundanciesLocalServer()
expect(total).to.equal(1)
}
})
it('Should have redundancy on server 1 and on server 2 with followings filter now server 2 follows server 1', async function () {
this.timeout(120000)
2021-07-16 09:04:35 +02:00
await localServer.follows.follow({ targets: [ remoteServer.url ] })
await waitJobs(servers)
2021-02-01 11:57:21 +01:00
await uploadWrapper('video 4 server 2')
2021-07-16 09:04:35 +02:00
await remoteServer.servers.waitUntilLog('Duplicated ', 20)
await waitJobs(servers)
{
const total = await getTotalRedundanciesRemoteServer()
expect(total).to.equal(4)
}
{
const total = await getTotalRedundanciesLocalServer()
expect(total).to.equal(2)
}
})
after(async function () {
await cleanupTests(servers)
})
})