From c3d29f694bf8c910f917be655626d0f80871124f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 09:16:40 +0200 Subject: Introduce follows command --- server/tests/api/redundancy/redundancy.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'server/tests/api/redundancy/redundancy.ts') diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index 0e0a73b9d..dfe8099ed 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts @@ -12,7 +12,6 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getFollowingListPaginationAndSort, getVideo, getVideoWithToken, immutableAssign, @@ -23,7 +22,6 @@ import { root, ServerInfo, setAccessTokensToServers, - unfollow, updateVideo, uploadVideo, viewVideo, @@ -38,7 +36,6 @@ import { 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' @@ -272,13 +269,19 @@ async function checkStatsWithoutRedundancy (strategy: VideoRedundancyStrategyWit expect(stat.totalVideos).to.equal(0) } +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 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 - 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 @@ -290,10 +293,7 @@ async function enableRedundancyOnServer1 () { async function disableRedundancyOnServer1 () { await updateRedundancy(servers[0].url, servers[0].accessToken, servers[1].host, 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 +388,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) -- cgit v1.2.3 From dab047092b51b453f175069573d8865fb17acdfc Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 10:56:45 +0200 Subject: Introduce redundancy command --- server/tests/api/redundancy/redundancy.ts | 49 ++++++++++++------------------- 1 file changed, 19 insertions(+), 30 deletions(-) (limited to 'server/tests/api/redundancy/redundancy.ts') diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index dfe8099ed..5b970473c 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts @@ -5,7 +5,8 @@ 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 { removeVideoRedundancy } from '@server/lib/redundancy' +import { HttpStatusCode } from '@shared/core-utils' import { checkSegmentHash, checkVideoFilesWereRemoved, @@ -26,19 +27,18 @@ import { uploadVideo, viewVideo, wait, + waitJobs, waitUntilLog -} from '../../../../shared/extra-utils' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' +} from '@shared/extra-utils' +import { getStats } from '@shared/extra-utils/server/stats' import { - addVideoRedundancy, - listVideoRedundancies, - removeVideoRedundancy, - updateRedundancy -} from '../../../../shared/extra-utils/server/redundancy' -import { getStats } from '../../../../shared/extra-utils/server/stats' -import { VideoRedundancy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '../../../../shared/models/redundancy' -import { ServerStats } from '../../../../shared/models/server/server-stats.model' -import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos' + ServerStats, + VideoDetails, + VideoPrivacy, + VideoRedundancy, + VideoRedundancyStrategy, + VideoRedundancyStrategyWithManual +} from '@shared/models' const expect = chai.expect @@ -279,7 +279,7 @@ async function findServerFollows () { } async function enableRedundancyOnServer1 () { - await updateRedundancy(servers[0].url, servers[0].accessToken, servers[1].host, true) + await servers[0].redundancyCommand.updateRedundancy({ host: servers[1].host, redundancyAllowed: true }) const { server2, server3 } = await findServerFollows() @@ -291,7 +291,7 @@ 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 { server2, server3 } = await findServerFollows() @@ -551,11 +551,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 +569,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) -- cgit v1.2.3 From bc8090411ddaa8d742ce4de3c83f9dba7bc18e2a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 11:07:12 +0200 Subject: Introduce stats command --- server/tests/api/redundancy/redundancy.ts | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) (limited to 'server/tests/api/redundancy/redundancy.ts') diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index 5b970473c..e4ea99de6 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts @@ -5,7 +5,6 @@ import * as chai from 'chai' import { readdir } from 'fs-extra' import * as magnetUtil from 'magnet-uri' import { join } from 'path' -import { removeVideoRedundancy } from '@server/lib/redundancy' import { HttpStatusCode } from '@shared/core-utils' import { checkSegmentHash, @@ -30,15 +29,7 @@ import { waitJobs, waitUntilLog } from '@shared/extra-utils' -import { getStats } from '@shared/extra-utils/server/stats' -import { - ServerStats, - VideoDetails, - VideoPrivacy, - VideoRedundancy, - VideoRedundancyStrategy, - VideoRedundancyStrategyWithManual -} from '@shared/models' +import { VideoDetails, VideoPrivacy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '@shared/models' const expect = chai.expect @@ -241,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] -- cgit v1.2.3 From 57f879a540551c3b958b0991c8e1e3657a4481d8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Jul 2021 10:21:10 +0200 Subject: Introduce streaming playlists command --- server/tests/api/redundancy/redundancy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'server/tests/api/redundancy/redundancy.ts') diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index e4ea99de6..d20cb80f1 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts @@ -203,7 +203,7 @@ async function check1PlaylistRedundancies (videoUUID?: string) { const hlsPlaylist = (res.body as VideoDetails).streamingPlaylists[0] for (const resolution of [ 240, 360, 480, 720 ]) { - await checkSegmentHash(baseUrlPlaylist, baseUrlSegment, videoUUID, resolution, hlsPlaylist) + await checkSegmentHash({ server: servers[1], baseUrlPlaylist, baseUrlSegment, videoUUID, resolution, hlsPlaylist }) } const directories = [ -- cgit v1.2.3 From 9293139fde7091e9badcafa9b570b83cea9a10ad Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Jul 2021 15:37:43 +0200 Subject: Introduce sql command --- server/tests/api/redundancy/redundancy.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'server/tests/api/redundancy/redundancy.ts') diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index d20cb80f1..56a2af395 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts @@ -634,7 +634,7 @@ describe('Test videos redundancy', function () { it('Should stop server 1 and expire video redundancy', async function () { this.timeout(80000) - killallServers([ servers[0] ]) + await killallServers([ servers[0] ]) await wait(15000) @@ -703,7 +703,7 @@ describe('Test videos redundancy', function () { await waitJobs(servers) - killallServers([ servers[0] ]) + await killallServers([ servers[0] ]) await reRunServer(servers[0], { redundancy: { videos: { -- cgit v1.2.3 From 6c5065a011b099618681a37bd77eaa7bd3db752e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 13 Jul 2021 09:43:59 +0200 Subject: Introduce server commands --- server/tests/api/redundancy/redundancy.ts | 36 +++++++++++++++---------------- 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'server/tests/api/redundancy/redundancy.ts') diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index 56a2af395..00a5e86cc 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts @@ -14,7 +14,6 @@ import { flushAndRunMultipleServers, getVideo, getVideoWithToken, - immutableAssign, killallServers, makeGetRequest, removeVideo, @@ -26,8 +25,7 @@ import { uploadVideo, viewVideo, wait, - waitJobs, - waitUntilLog + waitJobs } from '@shared/extra-utils' import { VideoDetails, VideoPrivacy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '@shared/models' @@ -53,11 +51,13 @@ async function flushAndRunServers (strategy: VideoRedundancyStrategy | null, add if (strategy !== null) { strategies.push( - immutableAssign({ + { min_lifetime: '1 hour', strategy: strategy, - size: '400KB' - }, additionalParams) + size: '400KB', + + ...additionalParams + } ) } @@ -316,7 +316,7 @@ describe('Test videos redundancy', function () { this.timeout(80000) await waitJobs(servers) - await waitUntilLog(servers[0], 'Duplicated ', 5) + await servers[0].serversCommand.waitUntilLog('Duplicated ', 5) await waitJobs(servers) await check2Webseeds() @@ -335,7 +335,7 @@ describe('Test videos redundancy', function () { await check1WebSeed() await check0PlaylistRedundancies() - await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].internalServerNumber, [ 'videos', join('playlists', 'hls') ]) + await checkVideoFilesWereRemoved(video1Server2UUID, servers[0], [ 'videos', join('playlists', 'hls') ]) }) after(async function () { @@ -366,7 +366,7 @@ describe('Test videos redundancy', function () { this.timeout(80000) await waitJobs(servers) - await waitUntilLog(servers[0], 'Duplicated ', 5) + await servers[0].serversCommand.waitUntilLog('Duplicated ', 5) await waitJobs(servers) await check2Webseeds() @@ -385,7 +385,7 @@ describe('Test videos redundancy', function () { await check1WebSeed() await check0PlaylistRedundancies() - await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].internalServerNumber, [ 'videos' ]) + await checkVideoFilesWereRemoved(video1Server2UUID, servers[0], [ 'videos' ]) }) after(async function () { @@ -438,7 +438,7 @@ describe('Test videos redundancy', function () { this.timeout(80000) await waitJobs(servers) - await waitUntilLog(servers[0], 'Duplicated ', 5) + await servers[0].serversCommand.waitUntilLog('Duplicated ', 5) await waitJobs(servers) await check2Webseeds() @@ -454,7 +454,7 @@ describe('Test videos redundancy', function () { await waitJobs(servers) for (const server of servers) { - await checkVideoFilesWereRemoved(video1Server2UUID, server.internalServerNumber) + await checkVideoFilesWereRemoved(video1Server2UUID, server) } }) @@ -502,7 +502,7 @@ describe('Test videos redundancy', function () { await waitJobs(servers) await waitJobs(servers) - await waitUntilLog(servers[0], 'Duplicated ', 1) + await servers[0].serversCommand.waitUntilLog('Duplicated ', 1) await waitJobs(servers) await check1PlaylistRedundancies() @@ -517,7 +517,7 @@ describe('Test videos redundancy', function () { await waitJobs(servers) for (const server of servers) { - await checkVideoFilesWereRemoved(video1Server2UUID, server.internalServerNumber) + await checkVideoFilesWereRemoved(video1Server2UUID, server) } }) @@ -547,7 +547,7 @@ describe('Test videos redundancy', function () { this.timeout(80000) await waitJobs(servers) - await waitUntilLog(servers[0], 'Duplicated ', 5) + await servers[0].serversCommand.waitUntilLog('Duplicated ', 5) await waitJobs(servers) await check2Webseeds() @@ -575,7 +575,7 @@ describe('Test videos redundancy', function () { await check1WebSeed() await check0PlaylistRedundancies() - await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ 'videos' ]) + await checkVideoFilesWereRemoved(video1Server2UUID, servers[0], [ 'videos' ]) }) after(async function () { @@ -658,7 +658,7 @@ describe('Test videos redundancy', function () { await enableRedundancyOnServer1() await waitJobs(servers) - await waitUntilLog(servers[0], 'Duplicated ', 5) + await servers[0].serversCommand.waitUntilLog('Duplicated ', 5) await waitJobs(servers) await check2Webseeds(video1Server2UUID) @@ -715,7 +715,7 @@ describe('Test videos redundancy', function () { await waitJobs(servers) - await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].internalServerNumber, [ join('redundancy', 'hls') ]) + await checkVideoFilesWereRemoved(video1Server2UUID, servers[0], [ join('redundancy', 'hls') ]) }) after(async function () { -- cgit v1.2.3 From d23dd9fbfc4d26026352c10f81d2795ceaf2908a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 15 Jul 2021 10:02:54 +0200 Subject: Introduce videos command --- server/tests/api/redundancy/redundancy.ts | 57 ++++++++++++------------------- 1 file changed, 22 insertions(+), 35 deletions(-) (limited to 'server/tests/api/redundancy/redundancy.ts') diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index 00a5e86cc..6ca9c9303 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts @@ -12,22 +12,16 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideo, - getVideoWithToken, killallServers, makeGetRequest, - removeVideo, reRunServer, root, ServerInfo, setAccessTokensToServers, - updateVideo, - uploadVideo, - viewVideo, wait, waitJobs } from '@shared/extra-utils' -import { VideoDetails, VideoPrivacy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '@shared/models' +import { VideoPrivacy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '@shared/models' const expect = chai.expect @@ -84,11 +78,11 @@ async function flushAndRunServers (strategy: VideoRedundancyStrategy | null, add await setAccessTokensToServers(servers) { - const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' }) - video1Server2UUID = res.body.video.uuid - video1Server2Id = res.body.video.id + const { uuid, id } = await servers[1].videosCommand.upload({ attributes: { name: 'video 1 server 2' } }) + video1Server2UUID = uuid + video1Server2Id = id - await viewVideo(servers[1].url, video1Server2UUID) + await servers[1].videosCommand.view({ id: video1Server2UUID }) } await waitJobs(servers) @@ -112,9 +106,8 @@ async function check1WebSeed (videoUUID?: string) { for (const server of servers) { // With token to avoid issues with video follow constraints - const res = await getVideoWithToken(server.url, server.accessToken, videoUUID) + const video = await server.videosCommand.getWithToken({ id: videoUUID }) - const video: VideoDetails = res.body for (const f of video.files) { checkMagnetWebseeds(f, webseeds, server) } @@ -130,9 +123,7 @@ async function check2Webseeds (videoUUID?: string) { ] for (const server of servers) { - const res = await getVideo(server.url, videoUUID) - - const video: VideoDetails = res.body + const video = await server.videosCommand.get({ id: videoUUID }) for (const file of video.files) { checkMagnetWebseeds(file, webseeds, server) @@ -172,8 +163,7 @@ async function check0PlaylistRedundancies (videoUUID?: string) { for (const server of servers) { // With token to avoid issues with video follow constraints - const res = await getVideoWithToken(server.url, server.accessToken, videoUUID) - const video: VideoDetails = res.body + const video = await server.videosCommand.getWithToken({ id: videoUUID }) expect(video.streamingPlaylists).to.be.an('array') expect(video.streamingPlaylists).to.have.lengthOf(1) @@ -185,8 +175,7 @@ async function check1PlaylistRedundancies (videoUUID?: string) { if (!videoUUID) videoUUID = video1Server2UUID for (const server of servers) { - const res = await getVideo(server.url, videoUUID) - const video: VideoDetails = res.body + const video = await server.videosCommand.get({ id: videoUUID }) expect(video.streamingPlaylists).to.have.lengthOf(1) expect(video.streamingPlaylists[0].redundancies).to.have.lengthOf(1) @@ -199,8 +188,8 @@ async function check1PlaylistRedundancies (videoUUID?: string) { const baseUrlPlaylist = servers[1].url + '/static/streaming-playlists/hls' const baseUrlSegment = servers[0].url + '/static/redundancy/hls' - const res = await getVideo(servers[0].url, videoUUID) - const hlsPlaylist = (res.body as VideoDetails).streamingPlaylists[0] + const video = await servers[0].videosCommand.get({ id: videoUUID }) + const hlsPlaylist = video.streamingPlaylists[0] for (const resolution of [ 240, 360, 480, 720 ]) { await checkSegmentHash({ server: servers[1], baseUrlPlaylist, baseUrlSegment, videoUUID, resolution, hlsPlaylist }) @@ -427,8 +416,8 @@ describe('Test videos redundancy', function () { it('Should view 2 times the first video to have > min_views config', async function () { this.timeout(80000) - await viewVideo(servers[0].url, video1Server2UUID) - await viewVideo(servers[2].url, video1Server2UUID) + await servers[0].videosCommand.view({ id: video1Server2UUID }) + await servers[2].videosCommand.view({ id: video1Server2UUID }) await wait(10000) await waitJobs(servers) @@ -449,7 +438,7 @@ describe('Test videos redundancy', function () { it('Should remove the video and the redundancy files', async function () { this.timeout(20000) - await removeVideo(servers[1].url, servers[1].accessToken, video1Server2UUID) + await servers[1].videosCommand.remove({ id: video1Server2UUID }) await waitJobs(servers) @@ -495,8 +484,8 @@ describe('Test videos redundancy', function () { it('Should have 1 redundancy on the first video', async function () { this.timeout(160000) - await viewVideo(servers[0].url, video1Server2UUID) - await viewVideo(servers[2].url, video1Server2UUID) + await servers[0].videosCommand.view({ id: video1Server2UUID }) + await servers[2].videosCommand.view({ id: video1Server2UUID }) await wait(10000) await waitJobs(servers) @@ -512,7 +501,7 @@ describe('Test videos redundancy', function () { it('Should remove the video and the redundancy files', async function () { this.timeout(20000) - await removeVideo(servers[1].url, servers[1].accessToken, video1Server2UUID) + await servers[1].videosCommand.remove({ id: video1Server2UUID }) await waitJobs(servers) @@ -588,8 +577,7 @@ describe('Test videos redundancy', function () { async function checkContains (servers: ServerInfo[], str: string) { for (const server of servers) { - const res = await getVideo(server.url, video1Server2UUID) - const video: VideoDetails = res.body + const video = await server.videosCommand.get({ id: video1Server2UUID }) for (const f of video.files) { expect(f.magnetUri).to.contain(str) @@ -599,8 +587,7 @@ describe('Test videos redundancy', function () { async function checkNotContains (servers: ServerInfo[], str: string) { for (const server of servers) { - const res = await getVideo(server.url, video1Server2UUID) - const video: VideoDetails = res.body + const video = await server.videosCommand.get({ id: video1Server2UUID }) for (const f of video.files) { expect(f.magnetUri).to.not.contain(str) @@ -665,13 +652,13 @@ describe('Test videos redundancy', function () { await check1PlaylistRedundancies(video1Server2UUID) await checkStatsWith1Redundancy(strategy) - const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 2 server 2', privacy: VideoPrivacy.PRIVATE }) - video2Server2UUID = res.body.video.uuid + const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video 2 server 2', privacy: VideoPrivacy.PRIVATE } }) + video2Server2UUID = uuid // Wait transcoding before federation await waitJobs(servers) - await updateVideo(servers[1].url, servers[1].accessToken, video2Server2UUID, { privacy: VideoPrivacy.PUBLIC }) + await servers[1].videosCommand.update({ id: video2Server2UUID, attributes: { privacy: VideoPrivacy.PUBLIC } }) }) it('Should cache video 2 webseeds on the first video', async function () { -- cgit v1.2.3 From 89d241a79c262b9775c233b73cff080043ebb5e6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 09:04:35 +0200 Subject: Shorter server command names --- server/tests/api/redundancy/redundancy.ts | 62 +++++++++++++++---------------- 1 file changed, 31 insertions(+), 31 deletions(-) (limited to 'server/tests/api/redundancy/redundancy.ts') diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index 6ca9c9303..77ea2278e 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts @@ -78,11 +78,11 @@ async function flushAndRunServers (strategy: VideoRedundancyStrategy | null, add await setAccessTokensToServers(servers) { - const { uuid, id } = await servers[1].videosCommand.upload({ attributes: { name: 'video 1 server 2' } }) + const { uuid, id } = await servers[1].videos.upload({ attributes: { name: 'video 1 server 2' } }) video1Server2UUID = uuid video1Server2Id = id - await servers[1].videosCommand.view({ id: video1Server2UUID }) + await servers[1].videos.view({ id: video1Server2UUID }) } await waitJobs(servers) @@ -106,7 +106,7 @@ async function check1WebSeed (videoUUID?: string) { for (const server of servers) { // With token to avoid issues with video follow constraints - const video = await server.videosCommand.getWithToken({ id: videoUUID }) + const video = await server.videos.getWithToken({ id: videoUUID }) for (const f of video.files) { checkMagnetWebseeds(f, webseeds, server) @@ -123,7 +123,7 @@ async function check2Webseeds (videoUUID?: string) { ] for (const server of servers) { - const video = await server.videosCommand.get({ id: videoUUID }) + const video = await server.videos.get({ id: videoUUID }) for (const file of video.files) { checkMagnetWebseeds(file, webseeds, server) @@ -163,7 +163,7 @@ async function check0PlaylistRedundancies (videoUUID?: string) { for (const server of servers) { // With token to avoid issues with video follow constraints - const video = await server.videosCommand.getWithToken({ id: videoUUID }) + const video = await server.videos.getWithToken({ id: videoUUID }) expect(video.streamingPlaylists).to.be.an('array') expect(video.streamingPlaylists).to.have.lengthOf(1) @@ -175,7 +175,7 @@ async function check1PlaylistRedundancies (videoUUID?: string) { if (!videoUUID) videoUUID = video1Server2UUID for (const server of servers) { - const video = await server.videosCommand.get({ id: videoUUID }) + const video = await server.videos.get({ id: videoUUID }) expect(video.streamingPlaylists).to.have.lengthOf(1) expect(video.streamingPlaylists[0].redundancies).to.have.lengthOf(1) @@ -188,7 +188,7 @@ async function check1PlaylistRedundancies (videoUUID?: string) { const baseUrlPlaylist = servers[1].url + '/static/streaming-playlists/hls' const baseUrlSegment = servers[0].url + '/static/redundancy/hls' - const video = await servers[0].videosCommand.get({ id: videoUUID }) + const video = await servers[0].videos.get({ id: videoUUID }) const hlsPlaylist = video.streamingPlaylists[0] for (const resolution of [ 240, 360, 480, 720 ]) { @@ -221,7 +221,7 @@ async function checkStatsGlobal (strategy: VideoRedundancyStrategyWithManual) { statsLength = 2 } - const data = await servers[0].statsCommand.get() + const data = await servers[0].stats.get() expect(data.videosRedundancy).to.have.lengthOf(statsLength) const stat = data.videosRedundancy[0] @@ -248,7 +248,7 @@ async function checkStatsWithoutRedundancy (strategy: VideoRedundancyStrategyWit } async function findServerFollows () { - const body = await servers[0].followsCommand.getFollowings({ start: 0, count: 5, sort: '-createdAt' }) + const body = await servers[0].follows.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}`) @@ -257,7 +257,7 @@ async function findServerFollows () { } async function enableRedundancyOnServer1 () { - await servers[0].redundancyCommand.updateRedundancy({ host: servers[1].host, redundancyAllowed: true }) + await servers[0].redundancy.updateRedundancy({ host: servers[1].host, redundancyAllowed: true }) const { server2, server3 } = await findServerFollows() @@ -269,7 +269,7 @@ async function enableRedundancyOnServer1 () { } async function disableRedundancyOnServer1 () { - await servers[0].redundancyCommand.updateRedundancy({ host: servers[1].host, redundancyAllowed: false }) + await servers[0].redundancy.updateRedundancy({ host: servers[1].host, redundancyAllowed: false }) const { server2, server3 } = await findServerFollows() @@ -305,7 +305,7 @@ describe('Test videos redundancy', function () { this.timeout(80000) await waitJobs(servers) - await servers[0].serversCommand.waitUntilLog('Duplicated ', 5) + await servers[0].servers.waitUntilLog('Duplicated ', 5) await waitJobs(servers) await check2Webseeds() @@ -355,7 +355,7 @@ describe('Test videos redundancy', function () { this.timeout(80000) await waitJobs(servers) - await servers[0].serversCommand.waitUntilLog('Duplicated ', 5) + await servers[0].servers.waitUntilLog('Duplicated ', 5) await waitJobs(servers) await check2Webseeds() @@ -366,7 +366,7 @@ describe('Test videos redundancy', function () { it('Should unfollow on server 1 and remove duplicated videos', async function () { this.timeout(80000) - await servers[0].followsCommand.unfollow({ target: servers[1] }) + await servers[0].follows.unfollow({ target: servers[1] }) await waitJobs(servers) await wait(5000) @@ -416,8 +416,8 @@ describe('Test videos redundancy', function () { it('Should view 2 times the first video to have > min_views config', async function () { this.timeout(80000) - await servers[0].videosCommand.view({ id: video1Server2UUID }) - await servers[2].videosCommand.view({ id: video1Server2UUID }) + await servers[0].videos.view({ id: video1Server2UUID }) + await servers[2].videos.view({ id: video1Server2UUID }) await wait(10000) await waitJobs(servers) @@ -427,7 +427,7 @@ describe('Test videos redundancy', function () { this.timeout(80000) await waitJobs(servers) - await servers[0].serversCommand.waitUntilLog('Duplicated ', 5) + await servers[0].servers.waitUntilLog('Duplicated ', 5) await waitJobs(servers) await check2Webseeds() @@ -438,7 +438,7 @@ describe('Test videos redundancy', function () { it('Should remove the video and the redundancy files', async function () { this.timeout(20000) - await servers[1].videosCommand.remove({ id: video1Server2UUID }) + await servers[1].videos.remove({ id: video1Server2UUID }) await waitJobs(servers) @@ -484,14 +484,14 @@ describe('Test videos redundancy', function () { it('Should have 1 redundancy on the first video', async function () { this.timeout(160000) - await servers[0].videosCommand.view({ id: video1Server2UUID }) - await servers[2].videosCommand.view({ id: video1Server2UUID }) + await servers[0].videos.view({ id: video1Server2UUID }) + await servers[2].videos.view({ id: video1Server2UUID }) await wait(10000) await waitJobs(servers) await waitJobs(servers) - await servers[0].serversCommand.waitUntilLog('Duplicated ', 1) + await servers[0].servers.waitUntilLog('Duplicated ', 1) await waitJobs(servers) await check1PlaylistRedundancies() @@ -501,7 +501,7 @@ describe('Test videos redundancy', function () { it('Should remove the video and the redundancy files', async function () { this.timeout(20000) - await servers[1].videosCommand.remove({ id: video1Server2UUID }) + await servers[1].videos.remove({ id: video1Server2UUID }) await waitJobs(servers) @@ -529,14 +529,14 @@ describe('Test videos redundancy', function () { }) it('Should create a redundancy on first video', async function () { - await servers[0].redundancyCommand.addVideo({ videoId: video1Server2Id }) + await servers[0].redundancy.addVideo({ videoId: video1Server2Id }) }) it('Should have 2 webseeds on the first video', async function () { this.timeout(80000) await waitJobs(servers) - await servers[0].serversCommand.waitUntilLog('Duplicated ', 5) + await servers[0].servers.waitUntilLog('Duplicated ', 5) await waitJobs(servers) await check2Webseeds() @@ -547,7 +547,7 @@ describe('Test videos redundancy', function () { it('Should manually remove redundancies on server 1 and remove duplicated videos', async function () { this.timeout(80000) - const body = await servers[0].redundancyCommand.listVideos({ target: 'remote-videos' }) + const body = await servers[0].redundancy.listVideos({ target: 'remote-videos' }) const videos = body.data expect(videos).to.have.lengthOf(1) @@ -555,7 +555,7 @@ describe('Test videos redundancy', function () { const video = videos[0] for (const r of video.redundancies.files.concat(video.redundancies.streamingPlaylists)) { - await servers[0].redundancyCommand.removeVideo({ redundancyId: r.id }) + await servers[0].redundancy.removeVideo({ redundancyId: r.id }) } await waitJobs(servers) @@ -577,7 +577,7 @@ describe('Test videos redundancy', function () { async function checkContains (servers: ServerInfo[], str: string) { for (const server of servers) { - const video = await server.videosCommand.get({ id: video1Server2UUID }) + const video = await server.videos.get({ id: video1Server2UUID }) for (const f of video.files) { expect(f.magnetUri).to.contain(str) @@ -587,7 +587,7 @@ describe('Test videos redundancy', function () { async function checkNotContains (servers: ServerInfo[], str: string) { for (const server of servers) { - const video = await server.videosCommand.get({ id: video1Server2UUID }) + const video = await server.videos.get({ id: video1Server2UUID }) for (const f of video.files) { expect(f.magnetUri).to.not.contain(str) @@ -645,20 +645,20 @@ describe('Test videos redundancy', function () { await enableRedundancyOnServer1() await waitJobs(servers) - await servers[0].serversCommand.waitUntilLog('Duplicated ', 5) + await servers[0].servers.waitUntilLog('Duplicated ', 5) await waitJobs(servers) await check2Webseeds(video1Server2UUID) await check1PlaylistRedundancies(video1Server2UUID) await checkStatsWith1Redundancy(strategy) - const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video 2 server 2', privacy: VideoPrivacy.PRIVATE } }) + const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video 2 server 2', privacy: VideoPrivacy.PRIVATE } }) video2Server2UUID = uuid // Wait transcoding before federation await waitJobs(servers) - await servers[1].videosCommand.update({ id: video2Server2UUID, attributes: { privacy: VideoPrivacy.PUBLIC } }) + await servers[1].videos.update({ id: video2Server2UUID, attributes: { privacy: VideoPrivacy.PUBLIC } }) }) it('Should cache video 2 webseeds on the first video', async function () { -- cgit v1.2.3 From 254d3579f5338f5fd775c17d15cdfc37078bcfb4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 09:47:51 +0200 Subject: Use an object to represent a server --- server/tests/api/redundancy/redundancy.ts | 33 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'server/tests/api/redundancy/redundancy.ts') diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index 77ea2278e..9d5d96efd 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts @@ -11,12 +11,11 @@ import { checkVideoFilesWereRemoved, cleanupTests, doubleFollow, - flushAndRunMultipleServers, + createMultipleServers, killallServers, makeGetRequest, - reRunServer, root, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, wait, waitJobs @@ -25,11 +24,11 @@ import { VideoPrivacy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManua const expect = chai.expect -let servers: ServerInfo[] = [] +let servers: PeerTubeServer[] = [] let video1Server2UUID: string let video1Server2Id: number -function checkMagnetWebseeds (file: { magnetUri: string, resolution: { id: number } }, baseWebseeds: string[], server: ServerInfo) { +function checkMagnetWebseeds (file: { magnetUri: string, resolution: { id: number } }, baseWebseeds: string[], server: PeerTubeServer) { const parsed = magnetUtil.decode(file.magnetUri) for (const ws of baseWebseeds) { @@ -40,7 +39,7 @@ function checkMagnetWebseeds (file: { magnetUri: string, resolution: { id: numbe expect(parsed.urlList).to.have.lengthOf(baseWebseeds.length) } -async function flushAndRunServers (strategy: VideoRedundancyStrategy | null, additionalParams: any = {}, withWebtorrent = true) { +async function createSingleServers (strategy: VideoRedundancyStrategy | null, additionalParams: any = {}, withWebtorrent = true) { const strategies: any[] = [] if (strategy !== null) { @@ -72,7 +71,7 @@ async function flushAndRunServers (strategy: VideoRedundancyStrategy | null, add } } - servers = await flushAndRunMultipleServers(3, config) + servers = await createMultipleServers(3, config) // Get the access tokens await setAccessTokensToServers(servers) @@ -288,7 +287,7 @@ describe('Test videos redundancy', function () { before(function () { this.timeout(120000) - return flushAndRunServers(strategy) + return createSingleServers(strategy) }) it('Should have 1 webseed on the first video', async function () { @@ -338,7 +337,7 @@ describe('Test videos redundancy', function () { before(function () { this.timeout(120000) - return flushAndRunServers(strategy) + return createSingleServers(strategy) }) it('Should have 1 webseed on the first video', async function () { @@ -388,7 +387,7 @@ describe('Test videos redundancy', function () { before(function () { this.timeout(120000) - return flushAndRunServers(strategy, { min_views: 3 }) + return createSingleServers(strategy, { min_views: 3 }) }) it('Should have 1 webseed on the first video', async function () { @@ -458,7 +457,7 @@ describe('Test videos redundancy', function () { before(async function () { this.timeout(120000) - await flushAndRunServers(strategy, { min_views: 3 }, false) + await createSingleServers(strategy, { min_views: 3 }, false) }) it('Should have 0 playlist redundancy on the first video', async function () { @@ -519,7 +518,7 @@ describe('Test videos redundancy', function () { before(function () { this.timeout(120000) - return flushAndRunServers(null) + return createSingleServers(null) }) it('Should have 1 webseed on the first video', async function () { @@ -575,7 +574,7 @@ describe('Test videos redundancy', function () { describe('Test expiration', function () { const strategy = 'recently-added' - async function checkContains (servers: ServerInfo[], str: string) { + async function checkContains (servers: PeerTubeServer[], str: string) { for (const server of servers) { const video = await server.videos.get({ id: video1Server2UUID }) @@ -585,7 +584,7 @@ describe('Test videos redundancy', function () { } } - async function checkNotContains (servers: ServerInfo[], str: string) { + async function checkNotContains (servers: PeerTubeServer[], str: string) { for (const server of servers) { const video = await server.videos.get({ id: video1Server2UUID }) @@ -598,7 +597,7 @@ describe('Test videos redundancy', function () { before(async function () { this.timeout(120000) - await flushAndRunServers(strategy, { min_lifetime: '7 seconds', min_views: 0 }) + await createSingleServers(strategy, { min_lifetime: '7 seconds', min_views: 0 }) await enableRedundancyOnServer1() }) @@ -640,7 +639,7 @@ describe('Test videos redundancy', function () { before(async function () { this.timeout(120000) - await flushAndRunServers(strategy, { min_lifetime: '7 seconds', min_views: 0 }) + await createSingleServers(strategy, { min_lifetime: '7 seconds', min_views: 0 }) await enableRedundancyOnServer1() @@ -691,7 +690,7 @@ describe('Test videos redundancy', function () { await waitJobs(servers) await killallServers([ servers[0] ]) - await reRunServer(servers[0], { + await servers[0].run({ redundancy: { videos: { check_interval: '1 second', -- cgit v1.2.3 From c0e8b12e7fd554ba4d2ceb0c4900804c6a4c63ea Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 10:42:24 +0200 Subject: Refactor requests --- server/tests/api/redundancy/redundancy.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'server/tests/api/redundancy/redundancy.ts') diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index 9d5d96efd..921a48856 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts @@ -5,7 +5,7 @@ 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' +import { HttpStatusCode } from '@shared/models' import { checkSegmentHash, checkVideoFilesWereRemoved, @@ -129,13 +129,13 @@ async function check2Webseeds (videoUUID?: string) { await makeGetRequest({ url: servers[0].url, - statusCodeExpected: HttpStatusCode.OK_200, + expectedStatus: HttpStatusCode.OK_200, path: '/static/redundancy/' + `${videoUUID}-${file.resolution.id}.mp4`, contentType: null }) await makeGetRequest({ url: servers[1].url, - statusCodeExpected: HttpStatusCode.OK_200, + expectedStatus: HttpStatusCode.OK_200, path: `/static/webseed/${videoUUID}-${file.resolution.id}.mp4`, contentType: null }) -- cgit v1.2.3 From 4c7e60bc17ee5830399bac4aa273356903421b4c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 14:27:30 +0200 Subject: Reorganize imports --- server/tests/api/redundancy/redundancy.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'server/tests/api/redundancy/redundancy.ts') diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index 921a48856..a6559d304 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts @@ -5,22 +5,21 @@ import * as chai from 'chai' import { readdir } from 'fs-extra' import * as magnetUtil from 'magnet-uri' import { join } from 'path' -import { HttpStatusCode } from '@shared/models' import { checkSegmentHash, checkVideoFilesWereRemoved, cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, killallServers, makeGetRequest, - root, PeerTubeServer, + root, setAccessTokensToServers, wait, waitJobs } from '@shared/extra-utils' -import { VideoPrivacy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '@shared/models' +import { HttpStatusCode, VideoPrivacy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '@shared/models' const expect = chai.expect -- cgit v1.2.3