X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fserver%2Fhandle-down.ts;h=1d524aa9351d6275aa514213b56b09430a8dc185;hb=6a9b3151822461a85bbc72b7a50e12ffb69bec3a;hp=35b905a8c8c9357d4895ed1adb9712a04de163e9;hpb=d23dd9fbfc4d26026352c10f81d2795ceaf2908a;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts index 35b905a8c..1d524aa93 100644 --- a/server/tests/api/server/handle-down.ts +++ b/server/tests/api/server/handle-down.ts @@ -1,26 +1,23 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import 'mocha' -import * as chai from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { expect } from 'chai' +import { completeVideoCheck, SQLCommand } from '@server/tests/shared' +import { wait } from '@shared/core-utils' +import { HttpStatusCode, JobState, VideoCreateResult, VideoPrivacy } from '@shared/models' import { cleanupTests, CommentsCommand, - completeVideoCheck, - flushAndRunMultipleServers, + createMultipleServers, killallServers, - reRunServer, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, - wait, waitJobs -} from '@shared/extra-utils' -import { JobState, VideoCreateResult, VideoPrivacy } from '@shared/models' - -const expect = chai.expect +} from '@shared/server-commands' describe('Test handle downs', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] + let sqlCommands: SQLCommand[] = [] + let threadIdServer1: number let threadIdServer2: number let commentIdServer1: number @@ -52,10 +49,10 @@ describe('Test handle downs', function () { let commentCommands: CommentsCommand[] before(async function () { - this.timeout(30000) + this.timeout(120000) - servers = await flushAndRunMultipleServers(3) - commentCommands = servers.map(s => s.commentsCommand) + servers = await createMultipleServers(3) + commentCommands = servers.map(s => s.comments) checkAttributes = { name: 'my super name for server 1', @@ -67,7 +64,7 @@ describe('Test handle downs', function () { support: 'my super support text for server 1', account: { name: 'root', - host: 'localhost:' + servers[0].port + host: servers[0].host }, isLocal: false, duration: 10, @@ -93,25 +90,27 @@ describe('Test handle downs', function () { // Get the access tokens await setAccessTokensToServers(servers) + + sqlCommands = servers.map(s => new SQLCommand(s)) }) it('Should remove followers that are often down', async function () { this.timeout(240000) // Server 2 and 3 follow server 1 - await servers[1].followsCommand.follow({ targets: [ servers[0].url ] }) - await servers[2].followsCommand.follow({ targets: [ servers[0].url ] }) + await servers[1].follows.follow({ hosts: [ servers[0].url ] }) + await servers[2].follows.follow({ hosts: [ servers[0].url ] }) await waitJobs(servers) // Upload a video to server 1 - await servers[0].videosCommand.upload({ attributes: videoAttributes }) + await servers[0].videos.upload({ attributes: videoAttributes }) await waitJobs(servers) // And check all servers have this video for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() expect(data).to.be.an('array') expect(data).to.have.lengthOf(1) } @@ -121,7 +120,7 @@ describe('Test handle downs', function () { // Remove server 2 follower for (let i = 0; i < 10; i++) { - await servers[0].videosCommand.upload({ attributes: videoAttributes }) + await servers[0].videos.upload({ attributes: videoAttributes }) } await waitJobs([ servers[0], servers[2] ]) @@ -129,12 +128,12 @@ describe('Test handle downs', function () { // Kill server 3 await killallServers([ servers[2] ]) - missedVideo1 = await servers[0].videosCommand.upload({ attributes: videoAttributes }) + missedVideo1 = await servers[0].videos.upload({ attributes: videoAttributes }) - missedVideo2 = await servers[0].videosCommand.upload({ attributes: videoAttributes }) + missedVideo2 = await servers[0].videos.upload({ attributes: videoAttributes }) // Unlisted video - unlistedVideo = await servers[0].videosCommand.upload({ attributes: unlistedVideoAttributes }) + unlistedVideo = await servers[0].videos.upload({ attributes: unlistedVideoAttributes }) // Add comments to video 2 { @@ -153,18 +152,18 @@ describe('Test handle downs', function () { await wait(11000) // Only server 3 is still a follower of server 1 - const body = await servers[0].followsCommand.getFollowers({ start: 0, count: 2, sort: 'createdAt' }) + const body = await servers[0].follows.getFollowers({ start: 0, count: 2, sort: 'createdAt' }) expect(body.data).to.be.an('array') expect(body.data).to.have.lengthOf(1) - expect(body.data[0].follower.host).to.equal('localhost:' + servers[2].port) + expect(body.data[0].follower.host).to.equal(servers[2].host) }) it('Should not have pending/processing jobs anymore', async function () { const states: JobState[] = [ 'waiting', 'active' ] for (const state of states) { - const body = await servers[0].jobsCommand.getJobsList({ - state: state, + const body = await servers[0].jobs.list({ + state, start: 0, count: 50, sort: '-createdAt' @@ -174,19 +173,19 @@ describe('Test handle downs', function () { }) it('Should re-follow server 1', async function () { - this.timeout(35000) + this.timeout(70000) - await reRunServer(servers[1]) - await reRunServer(servers[2]) + await servers[1].run() + await servers[2].run() - await servers[1].followsCommand.unfollow({ target: servers[0] }) + await servers[1].follows.unfollow({ target: servers[0] }) await waitJobs(servers) - await servers[1].followsCommand.follow({ targets: [ servers[0].url ] }) + await servers[1].follows.follow({ hosts: [ servers[0].url ] }) await waitJobs(servers) - const body = await servers[0].followsCommand.getFollowers({ start: 0, count: 2, sort: 'createdAt' }) + const body = await servers[0].follows.getFollowers({ start: 0, count: 2, sort: 'createdAt' }) expect(body.data).to.be.an('array') expect(body.data).to.have.lengthOf(2) }) @@ -195,26 +194,26 @@ describe('Test handle downs', function () { this.timeout(15000) { - const { data } = await servers[2].videosCommand.list() + const { data } = await servers[2].videos.list() expect(data).to.be.an('array') expect(data).to.have.lengthOf(11) } - await servers[0].videosCommand.update({ id: missedVideo1.uuid }) - await servers[0].videosCommand.update({ id: unlistedVideo.uuid }) + await servers[0].videos.update({ id: missedVideo1.uuid }) + await servers[0].videos.update({ id: unlistedVideo.uuid }) await waitJobs(servers) { - const { data } = await servers[2].videosCommand.list() + const { data } = await servers[2].videos.list() expect(data).to.be.an('array') // 1 video is unlisted expect(data).to.have.lengthOf(12) } // Check unlisted video - const video = await servers[2].videosCommand.get({ id: unlistedVideo.uuid }) - await completeVideoCheck(servers[2], video, unlistedCheckAttributes) + const video = await servers[2].videos.get({ id: unlistedVideo.uuid }) + await completeVideoCheck({ server: servers[2], originServer: servers[0], videoUUID: video.uuid, attributes: unlistedCheckAttributes }) }) it('Should send comments on a video to server 3, and automatically fetch the video', async function () { @@ -224,16 +223,16 @@ describe('Test handle downs', function () { await waitJobs(servers) - await servers[2].videosCommand.get({ id: missedVideo2.uuid }) + await servers[2].videos.get({ id: missedVideo2.uuid }) { - const { data } = await servers[2].commentsCommand.listThreads({ videoId: missedVideo2.uuid }) + const { data } = await servers[2].comments.listThreads({ videoId: missedVideo2.uuid }) expect(data).to.be.an('array') expect(data).to.have.lengthOf(1) threadIdServer2 = data[0].id - const tree = await servers[2].commentsCommand.getThread({ videoId: missedVideo2.uuid, threadId: threadIdServer2 }) + const tree = await servers[2].comments.getThread({ videoId: missedVideo2.uuid, threadId: threadIdServer2 }) expect(tree.comment.text).equal('thread 1') expect(tree.children).to.have.lengthOf(1) @@ -256,7 +255,7 @@ describe('Test handle downs', function () { it('Should correctly reply to the comment', async function () { this.timeout(15000) - await servers[2].commentsCommand.addReply({ videoId: missedVideo2.uuid, toCommentId: commentIdServer2, text: 'comment 1-4' }) + await servers[2].comments.addReply({ videoId: missedVideo2.uuid, toCommentId: commentIdServer2, text: 'comment 1-4' }) await waitJobs(servers) @@ -283,27 +282,27 @@ describe('Test handle downs', function () { }) it('Should upload many videos on server 1', async function () { - this.timeout(120000) + this.timeout(240000) for (let i = 0; i < 10; i++) { - const uuid = (await servers[0].videosCommand.quickUpload({ name: 'video ' + i })).uuid + const uuid = (await servers[0].videos.quickUpload({ name: 'video ' + i })).uuid videoIdsServer1.push(uuid) } await waitJobs(servers) for (const id of videoIdsServer1) { - await servers[1].videosCommand.get({ id }) + await servers[1].videos.get({ id }) } await waitJobs(servers) - await servers[1].sqlCommand.setActorFollowScores(20) + await sqlCommands[1].setActorFollowScores(20) // Wait video expiration await wait(11000) // Refresh video -> score + 10 = 30 - await servers[1].videosCommand.get({ id: videoIdsServer1[0] }) + await servers[1].videos.get({ id: videoIdsServer1[0] }) await waitJobs(servers) }) @@ -318,18 +317,22 @@ describe('Test handle downs', function () { for (let i = 0; i < 5; i++) { try { - await servers[1].videosCommand.get({ id: videoIdsServer1[i] }) + await servers[1].videos.get({ id: videoIdsServer1[i] }) await waitJobs([ servers[1] ]) await wait(1500) } catch {} } for (const id of videoIdsServer1) { - await servers[1].videosCommand.get({ id, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) + await servers[1].videos.get({ id, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) } }) after(async function () { + for (const sqlCommand of sqlCommands) { + await sqlCommand.cleanup() + } + await cleanupTests(servers) }) })