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

325 lines
9.1 KiB
TypeScript
Raw Normal View History

2020-01-31 16:56:52 +01:00
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2020-01-10 10:11:28 +01:00
2022-08-17 15:44:32 +02:00
import { expect } from 'chai'
2020-01-10 10:11:28 +01:00
import {
cleanupTests,
2021-07-16 09:47:51 +02:00
createMultipleServers,
2021-07-16 14:27:30 +02:00
doubleFollow,
2021-07-16 09:47:51 +02:00
PeerTubeServer,
2021-07-16 14:27:30 +02:00
RedundancyCommand,
2020-01-10 10:11:28 +01:00
setAccessTokensToServers,
2021-07-13 09:43:59 +02:00
waitJobs
} from '@shared/server-commands'
2021-07-07 10:56:45 +02:00
import { VideoPrivacy, VideoRedundanciesTarget } from '@shared/models'
2020-01-10 10:11:28 +01:00
describe('Test manage videos redundancy', function () {
const targets: VideoRedundanciesTarget[] = [ 'my-videos', 'remote-videos' ]
2021-07-16 09:47:51 +02:00
let servers: PeerTubeServer[]
2020-01-10 10:11:28 +01:00
let video1Server2UUID: string
let video2Server2UUID: string
let redundanciesToRemove: number[] = []
2021-07-07 10:56:45 +02:00
let commands: RedundancyCommand[]
2020-01-10 10:11:28 +01:00
before(async function () {
this.timeout(120000)
const config = {
transcoding: {
hls: {
enabled: true
}
},
redundancy: {
videos: {
check_interval: '1 second',
strategies: [
{
strategy: 'recently-added',
min_lifetime: '1 hour',
size: '10MB',
min_views: 0
}
]
}
}
}
2021-07-16 09:47:51 +02:00
servers = await createMultipleServers(3, config)
2020-01-10 10:11:28 +01:00
// Get the access tokens
await setAccessTokensToServers(servers)
2021-07-16 09:04:35 +02:00
commands = servers.map(s => s.redundancy)
2021-07-07 10:56:45 +02:00
2020-01-10 10:11:28 +01:00
{
2021-07-16 09:04:35 +02:00
const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video 1 server 2' } })
2021-07-15 10:02:54 +02:00
video1Server2UUID = uuid
2020-01-10 10:11:28 +01:00
}
{
2021-07-16 09:04:35 +02:00
const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video 2 server 2' } })
2021-07-15 10:02:54 +02:00
video2Server2UUID = uuid
2020-01-10 10:11:28 +01:00
}
await waitJobs(servers)
// Server 1 and server 2 follow each other
2020-01-31 16:56:52 +01:00
await doubleFollow(servers[0], servers[1])
await doubleFollow(servers[0], servers[2])
2021-07-07 10:56:45 +02:00
await commands[0].updateRedundancy({ host: servers[1].host, redundancyAllowed: true })
2020-01-10 10:11:28 +01:00
await waitJobs(servers)
})
it('Should not have redundancies on server 3', async function () {
for (const target of targets) {
2021-07-07 10:56:45 +02:00
const body = await commands[2].listVideos({ target })
2020-01-10 10:11:28 +01:00
2021-07-07 10:56:45 +02:00
expect(body.total).to.equal(0)
expect(body.data).to.have.lengthOf(0)
2020-01-10 10:11:28 +01:00
}
})
it('Should correctly list followings by redundancy', async function () {
const body = await servers[0].follows.getFollowings({ sort: '-redundancyAllowed' })
expect(body.total).to.equal(2)
expect(body.data).to.have.lengthOf(2)
expect(body.data[0].following.host).to.equal(servers[1].host)
expect(body.data[1].following.host).to.equal(servers[2].host)
})
2020-01-10 10:11:28 +01:00
it('Should not have "remote-videos" redundancies on server 2', async function () {
this.timeout(120000)
await waitJobs(servers)
2021-07-16 09:04:35 +02:00
await servers[0].servers.waitUntilLog('Duplicated ', 10)
2020-01-10 10:11:28 +01:00
await waitJobs(servers)
2021-07-07 10:56:45 +02:00
const body = await commands[1].listVideos({ target: 'remote-videos' })
2020-01-10 10:11:28 +01:00
2021-07-07 10:56:45 +02:00
expect(body.total).to.equal(0)
expect(body.data).to.have.lengthOf(0)
2020-01-10 10:11:28 +01:00
})
it('Should have "my-videos" redundancies on server 2', async function () {
this.timeout(120000)
2021-07-07 10:56:45 +02:00
const body = await commands[1].listVideos({ target: 'my-videos' })
expect(body.total).to.equal(2)
2020-01-10 10:11:28 +01:00
2021-07-07 10:56:45 +02:00
const videos = body.data
2020-01-10 10:11:28 +01:00
expect(videos).to.have.lengthOf(2)
const videos1 = videos.find(v => v.uuid === video1Server2UUID)
const videos2 = videos.find(v => v.uuid === video2Server2UUID)
expect(videos1.name).to.equal('video 1 server 2')
expect(videos2.name).to.equal('video 2 server 2')
expect(videos1.redundancies.files).to.have.lengthOf(4)
expect(videos1.redundancies.streamingPlaylists).to.have.lengthOf(1)
const redundancies = videos1.redundancies.files.concat(videos1.redundancies.streamingPlaylists)
for (const r of redundancies) {
expect(r.strategy).to.be.null
expect(r.fileUrl).to.exist
expect(r.createdAt).to.exist
expect(r.updatedAt).to.exist
expect(r.expiresOn).to.exist
}
})
it('Should not have "my-videos" redundancies on server 1', async function () {
2021-07-07 10:56:45 +02:00
const body = await commands[0].listVideos({ target: 'my-videos' })
2020-01-10 10:11:28 +01:00
2021-07-07 10:56:45 +02:00
expect(body.total).to.equal(0)
expect(body.data).to.have.lengthOf(0)
2020-01-10 10:11:28 +01:00
})
it('Should have "remote-videos" redundancies on server 1', async function () {
this.timeout(120000)
2021-07-07 10:56:45 +02:00
const body = await commands[0].listVideos({ target: 'remote-videos' })
expect(body.total).to.equal(2)
2020-01-10 10:11:28 +01:00
2021-07-07 10:56:45 +02:00
const videos = body.data
2020-01-10 10:11:28 +01:00
expect(videos).to.have.lengthOf(2)
const videos1 = videos.find(v => v.uuid === video1Server2UUID)
const videos2 = videos.find(v => v.uuid === video2Server2UUID)
expect(videos1.name).to.equal('video 1 server 2')
expect(videos2.name).to.equal('video 2 server 2')
expect(videos1.redundancies.files).to.have.lengthOf(4)
expect(videos1.redundancies.streamingPlaylists).to.have.lengthOf(1)
const redundancies = videos1.redundancies.files.concat(videos1.redundancies.streamingPlaylists)
for (const r of redundancies) {
expect(r.strategy).to.equal('recently-added')
expect(r.fileUrl).to.exist
expect(r.createdAt).to.exist
expect(r.updatedAt).to.exist
expect(r.expiresOn).to.exist
}
})
it('Should correctly paginate and sort results', async function () {
{
2021-07-07 10:56:45 +02:00
const body = await commands[0].listVideos({
2020-01-10 10:11:28 +01:00
target: 'remote-videos',
sort: 'name',
start: 0,
count: 2
})
2021-07-07 10:56:45 +02:00
const videos = body.data
2020-01-31 16:56:52 +01:00
expect(videos[0].name).to.equal('video 1 server 2')
expect(videos[1].name).to.equal('video 2 server 2')
2020-01-10 10:11:28 +01:00
}
{
2021-07-07 10:56:45 +02:00
const body = await commands[0].listVideos({
2020-01-10 10:11:28 +01:00
target: 'remote-videos',
sort: '-name',
start: 0,
count: 2
})
2021-07-07 10:56:45 +02:00
const videos = body.data
2020-01-31 16:56:52 +01:00
expect(videos[0].name).to.equal('video 2 server 2')
expect(videos[1].name).to.equal('video 1 server 2')
2020-01-10 10:11:28 +01:00
}
{
2021-07-07 10:56:45 +02:00
const body = await commands[0].listVideos({
2020-01-10 10:11:28 +01:00
target: 'remote-videos',
sort: '-name',
start: 1,
count: 1
})
2021-07-07 10:56:45 +02:00
expect(body.data[0].name).to.equal('video 1 server 2')
2020-01-10 10:11:28 +01:00
}
})
it('Should manually add a redundancy and list it', async function () {
this.timeout(120000)
2021-07-16 09:04:35 +02:00
const uuid = (await servers[1].videos.quickUpload({ name: 'video 3 server 2', privacy: VideoPrivacy.UNLISTED })).uuid
2020-01-10 10:11:28 +01:00
await waitJobs(servers)
2021-07-16 09:04:35 +02:00
const videoId = await servers[0].videos.getId({ uuid })
2020-01-10 10:11:28 +01:00
2021-07-07 10:56:45 +02:00
await commands[0].addVideo({ videoId })
2020-01-10 10:11:28 +01:00
await waitJobs(servers)
2021-07-16 09:04:35 +02:00
await servers[0].servers.waitUntilLog('Duplicated ', 15)
2020-01-10 10:11:28 +01:00
await waitJobs(servers)
{
2021-07-07 10:56:45 +02:00
const body = await commands[0].listVideos({
2020-01-10 10:11:28 +01:00
target: 'remote-videos',
sort: '-name',
start: 0,
count: 5
})
2021-07-07 10:56:45 +02:00
const video = body.data[0]
2020-01-10 10:11:28 +01:00
2021-07-07 10:56:45 +02:00
expect(video.name).to.equal('video 3 server 2')
2020-01-10 10:11:28 +01:00
expect(video.redundancies.files).to.have.lengthOf(4)
expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1)
const redundancies = video.redundancies.files.concat(video.redundancies.streamingPlaylists)
for (const r of redundancies) {
redundanciesToRemove.push(r.id)
expect(r.strategy).to.equal('manual')
expect(r.fileUrl).to.exist
expect(r.createdAt).to.exist
expect(r.updatedAt).to.exist
expect(r.expiresOn).to.be.null
}
}
2021-07-07 10:56:45 +02:00
const body = await commands[1].listVideos({
2020-01-10 10:11:28 +01:00
target: 'my-videos',
sort: '-name',
start: 0,
count: 5
})
2021-07-07 10:56:45 +02:00
const video = body.data[0]
expect(video.name).to.equal('video 3 server 2')
2020-01-10 10:11:28 +01:00
expect(video.redundancies.files).to.have.lengthOf(4)
expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1)
const redundancies = video.redundancies.files.concat(video.redundancies.streamingPlaylists)
for (const r of redundancies) {
expect(r.strategy).to.be.null
expect(r.fileUrl).to.exist
expect(r.createdAt).to.exist
expect(r.updatedAt).to.exist
expect(r.expiresOn).to.be.null
}
})
it('Should manually remove a redundancy and remove it from the list', async function () {
this.timeout(120000)
for (const redundancyId of redundanciesToRemove) {
2021-07-07 10:56:45 +02:00
await commands[0].removeVideo({ redundancyId })
2020-01-10 10:11:28 +01:00
}
{
2021-07-07 10:56:45 +02:00
const body = await commands[0].listVideos({
2020-01-10 10:11:28 +01:00
target: 'remote-videos',
sort: '-name',
start: 0,
count: 5
})
2021-07-07 10:56:45 +02:00
const videos = body.data
2020-01-10 10:11:28 +01:00
2021-07-07 10:56:45 +02:00
expect(videos).to.have.lengthOf(2)
2020-01-10 10:11:28 +01:00
2020-01-31 16:56:52 +01:00
const video = videos[0]
2021-07-07 10:56:45 +02:00
expect(video.name).to.equal('video 2 server 2')
2020-01-10 10:11:28 +01:00
expect(video.redundancies.files).to.have.lengthOf(4)
expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1)
const redundancies = video.redundancies.files.concat(video.redundancies.streamingPlaylists)
2021-07-07 10:56:45 +02:00
redundanciesToRemove = redundancies.map(r => r.id)
2020-01-10 10:11:28 +01:00
}
})
it('Should remove another (auto) redundancy', async function () {
2021-07-07 10:56:45 +02:00
for (const redundancyId of redundanciesToRemove) {
await commands[0].removeVideo({ redundancyId })
}
2020-01-10 10:11:28 +01:00
2021-07-07 10:56:45 +02:00
const body = await commands[0].listVideos({
target: 'remote-videos',
sort: '-name',
start: 0,
count: 5
})
2020-01-10 10:11:28 +01:00
2021-07-07 10:56:45 +02:00
const videos = body.data
expect(videos).to.have.lengthOf(1)
expect(videos[0].name).to.equal('video 1 server 2')
2020-01-10 10:11:28 +01:00
})
after(async function () {
await cleanupTests(servers)
})
})