2020-04-07 09:27:41 -04:00
|
|
|
/* 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'
|
2021-12-17 05:58:15 -05:00
|
|
|
import {
|
|
|
|
cleanupTests,
|
|
|
|
createSingleServer,
|
|
|
|
killallServers,
|
|
|
|
PeerTubeServer,
|
|
|
|
setAccessTokensToServers,
|
|
|
|
waitJobs
|
|
|
|
} from '@shared/server-commands'
|
2020-04-07 09:27:41 -04:00
|
|
|
|
|
|
|
describe('Test redundancy constraints', function () {
|
2021-07-16 03:47:51 -04:00
|
|
|
let remoteServer: PeerTubeServer
|
|
|
|
let localServer: PeerTubeServer
|
|
|
|
let servers: PeerTubeServer[]
|
2020-04-07 09:27:41 -04:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-04-07 09:27:41 -04:00
|
|
|
async function getTotalRedundanciesLocalServer () {
|
2021-07-16 03:04:35 -04:00
|
|
|
const body = await localServer.redundancy.listVideos({ target: 'my-videos' })
|
2020-04-07 09:27:41 -04:00
|
|
|
|
2021-07-07 04:56:45 -04:00
|
|
|
return body.total
|
2020-04-07 09:27:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
async function getTotalRedundanciesRemoteServer () {
|
2021-07-16 03:04:35 -04:00
|
|
|
const body = await remoteServer.redundancy.listVideos({ target: 'remote-videos' })
|
2020-04-07 09:27:41 -04:00
|
|
|
|
2021-07-07 04:56:45 -04:00
|
|
|
return body.total
|
2020-04-07 09:27:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(120000)
|
|
|
|
|
|
|
|
{
|
2021-07-16 03:47:51 -04:00
|
|
|
remoteServer = await createSingleServer(1, remoteServerConfig)
|
2020-04-07 09:27:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const config = {
|
|
|
|
remote_redundancy: {
|
|
|
|
videos: {
|
|
|
|
accept_from: 'nobody'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-07-16 03:47:51 -04:00
|
|
|
localServer = await createSingleServer(2, config)
|
2020-04-07 09:27:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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' } })
|
2020-04-07 09:27:41 -04:00
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
// Server 1 and server 2 follow each other
|
2021-07-20 08:15:15 -04:00
|
|
|
await remoteServer.follows.follow({ hosts: [ localServer.url ] })
|
2020-04-07 09:27:41 -04:00
|
|
|
await waitJobs(servers)
|
2021-07-16 03:04:35 -04:00
|
|
|
await remoteServer.redundancy.updateRedundancy({ host: localServer.host, redundancyAllowed: true })
|
2020-04-07 09:27:41 -04:00
|
|
|
|
|
|
|
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)
|
2020-04-07 09:27:41 -04:00
|
|
|
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)
|
2020-04-07 09:27:41 -04:00
|
|
|
|
2021-02-01 05:57:21 -05:00
|
|
|
await uploadWrapper('video 2 server 2')
|
2020-04-07 09:27:41 -04:00
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
await remoteServer.servers.waitUntilLog('Duplicated ', 10)
|
2020-04-07 09:27:41 -04:00
|
|
|
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)
|
2020-04-07 09:27:41 -04:00
|
|
|
|
2021-02-01 05:57:21 -05:00
|
|
|
await uploadWrapper('video 3 server 2')
|
2020-04-07 09:27:41 -04:00
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
await remoteServer.servers.waitUntilLog('Duplicated ', 15)
|
2020-04-07 09:27:41 -04:00
|
|
|
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-20 08:15:15 -04:00
|
|
|
await localServer.follows.follow({ hosts: [ remoteServer.url ] })
|
2020-04-07 09:27:41 -04:00
|
|
|
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)
|
2020-04-07 09:27:41 -04:00
|
|
|
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)
|
|
|
|
})
|
|
|
|
})
|