mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 18:29:27 +02:00
Introduce redundancy command
This commit is contained in:
parent
ae2abfd3ae
commit
dab047092b
7 changed files with 166 additions and 247 deletions
|
@ -1,21 +1,21 @@
|
|||
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
||||
|
||||
import * as chai from 'chai'
|
||||
import 'mocha'
|
||||
import * as chai from 'chai'
|
||||
import {
|
||||
cleanupTests,
|
||||
doubleFollow,
|
||||
flushAndRunMultipleServers,
|
||||
getLocalIdByUUID,
|
||||
RedundancyCommand,
|
||||
ServerInfo,
|
||||
setAccessTokensToServers,
|
||||
uploadVideo,
|
||||
uploadVideoAndGetId,
|
||||
waitJobs,
|
||||
waitUntilLog
|
||||
} from '../../../../shared/extra-utils'
|
||||
import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
|
||||
import { addVideoRedundancy, listVideoRedundancies, removeVideoRedundancy, updateRedundancy } from '@shared/extra-utils/server/redundancy'
|
||||
import { VideoPrivacy, VideoRedundanciesTarget, VideoRedundancy } from '@shared/models'
|
||||
} from '@shared/extra-utils'
|
||||
import { VideoPrivacy, VideoRedundanciesTarget } from '@shared/models'
|
||||
|
||||
const expect = chai.expect
|
||||
|
||||
|
@ -27,6 +27,8 @@ describe('Test manage videos redundancy', function () {
|
|||
let video2Server2UUID: string
|
||||
let redundanciesToRemove: number[] = []
|
||||
|
||||
let commands: RedundancyCommand[]
|
||||
|
||||
before(async function () {
|
||||
this.timeout(120000)
|
||||
|
||||
|
@ -55,6 +57,8 @@ describe('Test manage videos redundancy', function () {
|
|||
// Get the access tokens
|
||||
await setAccessTokensToServers(servers)
|
||||
|
||||
commands = servers.map(s => s.redundancyCommand)
|
||||
|
||||
{
|
||||
const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' })
|
||||
video1Server2UUID = res.body.video.uuid
|
||||
|
@ -69,21 +73,17 @@ describe('Test manage videos redundancy', function () {
|
|||
|
||||
// Server 1 and server 2 follow each other
|
||||
await doubleFollow(servers[0], servers[1])
|
||||
await updateRedundancy(servers[0].url, servers[0].accessToken, servers[1].host, true)
|
||||
await commands[0].updateRedundancy({ host: servers[1].host, redundancyAllowed: true })
|
||||
|
||||
await waitJobs(servers)
|
||||
})
|
||||
|
||||
it('Should not have redundancies on server 3', async function () {
|
||||
for (const target of targets) {
|
||||
const res = await listVideoRedundancies({
|
||||
url: servers[2].url,
|
||||
accessToken: servers[2].accessToken,
|
||||
target
|
||||
})
|
||||
const body = await commands[2].listVideos({ target })
|
||||
|
||||
expect(res.body.total).to.equal(0)
|
||||
expect(res.body.data).to.have.lengthOf(0)
|
||||
expect(body.total).to.equal(0)
|
||||
expect(body.data).to.have.lengthOf(0)
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -94,28 +94,19 @@ describe('Test manage videos redundancy', function () {
|
|||
await waitUntilLog(servers[0], 'Duplicated ', 10)
|
||||
await waitJobs(servers)
|
||||
|
||||
const res = await listVideoRedundancies({
|
||||
url: servers[1].url,
|
||||
accessToken: servers[1].accessToken,
|
||||
target: 'remote-videos'
|
||||
})
|
||||
const body = await commands[1].listVideos({ target: 'remote-videos' })
|
||||
|
||||
expect(res.body.total).to.equal(0)
|
||||
expect(res.body.data).to.have.lengthOf(0)
|
||||
expect(body.total).to.equal(0)
|
||||
expect(body.data).to.have.lengthOf(0)
|
||||
})
|
||||
|
||||
it('Should have "my-videos" redundancies on server 2', async function () {
|
||||
this.timeout(120000)
|
||||
|
||||
const res = await listVideoRedundancies({
|
||||
url: servers[1].url,
|
||||
accessToken: servers[1].accessToken,
|
||||
target: 'my-videos'
|
||||
})
|
||||
const body = await commands[1].listVideos({ target: 'my-videos' })
|
||||
expect(body.total).to.equal(2)
|
||||
|
||||
expect(res.body.total).to.equal(2)
|
||||
|
||||
const videos = res.body.data as VideoRedundancy[]
|
||||
const videos = body.data
|
||||
expect(videos).to.have.lengthOf(2)
|
||||
|
||||
const videos1 = videos.find(v => v.uuid === video1Server2UUID)
|
||||
|
@ -139,28 +130,19 @@ describe('Test manage videos redundancy', function () {
|
|||
})
|
||||
|
||||
it('Should not have "my-videos" redundancies on server 1', async function () {
|
||||
const res = await listVideoRedundancies({
|
||||
url: servers[0].url,
|
||||
accessToken: servers[0].accessToken,
|
||||
target: 'my-videos'
|
||||
})
|
||||
const body = await commands[0].listVideos({ target: 'my-videos' })
|
||||
|
||||
expect(res.body.total).to.equal(0)
|
||||
expect(res.body.data).to.have.lengthOf(0)
|
||||
expect(body.total).to.equal(0)
|
||||
expect(body.data).to.have.lengthOf(0)
|
||||
})
|
||||
|
||||
it('Should have "remote-videos" redundancies on server 1', async function () {
|
||||
this.timeout(120000)
|
||||
|
||||
const res = await listVideoRedundancies({
|
||||
url: servers[0].url,
|
||||
accessToken: servers[0].accessToken,
|
||||
target: 'remote-videos'
|
||||
})
|
||||
const body = await commands[0].listVideos({ target: 'remote-videos' })
|
||||
expect(body.total).to.equal(2)
|
||||
|
||||
expect(res.body.total).to.equal(2)
|
||||
|
||||
const videos = res.body.data as VideoRedundancy[]
|
||||
const videos = body.data
|
||||
expect(videos).to.have.lengthOf(2)
|
||||
|
||||
const videos1 = videos.find(v => v.uuid === video1Server2UUID)
|
||||
|
@ -185,47 +167,40 @@ describe('Test manage videos redundancy', function () {
|
|||
|
||||
it('Should correctly paginate and sort results', async function () {
|
||||
{
|
||||
const res = await listVideoRedundancies({
|
||||
url: servers[0].url,
|
||||
accessToken: servers[0].accessToken,
|
||||
const body = await commands[0].listVideos({
|
||||
target: 'remote-videos',
|
||||
sort: 'name',
|
||||
start: 0,
|
||||
count: 2
|
||||
})
|
||||
|
||||
const videos = res.body.data
|
||||
const videos = body.data
|
||||
expect(videos[0].name).to.equal('video 1 server 2')
|
||||
expect(videos[1].name).to.equal('video 2 server 2')
|
||||
}
|
||||
|
||||
{
|
||||
const res = await listVideoRedundancies({
|
||||
url: servers[0].url,
|
||||
accessToken: servers[0].accessToken,
|
||||
const body = await commands[0].listVideos({
|
||||
target: 'remote-videos',
|
||||
sort: '-name',
|
||||
start: 0,
|
||||
count: 2
|
||||
})
|
||||
|
||||
const videos = res.body.data
|
||||
const videos = body.data
|
||||
expect(videos[0].name).to.equal('video 2 server 2')
|
||||
expect(videos[1].name).to.equal('video 1 server 2')
|
||||
}
|
||||
|
||||
{
|
||||
const res = await listVideoRedundancies({
|
||||
url: servers[0].url,
|
||||
accessToken: servers[0].accessToken,
|
||||
const body = await commands[0].listVideos({
|
||||
target: 'remote-videos',
|
||||
sort: '-name',
|
||||
start: 1,
|
||||
count: 1
|
||||
})
|
||||
|
||||
const videos = res.body.data
|
||||
expect(videos[0].name).to.equal('video 1 server 2')
|
||||
expect(body.data[0].name).to.equal('video 1 server 2')
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -236,30 +211,23 @@ describe('Test manage videos redundancy', function () {
|
|||
await waitJobs(servers)
|
||||
const videoId = await getLocalIdByUUID(servers[0].url, uuid)
|
||||
|
||||
await addVideoRedundancy({
|
||||
url: servers[0].url,
|
||||
accessToken: servers[0].accessToken,
|
||||
videoId
|
||||
})
|
||||
await commands[0].addVideo({ videoId })
|
||||
|
||||
await waitJobs(servers)
|
||||
await waitUntilLog(servers[0], 'Duplicated ', 15)
|
||||
await waitJobs(servers)
|
||||
|
||||
{
|
||||
const res = await listVideoRedundancies({
|
||||
url: servers[0].url,
|
||||
accessToken: servers[0].accessToken,
|
||||
const body = await commands[0].listVideos({
|
||||
target: 'remote-videos',
|
||||
sort: '-name',
|
||||
start: 0,
|
||||
count: 5
|
||||
})
|
||||
|
||||
const videos = res.body.data
|
||||
expect(videos[0].name).to.equal('video 3 server 2')
|
||||
const video = body.data[0]
|
||||
|
||||
const video = videos[0]
|
||||
expect(video.name).to.equal('video 3 server 2')
|
||||
expect(video.redundancies.files).to.have.lengthOf(4)
|
||||
expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1)
|
||||
|
||||
|
@ -276,19 +244,15 @@ describe('Test manage videos redundancy', function () {
|
|||
}
|
||||
}
|
||||
|
||||
const res = await listVideoRedundancies({
|
||||
url: servers[1].url,
|
||||
accessToken: servers[1].accessToken,
|
||||
const body = await commands[1].listVideos({
|
||||
target: 'my-videos',
|
||||
sort: '-name',
|
||||
start: 0,
|
||||
count: 5
|
||||
})
|
||||
|
||||
const videos = res.body.data
|
||||
expect(videos[0].name).to.equal('video 3 server 2')
|
||||
|
||||
const video = videos[0]
|
||||
const video = body.data[0]
|
||||
expect(video.name).to.equal('video 3 server 2')
|
||||
expect(video.redundancies.files).to.have.lengthOf(4)
|
||||
expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1)
|
||||
|
||||
|
@ -307,64 +271,47 @@ describe('Test manage videos redundancy', function () {
|
|||
this.timeout(120000)
|
||||
|
||||
for (const redundancyId of redundanciesToRemove) {
|
||||
await removeVideoRedundancy({
|
||||
url: servers[0].url,
|
||||
accessToken: servers[0].accessToken,
|
||||
redundancyId
|
||||
})
|
||||
await commands[0].removeVideo({ redundancyId })
|
||||
}
|
||||
|
||||
{
|
||||
const res = await listVideoRedundancies({
|
||||
url: servers[0].url,
|
||||
accessToken: servers[0].accessToken,
|
||||
const body = await commands[0].listVideos({
|
||||
target: 'remote-videos',
|
||||
sort: '-name',
|
||||
start: 0,
|
||||
count: 5
|
||||
})
|
||||
|
||||
const videos = res.body.data
|
||||
const videos = body.data
|
||||
|
||||
expect(videos).to.have.lengthOf(2)
|
||||
|
||||
expect(videos[0].name).to.equal('video 2 server 2')
|
||||
|
||||
redundanciesToRemove = []
|
||||
const video = videos[0]
|
||||
expect(video.name).to.equal('video 2 server 2')
|
||||
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)
|
||||
}
|
||||
redundanciesToRemove = redundancies.map(r => r.id)
|
||||
}
|
||||
})
|
||||
|
||||
it('Should remove another (auto) redundancy', async function () {
|
||||
{
|
||||
for (const redundancyId of redundanciesToRemove) {
|
||||
await removeVideoRedundancy({
|
||||
url: servers[0].url,
|
||||
accessToken: servers[0].accessToken,
|
||||
redundancyId
|
||||
})
|
||||
}
|
||||
|
||||
const res = await listVideoRedundancies({
|
||||
url: servers[0].url,
|
||||
accessToken: servers[0].accessToken,
|
||||
target: 'remote-videos',
|
||||
sort: '-name',
|
||||
start: 0,
|
||||
count: 5
|
||||
})
|
||||
|
||||
const videos = res.body.data
|
||||
expect(videos[0].name).to.equal('video 1 server 2')
|
||||
expect(videos).to.have.lengthOf(1)
|
||||
for (const redundancyId of redundanciesToRemove) {
|
||||
await commands[0].removeVideo({ redundancyId })
|
||||
}
|
||||
|
||||
const body = await commands[0].listVideos({
|
||||
target: 'remote-videos',
|
||||
sort: '-name',
|
||||
start: 0,
|
||||
count: 5
|
||||
})
|
||||
|
||||
const videos = body.data
|
||||
expect(videos).to.have.lengthOf(1)
|
||||
expect(videos[0].name).to.equal('video 1 server 2')
|
||||
})
|
||||
|
||||
after(async function () {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue