1
0
Fork 0
peertube/server/tests/api/server/handle-down.ts

331 lines
9.9 KiB
TypeScript
Raw Normal View History

2020-01-31 15:56:52 +00:00
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2018-01-10 16:18:12 +00:00
2022-08-17 13:44:32 +00:00
import { expect } from 'chai'
import { completeVideoCheck } from '@server/tests/shared'
import { wait } from '@shared/core-utils'
import { HttpStatusCode, JobState, VideoCreateResult, VideoPrivacy } from '@shared/models'
2018-01-10 16:18:12 +00:00
import {
2019-04-24 13:10:37 +00:00
cleanupTests,
2021-07-09 12:15:11 +00:00
CommentsCommand,
2021-07-16 07:47:51 +00:00
createMultipleServers,
2018-07-10 15:02:20 +00:00
killallServers,
2021-07-16 07:47:51 +00:00
PeerTubeServer,
2018-07-10 15:02:20 +00:00
setAccessTokensToServers,
2021-07-07 07:16:40 +00:00
waitJobs
} from '@shared/server-commands'
2018-01-10 16:18:12 +00:00
describe('Test handle downs', function () {
2021-07-16 07:47:51 +00:00
let servers: PeerTubeServer[] = []
2018-01-11 10:40:18 +00:00
let threadIdServer1: number
let threadIdServer2: number
let commentIdServer1: number
let commentIdServer2: number
2021-07-15 08:02:54 +00:00
let missedVideo1: VideoCreateResult
let missedVideo2: VideoCreateResult
let unlistedVideo: VideoCreateResult
2018-01-10 16:18:12 +00:00
const videoIdsServer1: string[] = []
2019-08-06 15:19:53 +00:00
2018-01-10 16:18:12 +00:00
const videoAttributes = {
name: 'my super name for server 1',
category: 5,
licence: 4,
2018-04-23 12:39:52 +00:00
language: 'ja',
2018-01-10 16:18:12 +00:00
nsfw: true,
2018-01-11 10:40:18 +00:00
privacy: VideoPrivacy.PUBLIC,
2018-01-10 16:18:12 +00:00
description: 'my super description for server 1',
support: 'my super support text for server 1',
2018-01-10 16:18:12 +00:00
tags: [ 'tag1p1', 'tag2p1' ],
fixture: 'video_short1.webm'
}
2021-07-13 07:43:59 +00:00
const unlistedVideoAttributes = { ...videoAttributes, privacy: VideoPrivacy.UNLISTED }
2018-01-11 10:40:18 +00:00
2019-04-26 06:50:52 +00:00
let checkAttributes: any
let unlistedCheckAttributes: any
2018-01-11 10:40:18 +00:00
2021-07-09 12:15:11 +00:00
let commentCommands: CommentsCommand[]
2018-01-10 16:18:12 +00:00
before(async function () {
2021-12-28 10:41:41 +00:00
this.timeout(120000)
2018-01-10 16:18:12 +00:00
2021-07-16 07:47:51 +00:00
servers = await createMultipleServers(3)
2021-07-16 07:04:35 +00:00
commentCommands = servers.map(s => s.comments)
2018-01-10 16:18:12 +00:00
2019-04-26 06:50:52 +00:00
checkAttributes = {
name: 'my super name for server 1',
category: 5,
licence: 4,
language: 'ja',
nsfw: true,
description: 'my super description for server 1',
support: 'my super support text for server 1',
account: {
name: 'root',
2022-12-09 10:14:47 +00:00
host: servers[0].host
2019-04-26 06:50:52 +00:00
},
isLocal: false,
duration: 10,
tags: [ 'tag1p1', 'tag2p1' ],
privacy: VideoPrivacy.PUBLIC,
commentsEnabled: true,
downloadEnabled: true,
channel: {
name: 'root_channel',
displayName: 'Main root channel',
description: '',
isLocal: false
},
fixture: 'video_short1.webm',
files: [
{
resolution: 720,
size: 572456
}
]
}
2021-07-13 07:43:59 +00:00
unlistedCheckAttributes = { ...checkAttributes, privacy: VideoPrivacy.UNLISTED }
2019-04-26 06:50:52 +00:00
2018-01-10 16:18:12 +00:00
// Get the access tokens
await setAccessTokensToServers(servers)
})
it('Should remove followers that are often down', async function () {
2019-07-29 09:59:29 +00:00
this.timeout(240000)
2018-01-10 16:18:12 +00:00
2018-07-31 10:21:04 +00:00
// Server 2 and 3 follow server 1
await servers[1].follows.follow({ hosts: [ servers[0].url ] })
await servers[2].follows.follow({ hosts: [ servers[0].url ] })
2018-01-10 16:18:12 +00:00
await waitJobs(servers)
2018-01-10 16:18:12 +00:00
2018-07-31 10:21:04 +00:00
// Upload a video to server 1
2021-07-16 07:04:35 +00:00
await servers[0].videos.upload({ attributes: videoAttributes })
2018-01-10 16:18:12 +00:00
await waitJobs(servers)
2018-01-10 16:18:12 +00:00
2018-07-31 10:21:04 +00:00
// And check all servers have this video
2018-01-10 16:18:12 +00:00
for (const server of servers) {
2021-07-16 07:04:35 +00:00
const { data } = await server.videos.list()
2021-07-15 08:02:54 +00:00
expect(data).to.be.an('array')
expect(data).to.have.lengthOf(1)
2018-01-10 16:18:12 +00:00
}
2018-07-31 10:21:04 +00:00
// Kill server 2
2021-07-09 13:37:43 +00:00
await killallServers([ servers[1] ])
2018-01-10 16:18:12 +00:00
// Remove server 2 follower
for (let i = 0; i < 10; i++) {
2021-07-16 07:04:35 +00:00
await servers[0].videos.upload({ attributes: videoAttributes })
2018-01-11 10:40:18 +00:00
}
2021-05-10 14:28:26 +00:00
await waitJobs([ servers[0], servers[2] ])
2018-07-31 10:21:04 +00:00
// Kill server 3
2021-07-09 13:37:43 +00:00
await killallServers([ servers[2] ])
2018-07-31 10:21:04 +00:00
2021-07-16 07:04:35 +00:00
missedVideo1 = await servers[0].videos.upload({ attributes: videoAttributes })
2018-07-31 10:21:04 +00:00
2021-07-16 07:04:35 +00:00
missedVideo2 = await servers[0].videos.upload({ attributes: videoAttributes })
2018-07-31 10:21:04 +00:00
// Unlisted video
2021-07-16 07:04:35 +00:00
unlistedVideo = await servers[0].videos.upload({ attributes: unlistedVideoAttributes })
2018-01-11 10:40:18 +00:00
// Add comments to video 2
{
const text = 'thread 1'
2021-07-09 12:15:11 +00:00
let comment = await commentCommands[0].createThread({ videoId: missedVideo2.uuid, text })
2018-01-11 10:40:18 +00:00
threadIdServer1 = comment.id
2021-07-09 12:15:11 +00:00
comment = await commentCommands[0].addReply({ videoId: missedVideo2.uuid, toCommentId: comment.id, text: 'comment 1-1' })
2018-01-11 10:40:18 +00:00
2021-07-09 12:15:11 +00:00
const created = await commentCommands[0].addReply({ videoId: missedVideo2.uuid, toCommentId: comment.id, text: 'comment 1-2' })
commentIdServer1 = created.id
2018-01-10 16:18:12 +00:00
}
await waitJobs(servers[0])
// Wait scheduler
await wait(11000)
2018-01-10 16:18:12 +00:00
2018-07-31 10:21:04 +00:00
// Only server 3 is still a follower of server 1
2021-07-16 07:04:35 +00:00
const body = await servers[0].follows.getFollowers({ start: 0, count: 2, sort: 'createdAt' })
2021-07-07 07:16:40 +00:00
expect(body.data).to.be.an('array')
expect(body.data).to.have.lengthOf(1)
2022-12-09 10:14:47 +00:00
expect(body.data[0].follower.host).to.equal(servers[2].host)
2018-01-10 16:18:12 +00:00
})
it('Should not have pending/processing jobs anymore', async function () {
2018-07-10 15:02:20 +00:00
const states: JobState[] = [ 'waiting', 'active' ]
2018-01-10 16:18:12 +00:00
for (const state of states) {
2021-08-25 13:13:41 +00:00
const body = await servers[0].jobs.list({
2022-07-13 09:58:01 +00:00
state,
2019-12-04 13:49:59 +00:00
start: 0,
count: 50,
sort: '-createdAt'
})
2021-07-07 07:34:56 +00:00
expect(body.data).to.have.length(0)
2018-01-10 16:18:12 +00:00
}
})
2018-07-31 10:21:04 +00:00
it('Should re-follow server 1', async function () {
2021-10-14 06:30:17 +00:00
this.timeout(70000)
2018-01-11 10:40:18 +00:00
2021-07-16 07:47:51 +00:00
await servers[1].run()
await servers[2].run()
2018-07-31 10:21:04 +00:00
2021-07-16 07:04:35 +00:00
await servers[1].follows.unfollow({ target: servers[0] })
2018-07-31 10:21:04 +00:00
await waitJobs(servers)
2018-01-10 16:18:12 +00:00
await servers[1].follows.follow({ hosts: [ servers[0].url ] })
2018-01-10 16:18:12 +00:00
await waitJobs(servers)
2018-01-10 16:18:12 +00:00
2021-07-16 07:04:35 +00:00
const body = await servers[0].follows.getFollowers({ start: 0, count: 2, sort: 'createdAt' })
2021-07-07 07:16:40 +00:00
expect(body.data).to.be.an('array')
expect(body.data).to.have.lengthOf(2)
2018-01-10 16:18:12 +00:00
})
it('Should send an update to server 3, and automatically fetch the video', async function () {
2018-01-11 10:40:18 +00:00
this.timeout(15000)
2018-01-10 16:18:12 +00:00
2021-07-15 08:02:54 +00:00
{
2021-07-16 07:04:35 +00:00
const { data } = await servers[2].videos.list()
2021-07-15 08:02:54 +00:00
expect(data).to.be.an('array')
expect(data).to.have.lengthOf(11)
}
2018-07-31 10:21:04 +00:00
2021-07-16 07:04:35 +00:00
await servers[0].videos.update({ id: missedVideo1.uuid })
await servers[0].videos.update({ id: unlistedVideo.uuid })
2018-01-10 16:18:12 +00:00
await waitJobs(servers)
2018-01-10 16:18:12 +00:00
2021-07-15 08:02:54 +00:00
{
2021-07-16 07:04:35 +00:00
const { data } = await servers[2].videos.list()
2021-07-15 08:02:54 +00:00
expect(data).to.be.an('array')
// 1 video is unlisted
expect(data).to.have.lengthOf(12)
}
2018-01-11 10:40:18 +00:00
2018-07-31 10:21:04 +00:00
// Check unlisted video
2021-07-16 07:04:35 +00:00
const video = await servers[2].videos.get({ id: unlistedVideo.uuid })
2021-07-15 08:02:54 +00:00
await completeVideoCheck(servers[2], video, unlistedCheckAttributes)
2018-01-11 10:40:18 +00:00
})
2018-07-31 10:21:04 +00:00
it('Should send comments on a video to server 3, and automatically fetch the video', async function () {
2018-01-11 10:40:18 +00:00
this.timeout(25000)
2018-01-10 16:18:12 +00:00
2021-07-09 12:15:11 +00:00
await commentCommands[0].addReply({ videoId: missedVideo2.uuid, toCommentId: commentIdServer1, text: 'comment 1-3' })
2018-01-11 10:40:18 +00:00
await waitJobs(servers)
2018-01-11 10:40:18 +00:00
2021-07-16 07:04:35 +00:00
await servers[2].videos.get({ id: missedVideo2.uuid })
2018-01-11 10:40:18 +00:00
{
2021-07-16 07:04:35 +00:00
const { data } = await servers[2].comments.listThreads({ videoId: missedVideo2.uuid })
2021-07-09 12:15:11 +00:00
expect(data).to.be.an('array')
expect(data).to.have.lengthOf(1)
2018-01-11 10:40:18 +00:00
2021-07-09 12:15:11 +00:00
threadIdServer2 = data[0].id
2018-01-11 10:40:18 +00:00
2021-07-16 07:04:35 +00:00
const tree = await servers[2].comments.getThread({ videoId: missedVideo2.uuid, threadId: threadIdServer2 })
2018-01-11 10:40:18 +00:00
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 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(0)
commentIdServer2 = childOfChildFirstChild.comment.id
}
})
it('Should correctly reply to the comment', async function () {
this.timeout(15000)
2021-07-16 07:04:35 +00:00
await servers[2].comments.addReply({ videoId: missedVideo2.uuid, toCommentId: commentIdServer2, text: 'comment 1-4' })
2018-01-11 10:40:18 +00:00
await waitJobs(servers)
2018-01-11 10:40:18 +00:00
2021-07-09 12:15:11 +00:00
const tree = await commentCommands[0].getThread({ videoId: missedVideo2.uuid, threadId: threadIdServer1 })
2018-01-11 10:40:18 +00:00
2021-07-09 12:15:11 +00:00
expect(tree.comment.text).equal('thread 1')
expect(tree.children).to.have.lengthOf(1)
2018-01-11 10:40:18 +00:00
2021-07-09 12:15:11 +00:00
const firstChild = tree.children[0]
expect(firstChild.comment.text).to.equal('comment 1-1')
expect(firstChild.children).to.have.lengthOf(1)
2018-01-11 10:40:18 +00:00
2021-07-09 12:15:11 +00:00
const childOfFirstChild = firstChild.children[0]
expect(childOfFirstChild.comment.text).to.equal('comment 1-2')
expect(childOfFirstChild.children).to.have.lengthOf(1)
2018-01-11 10:40:18 +00:00
2021-07-09 12:15:11 +00:00
const childOfChildFirstChild = childOfFirstChild.children[0]
expect(childOfChildFirstChild.comment.text).to.equal('comment 1-3')
expect(childOfChildFirstChild.children).to.have.lengthOf(1)
2018-01-11 10:40:18 +00:00
2021-07-09 12:15:11 +00:00
const childOfChildOfChildOfFirstChild = childOfChildFirstChild.children[0]
expect(childOfChildOfChildOfFirstChild.comment.text).to.equal('comment 1-4')
expect(childOfChildOfChildOfFirstChild.children).to.have.lengthOf(0)
2018-01-10 16:18:12 +00:00
})
2019-08-06 15:19:53 +00:00
it('Should upload many videos on server 1', async function () {
this.timeout(120000)
for (let i = 0; i < 10; i++) {
2021-07-16 07:04:35 +00:00
const uuid = (await servers[0].videos.quickUpload({ name: 'video ' + i })).uuid
2019-08-06 15:19:53 +00:00
videoIdsServer1.push(uuid)
}
await waitJobs(servers)
for (const id of videoIdsServer1) {
2021-07-16 07:04:35 +00:00
await servers[1].videos.get({ id })
2019-08-06 15:19:53 +00:00
}
await waitJobs(servers)
2021-07-16 07:04:35 +00:00
await servers[1].sql.setActorFollowScores(20)
2019-08-06 15:19:53 +00:00
// Wait video expiration
await wait(11000)
// Refresh video -> score + 10 = 30
2021-07-16 07:04:35 +00:00
await servers[1].videos.get({ id: videoIdsServer1[0] })
2019-08-06 15:19:53 +00:00
await waitJobs(servers)
})
it('Should remove followings that are down', async function () {
this.timeout(120000)
2021-07-09 13:37:43 +00:00
await killallServers([ servers[0] ])
2019-08-06 15:19:53 +00:00
// Wait video expiration
await wait(11000)
2021-05-11 12:23:49 +00:00
for (let i = 0; i < 5; i++) {
try {
2021-07-16 07:04:35 +00:00
await servers[1].videos.get({ id: videoIdsServer1[i] })
2021-05-11 12:23:49 +00:00
await waitJobs([ servers[1] ])
await wait(1500)
} catch {}
2019-08-06 15:19:53 +00:00
}
for (const id of videoIdsServer1) {
2021-07-16 07:04:35 +00:00
await servers[1].videos.get({ id, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
2019-08-06 15:19:53 +00:00
}
})
2019-04-24 13:10:37 +00:00
after(async function () {
await cleanupTests(servers)
2018-01-10 16:18:12 +00:00
})
})