X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fserver%2Fhandle-down.ts;h=1d524aa9351d6275aa514213b56b09430a8dc185;hb=6a9b3151822461a85bbc72b7a50e12ffb69bec3a;hp=1f751c957025aa6cfc228b2805a3a2fa6b5dab23;hpb=4c7e60bc17ee5830399bac4aa273356903421b4c;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts index 1f751c957..1d524aa93 100644 --- a/server/tests/api/server/handle-down.ts +++ b/server/tests/api/server/handle-down.ts @@ -1,24 +1,23 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import 'mocha' -import * as chai from 'chai' +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, createMultipleServers, killallServers, PeerTubeServer, setAccessTokensToServers, - wait, waitJobs -} from '@shared/extra-utils' -import { HttpStatusCode, JobState, VideoCreateResult, VideoPrivacy } from '@shared/models' - -const expect = chai.expect +} from '@shared/server-commands' describe('Test handle downs', function () { let servers: PeerTubeServer[] = [] + let sqlCommands: SQLCommand[] = [] + let threadIdServer1: number let threadIdServer2: number let commentIdServer1: number @@ -50,7 +49,7 @@ describe('Test handle downs', function () { let commentCommands: CommentsCommand[] before(async function () { - this.timeout(30000) + this.timeout(120000) servers = await createMultipleServers(3) commentCommands = servers.map(s => s.comments) @@ -65,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, @@ -91,14 +90,16 @@ 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].follows.follow({ targets: [ servers[0].url ] }) - await servers[2].follows.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) @@ -154,15 +155,15 @@ describe('Test handle downs', function () { 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].jobs.getJobsList({ - state: state, + const body = await servers[0].jobs.list({ + state, start: 0, count: 50, sort: '-createdAt' @@ -172,7 +173,7 @@ describe('Test handle downs', function () { }) it('Should re-follow server 1', async function () { - this.timeout(35000) + this.timeout(70000) await servers[1].run() await servers[2].run() @@ -180,7 +181,7 @@ describe('Test handle downs', function () { await servers[1].follows.unfollow({ target: servers[0] }) await waitJobs(servers) - await servers[1].follows.follow({ targets: [ servers[0].url ] }) + await servers[1].follows.follow({ hosts: [ servers[0].url ] }) await waitJobs(servers) @@ -212,7 +213,7 @@ describe('Test handle downs', function () { // Check unlisted video const video = await servers[2].videos.get({ id: unlistedVideo.uuid }) - await completeVideoCheck(servers[2], video, unlistedCheckAttributes) + 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 () { @@ -281,7 +282,7 @@ 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].videos.quickUpload({ name: 'video ' + i })).uuid @@ -295,7 +296,7 @@ describe('Test handle downs', function () { } await waitJobs(servers) - await servers[1].sql.setActorFollowScores(20) + await sqlCommands[1].setActorFollowScores(20) // Wait video expiration await wait(11000) @@ -328,6 +329,10 @@ describe('Test handle downs', function () { }) after(async function () { + for (const sqlCommand of sqlCommands) { + await sqlCommand.cleanup() + } + await cleanupTests(servers) }) })