X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fserver%2Fhandle-down.ts;h=d45c3ae8a72441315d5e0f2031e181f65ce7fc94;hb=6c5065a011b099618681a37bd77eaa7bd3db752e;hp=fa1a3c4446612eac29572933d6a4d8c32ae45935;hpb=2b02c520e66ea452687cab39401b371711caa9ed;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts index fa1a3c444..d45c3ae8a 100644 --- a/server/tests/api/server/handle-down.ts +++ b/server/tests/api/server/handle-down.ts @@ -1,39 +1,26 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' -import { JobState, Video } from '../../../../shared/models' -import { VideoPrivacy } from '../../../../shared/models/videos' -import { VideoCommentThreadTree } from '../../../../shared/models/videos/comment/video-comment.model' - +import * as chai from 'chai' +import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, - closeAllSequelize, + CommentsCommand, completeVideoCheck, flushAndRunMultipleServers, getVideo, getVideosList, - immutableAssign, killallServers, reRunServer, ServerInfo, setAccessTokensToServers, - setActorFollowScores, - unfollow, updateVideo, uploadVideo, uploadVideoAndGetId, - wait -} from '../../../../shared/extra-utils' -import { follow, getFollowersListPaginationAndSort } from '../../../../shared/extra-utils/server/follows' -import { getJobsListPaginationAndSort, waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { - addVideoCommentReply, - addVideoCommentThread, - getVideoCommentThreads, - getVideoThreadComments -} from '../../../../shared/extra-utils/videos/video-comments' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' + wait, + waitJobs +} from '@shared/extra-utils' +import { JobState, Video, VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -47,7 +34,7 @@ describe('Test handle downs', function () { let missedVideo2: Video let unlistedVideo: Video - const videoIdsServer1: number[] = [] + const videoIdsServer1: string[] = [] const videoAttributes = { name: 'my super name for server 1', @@ -62,17 +49,18 @@ describe('Test handle downs', function () { fixture: 'video_short1.webm' } - const unlistedVideoAttributes = immutableAssign(videoAttributes, { - privacy: VideoPrivacy.UNLISTED - }) + const unlistedVideoAttributes = { ...videoAttributes, privacy: VideoPrivacy.UNLISTED } let checkAttributes: any let unlistedCheckAttributes: any + let commentCommands: CommentsCommand[] + before(async function () { this.timeout(30000) servers = await flushAndRunMultipleServers(3) + commentCommands = servers.map(s => s.commentsCommand) checkAttributes = { name: 'my super name for server 1', @@ -106,9 +94,7 @@ describe('Test handle downs', function () { } ] } - unlistedCheckAttributes = immutableAssign(checkAttributes, { - privacy: VideoPrivacy.UNLISTED - }) + unlistedCheckAttributes = { ...checkAttributes, privacy: VideoPrivacy.UNLISTED } // Get the access tokens await setAccessTokensToServers(servers) @@ -118,8 +104,8 @@ describe('Test handle downs', function () { this.timeout(240000) // Server 2 and 3 follow server 1 - await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken) - await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken) + await servers[1].followsCommand.follow({ targets: [ servers[0].url ] }) + await servers[2].followsCommand.follow({ targets: [ servers[0].url ] }) await waitJobs(servers) @@ -136,7 +122,7 @@ describe('Test handle downs', function () { } // Kill server 2 - killallServers([ servers[1] ]) + await killallServers([ servers[1] ]) // Remove server 2 follower for (let i = 0; i < 10; i++) { @@ -146,7 +132,7 @@ describe('Test handle downs', function () { await waitJobs([ servers[0], servers[2] ]) // Kill server 3 - killallServers([ servers[2] ]) + await killallServers([ servers[2] ]) const resLastVideo1 = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) missedVideo1 = resLastVideo1.body.video @@ -161,15 +147,13 @@ describe('Test handle downs', function () { // Add comments to video 2 { const text = 'thread 1' - let resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, missedVideo2.uuid, text) - let comment = resComment.body.comment + let comment = await commentCommands[0].createThread({ videoId: missedVideo2.uuid, text }) threadIdServer1 = comment.id - resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, missedVideo2.uuid, comment.id, 'comment 1-1') - comment = resComment.body.comment + comment = await commentCommands[0].addReply({ videoId: missedVideo2.uuid, toCommentId: comment.id, text: 'comment 1-1' }) - resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, missedVideo2.uuid, comment.id, 'comment 1-2') - commentIdServer1 = resComment.body.comment.id + const created = await commentCommands[0].addReply({ videoId: missedVideo2.uuid, toCommentId: comment.id, text: 'comment 1-2' }) + commentIdServer1 = created.id } await waitJobs(servers[0]) @@ -177,25 +161,23 @@ describe('Test handle downs', function () { await wait(11000) // Only server 3 is still a follower of server 1 - const res = await getFollowersListPaginationAndSort({ url: servers[0].url, start: 0, count: 2, sort: 'createdAt' }) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].follower.host).to.equal('localhost:' + servers[2].port) + const body = await servers[0].followsCommand.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) }) it('Should not have pending/processing jobs anymore', async function () { const states: JobState[] = [ 'waiting', 'active' ] for (const state of states) { - const res = await getJobsListPaginationAndSort({ - url: servers[0].url, - accessToken: servers[0].accessToken, + const body = await servers[0].jobsCommand.getJobsList({ state: state, start: 0, count: 50, sort: '-createdAt' }) - expect(res.body.data).to.have.length(0) + expect(body.data).to.have.length(0) } }) @@ -205,16 +187,16 @@ describe('Test handle downs', function () { await reRunServer(servers[1]) await reRunServer(servers[2]) - await unfollow(servers[1].url, servers[1].accessToken, servers[0]) + await servers[1].followsCommand.unfollow({ target: servers[0] }) await waitJobs(servers) - await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken) + await servers[1].followsCommand.follow({ targets: [ servers[0].url ] }) await waitJobs(servers) - const res = await getFollowersListPaginationAndSort({ url: servers[0].url, start: 0, count: 2, sort: 'createdAt' }) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(2) + const body = await servers[0].followsCommand.getFollowers({ start: 0, count: 2, sort: 'createdAt' }) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(2) }) it('Should send an update to server 3, and automatically fetch the video', async function () { @@ -244,7 +226,7 @@ describe('Test handle downs', function () { it('Should send comments on a video to server 3, and automatically fetch the video', async function () { this.timeout(25000) - await addVideoCommentReply(servers[0].url, servers[0].accessToken, missedVideo2.uuid, commentIdServer1, 'comment 1-3') + await commentCommands[0].addReply({ videoId: missedVideo2.uuid, toCommentId: commentIdServer1, text: 'comment 1-3' }) await waitJobs(servers) @@ -252,15 +234,13 @@ describe('Test handle downs', function () { expect(resVideo.body).not.to.be.undefined { - let resComment = await getVideoCommentThreads(servers[2].url, missedVideo2.uuid, 0, 5) - expect(resComment.body.data).to.be.an('array') - expect(resComment.body.data).to.have.lengthOf(1) - - threadIdServer2 = resComment.body.data[0].id + const { data } = await servers[2].commentsCommand.listThreads({ videoId: missedVideo2.uuid }) + expect(data).to.be.an('array') + expect(data).to.have.lengthOf(1) - resComment = await getVideoThreadComments(servers[2].url, missedVideo2.uuid, threadIdServer2) + threadIdServer2 = data[0].id - const tree: VideoCommentThreadTree = resComment.body + const tree = await servers[2].commentsCommand.getThread({ videoId: missedVideo2.uuid, threadId: threadIdServer2 }) expect(tree.comment.text).equal('thread 1') expect(tree.children).to.have.lengthOf(1) @@ -283,33 +263,30 @@ describe('Test handle downs', function () { it('Should correctly reply to the comment', async function () { this.timeout(15000) - await addVideoCommentReply(servers[2].url, servers[2].accessToken, missedVideo2.uuid, commentIdServer2, 'comment 1-4') + await servers[2].commentsCommand.addReply({ videoId: missedVideo2.uuid, toCommentId: commentIdServer2, text: 'comment 1-4' }) await waitJobs(servers) - { - const resComment = await getVideoThreadComments(servers[0].url, missedVideo2.uuid, threadIdServer1) + const tree = await commentCommands[0].getThread({ videoId: missedVideo2.uuid, threadId: threadIdServer1 }) - const tree: VideoCommentThreadTree = resComment.body - expect(tree.comment.text).equal('thread 1') - expect(tree.children).to.have.lengthOf(1) + expect(tree.comment.text).equal('thread 1') + expect(tree.children).to.have.lengthOf(1) - const firstChild = tree.children[0] - expect(firstChild.comment.text).to.equal('comment 1-1') - expect(firstChild.children).to.have.lengthOf(1) + const firstChild = tree.children[0] + expect(firstChild.comment.text).to.equal('comment 1-1') + expect(firstChild.children).to.have.lengthOf(1) - const childOfFirstChild = firstChild.children[0] - expect(childOfFirstChild.comment.text).to.equal('comment 1-2') - expect(childOfFirstChild.children).to.have.lengthOf(1) + const childOfFirstChild = firstChild.children[0] + expect(childOfFirstChild.comment.text).to.equal('comment 1-2') + expect(childOfFirstChild.children).to.have.lengthOf(1) - const childOfChildFirstChild = childOfFirstChild.children[0] - expect(childOfChildFirstChild.comment.text).to.equal('comment 1-3') - expect(childOfChildFirstChild.children).to.have.lengthOf(1) + const childOfChildFirstChild = childOfFirstChild.children[0] + expect(childOfChildFirstChild.comment.text).to.equal('comment 1-3') + expect(childOfChildFirstChild.children).to.have.lengthOf(1) - const childOfChildOfChildOfFirstChild = childOfChildFirstChild.children[0] - expect(childOfChildOfChildOfFirstChild.comment.text).to.equal('comment 1-4') - expect(childOfChildOfChildOfFirstChild.children).to.have.lengthOf(0) - } + const childOfChildOfChildOfFirstChild = childOfChildFirstChild.children[0] + expect(childOfChildOfChildOfFirstChild.comment.text).to.equal('comment 1-4') + expect(childOfChildOfChildOfFirstChild.children).to.have.lengthOf(0) }) it('Should upload many videos on server 1', async function () { @@ -327,7 +304,7 @@ describe('Test handle downs', function () { } await waitJobs(servers) - await setActorFollowScores(servers[1].internalServerNumber, 20) + await servers[1].sqlCommand.setActorFollowScores(20) // Wait video expiration await wait(11000) @@ -341,15 +318,17 @@ describe('Test handle downs', function () { it('Should remove followings that are down', async function () { this.timeout(120000) - killallServers([ servers[0] ]) + await killallServers([ servers[0] ]) // Wait video expiration await wait(11000) - for (let i = 0; i < 3; i++) { - await getVideo(servers[1].url, videoIdsServer1[i]) - await waitJobs([ servers[1] ]) - await wait(1500) + for (let i = 0; i < 5; i++) { + try { + await getVideo(servers[1].url, videoIdsServer1[i]) + await waitJobs([ servers[1] ]) + await wait(1500) + } catch {} } for (const id of videoIdsServer1) { @@ -358,8 +337,6 @@ describe('Test handle downs', function () { }) after(async function () { - await closeAllSequelize([ servers[1] ]) - await cleanupTests(servers) }) })