1
0
Fork 0
peertube/server/tests/api/redundancy/redundancy-constraints.ts

192 lines
4.8 KiB
TypeScript
Raw Normal View History

/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2021-07-09 05:21:30 -04:00
import { expect } from 'chai'
2021-07-07 04:56:45 -04:00
import { VideoPrivacy } from '@shared/models'
import {
cleanupTests,
createSingleServer,
killallServers,
PeerTubeServer,
setAccessTokensToServers,
waitJobs
} from '@shared/server-commands'
describe('Test redundancy constraints', function () {
2021-07-16 03:47:51 -04:00
let remoteServer: PeerTubeServer
let localServer: PeerTubeServer
let servers: PeerTubeServer[]
2021-02-01 05:57:21 -05: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 03:04:35 -04:00
const { id } = await localServer.videos.upload({ attributes: { name: 'to transcode', privacy: VideoPrivacy.PRIVATE } })
2021-02-01 05:57:21 -05:00
await waitJobs([ localServer ])
// Update video to schedule a federation
2021-07-16 03:04:35 -04:00
await localServer.videos.update({ id, attributes: { name: videoName, privacy: VideoPrivacy.PUBLIC } })
2021-02-01 05:57:21 -05:00
}
async function getTotalRedundanciesLocalServer () {
2021-07-16 03:04:35 -04:00
const body = await localServer.redundancy.listVideos({ target: 'my-videos' })
2021-07-07 04:56:45 -04:00
return body.total
}
async function getTotalRedundanciesRemoteServer () {
2021-07-16 03:04:35 -04:00
const body = await remoteServer.redundancy.listVideos({ target: 'remote-videos' })
2021-07-07 04:56:45 -04:00
return body.total
}
before(async function () {
this.timeout(120000)
{
2021-07-16 03:47:51 -04:00
remoteServer = await createSingleServer(1, remoteServerConfig)
}
{
const config = {
remote_redundancy: {
videos: {
accept_from: 'nobody'
}
}
}
2021-07-16 03:47:51 -04:00
localServer = await createSingleServer(2, config)
}
servers = [ remoteServer, localServer ]
// Get the access tokens
await setAccessTokensToServers(servers)
2021-07-16 03:04:35 -04:00
await localServer.videos.upload({ attributes: { name: 'video 1 server 2' } })
await waitJobs(servers)
// Server 1 and server 2 follow each other
await remoteServer.follows.follow({ hosts: [ localServer.url ] })
await waitJobs(servers)
2021-07-16 03:04:35 -04: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 03:04:35 -04: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-16 04:42:24 -04:00
await killallServers([ localServer ])
2021-07-16 03:47:51 -04:00
await localServer.run(config)
2021-02-01 05:57:21 -05:00
await uploadWrapper('video 2 server 2')
2021-07-16 03:04:35 -04: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 09:37:43 -04:00
await killallServers([ localServer ])
2021-07-16 03:47:51 -04:00
await localServer.run(config)
2021-02-01 05:57:21 -05:00
await uploadWrapper('video 3 server 2')
2021-07-16 03:04:35 -04: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)
await localServer.follows.follow({ hosts: [ remoteServer.url ] })
await waitJobs(servers)
2021-02-01 05:57:21 -05:00
await uploadWrapper('video 4 server 2')
2021-07-16 03:04:35 -04: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)
})
})