X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fredundancy%2Fredundancy.ts;h=e4ea99de6c2223973218a09f66593446a6613f5e;hb=a2470c9f4bfc7f49f4b94de935bacdd53fd54f29;hp=0e0a73b9ddc3b9a0063fdd5a4178b07616d0c98b;hpb=5e8dd6e08ac1595aeb72c6b5b2c7d2c6aced8b47;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index 0e0a73b9d..e4ea99de6 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts @@ -5,14 +5,13 @@ import * as chai from 'chai' import { readdir } from 'fs-extra' import * as magnetUtil from 'magnet-uri' import { join } from 'path' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { checkSegmentHash, checkVideoFilesWereRemoved, cleanupTests, doubleFollow, flushAndRunMultipleServers, - getFollowingListPaginationAndSort, getVideo, getVideoWithToken, immutableAssign, @@ -23,25 +22,14 @@ import { root, ServerInfo, setAccessTokensToServers, - unfollow, updateVideo, uploadVideo, viewVideo, wait, + 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 { getStats } from '../../../../shared/extra-utils/server/stats' -import { ActorFollow } from '../../../../shared/models/actors' -import { VideoRedundancy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '../../../../shared/models/redundancy' -import { ServerStats } from '../../../../shared/models/server/server-stats.model' -import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos' +} from '@shared/extra-utils' +import { VideoDetails, VideoPrivacy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '@shared/models' const expect = chai.expect @@ -244,9 +232,7 @@ async function checkStatsGlobal (strategy: VideoRedundancyStrategyWithManual) { statsLength = 2 } - const res = await getStats(servers[0].url) - const data: ServerStats = res.body - + const data = await servers[0].statsCommand.get() expect(data.videosRedundancy).to.have.lengthOf(statsLength) const stat = data.videosRedundancy[0] @@ -272,14 +258,20 @@ async function checkStatsWithoutRedundancy (strategy: VideoRedundancyStrategyWit expect(stat.totalVideos).to.equal(0) } -async function enableRedundancyOnServer1 () { - await updateRedundancy(servers[0].url, servers[0].accessToken, servers[1].host, true) - - const res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 5, sort: '-createdAt' }) - const follows: ActorFollow[] = res.body.data +async function findServerFollows () { + const body = await servers[0].followsCommand.getFollowings({ start: 0, count: 5, sort: '-createdAt' }) + const follows = body.data const server2 = follows.find(f => f.following.host === `localhost:${servers[1].port}`) const server3 = follows.find(f => f.following.host === `localhost:${servers[2].port}`) + return { server2, server3 } +} + +async function enableRedundancyOnServer1 () { + await servers[0].redundancyCommand.updateRedundancy({ host: servers[1].host, redundancyAllowed: true }) + + const { server2, server3 } = await findServerFollows() + expect(server3).to.not.be.undefined expect(server3.following.hostRedundancyAllowed).to.be.false @@ -288,12 +280,9 @@ async function enableRedundancyOnServer1 () { } async function disableRedundancyOnServer1 () { - await updateRedundancy(servers[0].url, servers[0].accessToken, servers[1].host, false) + await servers[0].redundancyCommand.updateRedundancy({ host: servers[1].host, redundancyAllowed: false }) - const res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 5, sort: '-createdAt' }) - const follows: ActorFollow[] = res.body.data - const server2 = follows.find(f => f.following.host === `localhost:${servers[1].port}`) - const server3 = follows.find(f => f.following.host === `localhost:${servers[2].port}`) + const { server2, server3 } = await findServerFollows() expect(server3).to.not.be.undefined expect(server3.following.hostRedundancyAllowed).to.be.false @@ -388,7 +377,7 @@ describe('Test videos redundancy', function () { it('Should unfollow on server 1 and remove duplicated videos', async function () { this.timeout(80000) - await unfollow(servers[0].url, servers[0].accessToken, servers[1]) + await servers[0].followsCommand.unfollow({ target: servers[1] }) await waitJobs(servers) await wait(5000) @@ -551,11 +540,7 @@ describe('Test videos redundancy', function () { }) it('Should create a redundancy on first video', async function () { - await addVideoRedundancy({ - url: servers[0].url, - accessToken: servers[0].accessToken, - videoId: video1Server2Id - }) + await servers[0].redundancyCommand.addVideo({ videoId: video1Server2Id }) }) it('Should have 2 webseeds on the first video', async function () { @@ -573,22 +558,15 @@ describe('Test videos redundancy', function () { it('Should manually remove redundancies on server 1 and remove duplicated videos', async function () { this.timeout(80000) - const res = await listVideoRedundancies({ - url: servers[0].url, - accessToken: servers[0].accessToken, - target: 'remote-videos' - }) + const body = await servers[0].redundancyCommand.listVideos({ target: 'remote-videos' }) - const videos = res.body.data as VideoRedundancy[] + const videos = body.data expect(videos).to.have.lengthOf(1) const video = videos[0] + for (const r of video.redundancies.files.concat(video.redundancies.streamingPlaylists)) { - await removeVideoRedundancy({ - url: servers[0].url, - accessToken: servers[0].accessToken, - redundancyId: r.id - }) + await servers[0].redundancyCommand.removeVideo({ redundancyId: r.id }) } await waitJobs(servers)