PeerTube/server/tests/api/server/handle-down.ts

365 lines
11 KiB
TypeScript
Raw Normal View History

2020-01-31 09:56:52 -06:00
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2018-01-10 10:18:12 -06:00
import * as chai from 'chai'
import 'mocha'
2018-07-31 05:21:04 -05:00
import { JobState, Video } from '../../../../shared/models'
2018-01-10 10:18:12 -06:00
import { VideoPrivacy } from '../../../../shared/models/videos'
2018-01-11 04:40:18 -06:00
import { VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
2018-11-15 15:07:16 -06:00
2018-01-10 10:18:12 -06:00
import {
2019-04-24 08:10:37 -05:00
cleanupTests,
2020-01-31 09:56:52 -06:00
closeAllSequelize,
completeVideoCheck,
2018-07-10 10:02:20 -05:00
flushAndRunMultipleServers,
2019-01-09 08:14:29 -06:00
getVideo,
2018-07-10 10:02:20 -05:00
getVideosList,
2019-01-09 08:14:29 -06:00
immutableAssign,
2018-07-10 10:02:20 -05:00
killallServers,
2019-01-09 08:14:29 -06:00
reRunServer,
2018-07-10 10:02:20 -05:00
ServerInfo,
setAccessTokensToServers,
2020-01-31 09:56:52 -06:00
setActorFollowScores,
2019-01-09 08:14:29 -06:00
unfollow,
2018-11-15 15:07:16 -06:00
updateVideo,
2020-01-31 09:56:52 -06:00
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'
2018-01-11 04:40:18 -06:00
import {
2018-07-10 10:02:20 -05:00
addVideoCommentReply,
addVideoCommentThread,
getVideoCommentThreads,
2018-01-11 04:40:18 -06:00
getVideoThreadComments
} from '../../../../shared/extra-utils/videos/video-comments'
2018-01-10 10:18:12 -06:00
const expect = chai.expect
describe('Test handle downs', function () {
let servers: ServerInfo[] = []
2018-01-11 04:40:18 -06:00
let threadIdServer1: number
let threadIdServer2: number
let commentIdServer1: number
let commentIdServer2: number
2018-07-31 05:21:04 -05:00
let missedVideo1: Video
let missedVideo2: Video
let unlistedVideo: Video
2018-01-10 10:18:12 -06:00
2020-01-31 09:56:52 -06:00
const videoIdsServer1: number[] = []
2019-08-06 10:19:53 -05:00
2018-01-10 10:18:12 -06:00
const videoAttributes = {
name: 'my super name for server 1',
category: 5,
licence: 4,
2018-04-23 07:39:52 -05:00
language: 'ja',
2018-01-10 10:18:12 -06:00
nsfw: true,
2018-01-11 04:40:18 -06:00
privacy: VideoPrivacy.PUBLIC,
2018-01-10 10:18:12 -06:00
description: 'my super description for server 1',
support: 'my super support text for server 1',
2018-01-10 10:18:12 -06:00
tags: [ 'tag1p1', 'tag2p1' ],
fixture: 'video_short1.webm'
}
2018-01-11 04:40:18 -06:00
const unlistedVideoAttributes = immutableAssign(videoAttributes, {
privacy: VideoPrivacy.UNLISTED
})
2019-04-26 01:50:52 -05:00
let checkAttributes: any
let unlistedCheckAttributes: any
2018-01-11 04:40:18 -06:00
2018-01-10 10:18:12 -06:00
before(async function () {
2018-01-18 11:10:45 -06:00
this.timeout(30000)
2018-01-10 10:18:12 -06:00
2018-07-31 05:21:04 -05:00
servers = await flushAndRunMultipleServers(3)
2018-01-10 10:18:12 -06:00
2019-04-26 01:50:52 -05: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',
host: 'localhost:' + servers[0].port
},
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
}
]
}
unlistedCheckAttributes = immutableAssign(checkAttributes, {
privacy: VideoPrivacy.UNLISTED
})
2018-01-10 10:18:12 -06:00
// Get the access tokens
await setAccessTokensToServers(servers)
})
it('Should remove followers that are often down', async function () {
2019-07-29 04:59:29 -05:00
this.timeout(240000)
2018-01-10 10:18:12 -06:00
2018-07-31 05:21:04 -05:00
// Server 2 and 3 follow server 1
2018-01-10 10:18:12 -06:00
await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken)
2018-07-31 05:21:04 -05:00
await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
2018-01-10 10:18:12 -06:00
await waitJobs(servers)
2018-01-10 10:18:12 -06:00
2018-07-31 05:21:04 -05:00
// Upload a video to server 1
2018-01-10 10:18:12 -06:00
await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
await waitJobs(servers)
2018-01-10 10:18:12 -06:00
2018-07-31 05:21:04 -05:00
// And check all servers have this video
2018-01-10 10:18:12 -06:00
for (const server of servers) {
const res = await getVideosList(server.url)
expect(res.body.data).to.be.an('array')
expect(res.body.data).to.have.lengthOf(1)
}
2018-07-31 05:21:04 -05:00
// Kill server 2
2018-01-10 10:18:12 -06:00
killallServers([ servers[1] ])
// Remove server 2 follower
for (let i = 0; i < 10; i++) {
2020-01-31 09:56:52 -06:00
await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
2018-01-11 04:40:18 -06:00
}
await waitJobs(servers[0])
2018-07-31 05:21:04 -05:00
// Kill server 3
killallServers([ servers[2] ])
2020-01-31 09:56:52 -06:00
const resLastVideo1 = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
2018-07-31 05:21:04 -05:00
missedVideo1 = resLastVideo1.body.video
2020-01-31 09:56:52 -06:00
const resLastVideo2 = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
2018-07-31 05:21:04 -05:00
missedVideo2 = resLastVideo2.body.video
// Unlisted video
2020-01-31 09:56:52 -06:00
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, unlistedVideoAttributes)
2018-07-31 05:21:04 -05:00
unlistedVideo = resVideo.body.video
2018-01-11 04:40:18 -06:00
// Add comments to video 2
{
const text = 'thread 1'
2018-07-31 05:21:04 -05:00
let resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, missedVideo2.uuid, text)
2018-01-11 04:40:18 -06:00
let comment = resComment.body.comment
threadIdServer1 = comment.id
2018-07-31 05:21:04 -05:00
resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, missedVideo2.uuid, comment.id, 'comment 1-1')
2018-01-11 04:40:18 -06:00
comment = resComment.body.comment
2018-07-31 05:21:04 -05:00
resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, missedVideo2.uuid, comment.id, 'comment 1-2')
2018-01-11 04:40:18 -06:00
commentIdServer1 = resComment.body.comment.id
2018-01-10 10:18:12 -06:00
}
await waitJobs(servers[0])
// Wait scheduler
await wait(11000)
2018-01-10 10:18:12 -06:00
2018-07-31 05:21:04 -05:00
// Only server 3 is still a follower of server 1
2020-01-31 09:56:52 -06:00
const res = await getFollowersListPaginationAndSort({ url: servers[0].url, start: 0, count: 2, sort: 'createdAt' })
2018-01-10 10:18:12 -06:00
expect(res.body.data).to.be.an('array')
2018-07-31 05:21:04 -05:00
expect(res.body.data).to.have.lengthOf(1)
expect(res.body.data[0].follower.host).to.equal('localhost:' + servers[2].port)
2018-01-10 10:18:12 -06:00
})
it('Should not have pending/processing jobs anymore', async function () {
2018-07-10 10:02:20 -05:00
const states: JobState[] = [ 'waiting', 'active' ]
2018-01-10 10:18:12 -06:00
for (const state of states) {
2019-12-04 07:49:59 -06:00
const res = await getJobsListPaginationAndSort({
2020-01-31 09:56:52 -06:00
url: servers[0].url,
accessToken: servers[0].accessToken,
2019-12-04 07:49:59 -06:00
state: state,
start: 0,
count: 50,
sort: '-createdAt'
})
expect(res.body.data).to.have.length(0)
2018-01-10 10:18:12 -06:00
}
})
2018-07-31 05:21:04 -05:00
it('Should re-follow server 1', async function () {
2018-07-31 08:09:34 -05:00
this.timeout(35000)
2018-01-11 04:40:18 -06:00
await reRunServer(servers[1])
2018-07-31 05:21:04 -05:00
await reRunServer(servers[2])
await unfollow(servers[1].url, servers[1].accessToken, servers[0])
await waitJobs(servers)
2018-01-10 10:18:12 -06:00
await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken)
await waitJobs(servers)
2018-01-10 10:18:12 -06:00
2020-01-31 09:56:52 -06:00
const res = await getFollowersListPaginationAndSort({ url: servers[0].url, start: 0, count: 2, sort: 'createdAt' })
2018-01-10 10:18:12 -06:00
expect(res.body.data).to.be.an('array')
2018-07-31 05:21:04 -05:00
expect(res.body.data).to.have.lengthOf(2)
2018-01-10 10:18:12 -06:00
})
it('Should send an update to server 3, and automatically fetch the video', async function () {
2018-01-11 04:40:18 -06:00
this.timeout(15000)
2018-01-10 10:18:12 -06:00
2018-07-31 05:21:04 -05:00
const res1 = await getVideosList(servers[2].url)
expect(res1.body.data).to.be.an('array')
expect(res1.body.data).to.have.lengthOf(11)
2020-01-31 09:56:52 -06:00
await updateVideo(servers[0].url, servers[0].accessToken, missedVideo1.uuid, {})
await updateVideo(servers[0].url, servers[0].accessToken, unlistedVideo.uuid, {})
2018-01-10 10:18:12 -06:00
await waitJobs(servers)
2018-01-10 10:18:12 -06:00
2018-07-31 05:21:04 -05:00
const res = await getVideosList(servers[2].url)
2018-01-11 04:40:18 -06:00
expect(res.body.data).to.be.an('array')
2018-07-31 05:21:04 -05:00
// 1 video is unlisted
expect(res.body.data).to.have.lengthOf(12)
2018-01-11 04:40:18 -06:00
2018-07-31 05:21:04 -05:00
// Check unlisted video
const resVideo = await getVideo(servers[2].url, unlistedVideo.uuid)
2018-01-11 04:40:18 -06:00
expect(resVideo.body).not.to.be.undefined
2018-07-31 05:21:04 -05:00
await completeVideoCheck(servers[2].url, resVideo.body, unlistedCheckAttributes)
2018-01-11 04:40:18 -06:00
})
2018-07-31 05:21:04 -05:00
it('Should send comments on a video to server 3, and automatically fetch the video', async function () {
2018-01-11 04:40:18 -06:00
this.timeout(25000)
2018-01-10 10:18:12 -06:00
2018-07-31 05:21:04 -05:00
await addVideoCommentReply(servers[0].url, servers[0].accessToken, missedVideo2.uuid, commentIdServer1, 'comment 1-3')
2018-01-11 04:40:18 -06:00
await waitJobs(servers)
2018-01-11 04:40:18 -06:00
2018-07-31 05:21:04 -05:00
const resVideo = await getVideo(servers[2].url, missedVideo2.uuid)
2018-01-11 04:40:18 -06:00
expect(resVideo.body).not.to.be.undefined
{
2018-07-31 05:21:04 -05:00
let resComment = await getVideoCommentThreads(servers[2].url, missedVideo2.uuid, 0, 5)
2018-01-11 04:40:18 -06:00
expect(resComment.body.data).to.be.an('array')
expect(resComment.body.data).to.have.lengthOf(1)
threadIdServer2 = resComment.body.data[0].id
2018-07-31 05:21:04 -05:00
resComment = await getVideoThreadComments(servers[2].url, missedVideo2.uuid, threadIdServer2)
2018-01-11 04:40:18 -06:00
const tree: VideoCommentThreadTree = resComment.body
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)
2018-07-31 05:21:04 -05:00
await addVideoCommentReply(servers[2].url, servers[2].accessToken, missedVideo2.uuid, commentIdServer2, 'comment 1-4')
2018-01-11 04:40:18 -06:00
await waitJobs(servers)
2018-01-11 04:40:18 -06:00
{
2018-07-31 05:21:04 -05:00
const resComment = await getVideoThreadComments(servers[0].url, missedVideo2.uuid, threadIdServer1)
2018-01-11 04:40:18 -06:00
const tree: VideoCommentThreadTree = resComment.body
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(1)
const childOfChildOfChildOfFirstChild = childOfChildFirstChild.children[0]
expect(childOfChildOfChildOfFirstChild.comment.text).to.equal('comment 1-4')
expect(childOfChildOfChildOfFirstChild.children).to.have.lengthOf(0)
}
2018-01-10 10:18:12 -06:00
})
2019-08-06 10:19:53 -05:00
it('Should upload many videos on server 1', async function () {
this.timeout(120000)
for (let i = 0; i < 10; i++) {
2020-01-31 09:56:52 -06:00
const uuid = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video ' + i })).uuid
2019-08-06 10:19:53 -05:00
videoIdsServer1.push(uuid)
}
await waitJobs(servers)
for (const id of videoIdsServer1) {
2020-01-31 09:56:52 -06:00
await getVideo(servers[1].url, id)
2019-08-06 10:19:53 -05:00
}
await waitJobs(servers)
await setActorFollowScores(servers[1].internalServerNumber, 20)
// Wait video expiration
await wait(11000)
// Refresh video -> score + 10 = 30
await getVideo(servers[1].url, videoIdsServer1[0])
await waitJobs(servers)
})
it('Should remove followings that are down', async function () {
this.timeout(120000)
killallServers([ servers[0] ])
// Wait video expiration
await wait(11000)
for (let i = 0; i < 3; i++) {
await getVideo(servers[1].url, videoIdsServer1[i])
await wait(1000)
await waitJobs([ servers[1] ])
}
for (const id of videoIdsServer1) {
await getVideo(servers[1].url, id, 403)
}
})
2019-04-24 08:10:37 -05:00
after(async function () {
2019-08-06 10:19:53 -05:00
await closeAllSequelize([ servers[1] ])
2019-04-24 08:10:37 -05:00
await cleanupTests(servers)
2018-01-10 10:18:12 -06:00
})
})