]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/server/handle-down.ts
Add ability to disable tracker
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / handle-down.ts
CommitLineData
2ccaeeb3
C
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
cc6373e6 5import { JobState, Video } from '../../../../shared/models'
2ccaeeb3 6import { VideoPrivacy } from '../../../../shared/models/videos'
7bc29171 7import { VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
ae28cdf3 8
2ccaeeb3 9import {
9639bd17 10 completeVideoCheck,
94831479 11 flushAndRunMultipleServers,
a4101923 12 getVideo,
94831479 13 getVideosList,
a4101923 14 immutableAssign,
94831479 15 killallServers,
a4101923 16 reRunServer,
94831479
C
17 ServerInfo,
18 setAccessTokensToServers,
a4101923 19 unfollow,
ae28cdf3 20 updateVideo,
94831479 21 uploadVideo,
2ccaeeb3 22 wait
9639bd17 23} from '../../../../shared/utils'
24import { follow, getFollowersListPaginationAndSort } from '../../../../shared/utils/server/follows'
25import { getJobsListPaginationAndSort, waitJobs } from '../../../../shared/utils/server/jobs'
7bc29171 26import {
94831479
C
27 addVideoCommentReply,
28 addVideoCommentThread,
29 getVideoCommentThreads,
7bc29171 30 getVideoThreadComments
9639bd17 31} from '../../../../shared/utils/videos/video-comments'
2ccaeeb3
C
32
33const expect = chai.expect
34
35describe('Test handle downs', function () {
36 let servers: ServerInfo[] = []
7bc29171
C
37 let threadIdServer1: number
38 let threadIdServer2: number
39 let commentIdServer1: number
40 let commentIdServer2: number
cc6373e6
C
41 let missedVideo1: Video
42 let missedVideo2: Video
43 let unlistedVideo: Video
2ccaeeb3
C
44
45 const videoAttributes = {
46 name: 'my super name for server 1',
47 category: 5,
48 licence: 4,
9d3ef9fe 49 language: 'ja',
2ccaeeb3 50 nsfw: true,
7bc29171 51 privacy: VideoPrivacy.PUBLIC,
2ccaeeb3 52 description: 'my super description for server 1',
2422c46b 53 support: 'my super support text for server 1',
2ccaeeb3
C
54 tags: [ 'tag1p1', 'tag2p1' ],
55 fixture: 'video_short1.webm'
56 }
57
7bc29171
C
58 const unlistedVideoAttributes = immutableAssign(videoAttributes, {
59 privacy: VideoPrivacy.UNLISTED
60 })
61
2ccaeeb3
C
62 const checkAttributes = {
63 name: 'my super name for server 1',
64 category: 5,
65 licence: 4,
9d3ef9fe 66 language: 'ja',
2ccaeeb3
C
67 nsfw: true,
68 description: 'my super description for server 1',
2422c46b 69 support: 'my super support text for server 1',
b64c950a
C
70 account: {
71 name: 'root',
72 host: 'localhost:9001'
73 },
2ccaeeb3
C
74 isLocal: false,
75 duration: 10,
76 tags: [ 'tag1p1', 'tag2p1' ],
77 privacy: VideoPrivacy.PUBLIC,
78 commentsEnabled: true,
7f2cfe3a 79 downloadEnabled: true,
2ccaeeb3 80 channel: {
f6eebcb3
C
81 name: 'root_channel',
82 displayName: 'Main root channel',
2ccaeeb3
C
83 description: '',
84 isLocal: false
85 },
86 fixture: 'video_short1.webm',
87 files: [
88 {
89 resolution: 720,
90 size: 572456
91 }
92 ]
93 }
94
7bc29171
C
95 const unlistedCheckAttributes = immutableAssign(checkAttributes, {
96 privacy: VideoPrivacy.UNLISTED
97 })
98
2ccaeeb3 99 before(async function () {
e212f887 100 this.timeout(30000)
2ccaeeb3 101
cc6373e6 102 servers = await flushAndRunMultipleServers(3)
2ccaeeb3
C
103
104 // Get the access tokens
105 await setAccessTokensToServers(servers)
106 })
107
108 it('Should remove followers that are often down', async function () {
109 this.timeout(60000)
110
cc6373e6 111 // Server 2 and 3 follow server 1
2ccaeeb3 112 await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken)
cc6373e6 113 await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
2ccaeeb3 114
3cd0734f 115 await waitJobs(servers)
2ccaeeb3 116
cc6373e6 117 // Upload a video to server 1
2ccaeeb3
C
118 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
119
3cd0734f 120 await waitJobs(servers)
2ccaeeb3 121
cc6373e6 122 // And check all servers have this video
2ccaeeb3
C
123 for (const server of servers) {
124 const res = await getVideosList(server.url)
125 expect(res.body.data).to.be.an('array')
126 expect(res.body.data).to.have.lengthOf(1)
127 }
128
cc6373e6 129 // Kill server 2
2ccaeeb3
C
130 killallServers([ servers[1] ])
131
132 // Remove server 2 follower
133 for (let i = 0; i < 10; i++) {
cc6373e6 134 await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes)
7bc29171
C
135 }
136
3cd0734f 137 await waitJobs(servers[0])
6502c3d4 138
cc6373e6
C
139 // Kill server 3
140 killallServers([ servers[2] ])
141
142 const resLastVideo1 = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes)
143 missedVideo1 = resLastVideo1.body.video
144
145 const resLastVideo2 = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes)
146 missedVideo2 = resLastVideo2.body.video
147
148 // Unlisted video
149 let resVideo = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, unlistedVideoAttributes)
150 unlistedVideo = resVideo.body.video
6502c3d4 151
7bc29171
C
152 // Add comments to video 2
153 {
154 const text = 'thread 1'
cc6373e6 155 let resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, missedVideo2.uuid, text)
7bc29171
C
156 let comment = resComment.body.comment
157 threadIdServer1 = comment.id
158
cc6373e6 159 resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, missedVideo2.uuid, comment.id, 'comment 1-1')
7bc29171
C
160 comment = resComment.body.comment
161
cc6373e6 162 resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, missedVideo2.uuid, comment.id, 'comment 1-2')
7bc29171 163 commentIdServer1 = resComment.body.comment.id
2ccaeeb3
C
164 }
165
3cd0734f
C
166 await waitJobs(servers[0])
167 // Wait scheduler
9a4a9b6c 168 await wait(11000)
2ccaeeb3 169
cc6373e6
C
170 // Only server 3 is still a follower of server 1
171 const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 2, 'createdAt')
2ccaeeb3 172 expect(res.body.data).to.be.an('array')
cc6373e6
C
173 expect(res.body.data).to.have.lengthOf(1)
174 expect(res.body.data[0].follower.host).to.equal('localhost:9003')
2ccaeeb3
C
175 })
176
177 it('Should not have pending/processing jobs anymore', async function () {
94831479 178 const states: JobState[] = [ 'waiting', 'active' ]
2ccaeeb3 179
94a5ff8a
C
180 for (const state of states) {
181 const res = await getJobsListPaginationAndSort(servers[ 0 ].url, servers[ 0 ].accessToken, state,0, 50, '-createdAt')
182 expect(res.body.data).to.have.length(0)
2ccaeeb3
C
183 }
184 })
185
cc6373e6 186 it('Should re-follow server 1', async function () {
cf7a61b5 187 this.timeout(35000)
7bc29171
C
188
189 await reRunServer(servers[1])
cc6373e6
C
190 await reRunServer(servers[2])
191
192 await unfollow(servers[1].url, servers[1].accessToken, servers[0])
193 await waitJobs(servers)
2ccaeeb3
C
194
195 await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken)
196
3cd0734f 197 await waitJobs(servers)
2ccaeeb3 198
cc6373e6 199 const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 2, 'createdAt')
2ccaeeb3 200 expect(res.body.data).to.be.an('array')
cc6373e6 201 expect(res.body.data).to.have.lengthOf(2)
2ccaeeb3
C
202 })
203
8cf99873 204 it('Should send an update to server 3, and automatically fetch the video', async function () {
7bc29171 205 this.timeout(15000)
2ccaeeb3 206
cc6373e6
C
207 const res1 = await getVideosList(servers[2].url)
208 expect(res1.body.data).to.be.an('array')
209 expect(res1.body.data).to.have.lengthOf(11)
210
8cf99873
C
211 await updateVideo(servers[0].url, servers[0].accessToken, missedVideo1.uuid, { })
212 await updateVideo(servers[0].url, servers[0].accessToken, unlistedVideo.uuid, { })
2ccaeeb3 213
3cd0734f 214 await waitJobs(servers)
2ccaeeb3 215
cc6373e6 216 const res = await getVideosList(servers[2].url)
7bc29171 217 expect(res.body.data).to.be.an('array')
cc6373e6
C
218 // 1 video is unlisted
219 expect(res.body.data).to.have.lengthOf(12)
7bc29171 220
cc6373e6
C
221 // Check unlisted video
222 const resVideo = await getVideo(servers[2].url, unlistedVideo.uuid)
7bc29171
C
223 expect(resVideo.body).not.to.be.undefined
224
cc6373e6 225 await completeVideoCheck(servers[2].url, resVideo.body, unlistedCheckAttributes)
7bc29171
C
226 })
227
cc6373e6 228 it('Should send comments on a video to server 3, and automatically fetch the video', async function () {
7bc29171 229 this.timeout(25000)
2ccaeeb3 230
cc6373e6 231 await addVideoCommentReply(servers[0].url, servers[0].accessToken, missedVideo2.uuid, commentIdServer1, 'comment 1-3')
7bc29171 232
3cd0734f 233 await waitJobs(servers)
7bc29171 234
cc6373e6 235 const resVideo = await getVideo(servers[2].url, missedVideo2.uuid)
7bc29171
C
236 expect(resVideo.body).not.to.be.undefined
237
7bc29171 238 {
cc6373e6 239 let resComment = await getVideoCommentThreads(servers[2].url, missedVideo2.uuid, 0, 5)
7bc29171
C
240 expect(resComment.body.data).to.be.an('array')
241 expect(resComment.body.data).to.have.lengthOf(1)
242
243 threadIdServer2 = resComment.body.data[0].id
244
cc6373e6 245 resComment = await getVideoThreadComments(servers[2].url, missedVideo2.uuid, threadIdServer2)
7bc29171
C
246
247 const tree: VideoCommentThreadTree = resComment.body
248 expect(tree.comment.text).equal('thread 1')
249 expect(tree.children).to.have.lengthOf(1)
250
251 const firstChild = tree.children[0]
252 expect(firstChild.comment.text).to.equal('comment 1-1')
253 expect(firstChild.children).to.have.lengthOf(1)
254
255 const childOfFirstChild = firstChild.children[0]
256 expect(childOfFirstChild.comment.text).to.equal('comment 1-2')
257 expect(childOfFirstChild.children).to.have.lengthOf(1)
258
259 const childOfChildFirstChild = childOfFirstChild.children[0]
260 expect(childOfChildFirstChild.comment.text).to.equal('comment 1-3')
261 expect(childOfChildFirstChild.children).to.have.lengthOf(0)
262
263 commentIdServer2 = childOfChildFirstChild.comment.id
264 }
265 })
266
267 it('Should correctly reply to the comment', async function () {
268 this.timeout(15000)
269
cc6373e6 270 await addVideoCommentReply(servers[2].url, servers[2].accessToken, missedVideo2.uuid, commentIdServer2, 'comment 1-4')
7bc29171 271
3cd0734f 272 await waitJobs(servers)
7bc29171
C
273
274 {
cc6373e6 275 const resComment = await getVideoThreadComments(servers[0].url, missedVideo2.uuid, threadIdServer1)
7bc29171
C
276
277 const tree: VideoCommentThreadTree = resComment.body
278 expect(tree.comment.text).equal('thread 1')
279 expect(tree.children).to.have.lengthOf(1)
280
281 const firstChild = tree.children[0]
282 expect(firstChild.comment.text).to.equal('comment 1-1')
283 expect(firstChild.children).to.have.lengthOf(1)
284
285 const childOfFirstChild = firstChild.children[0]
286 expect(childOfFirstChild.comment.text).to.equal('comment 1-2')
287 expect(childOfFirstChild.children).to.have.lengthOf(1)
288
289 const childOfChildFirstChild = childOfFirstChild.children[0]
290 expect(childOfChildFirstChild.comment.text).to.equal('comment 1-3')
291 expect(childOfChildFirstChild.children).to.have.lengthOf(1)
292
293 const childOfChildOfChildOfFirstChild = childOfChildFirstChild.children[0]
294 expect(childOfChildOfChildOfFirstChild.comment.text).to.equal('comment 1-4')
295 expect(childOfChildOfChildOfFirstChild.children).to.have.lengthOf(0)
296 }
2ccaeeb3
C
297 })
298
299 after(async function () {
300 killallServers(servers)
2ccaeeb3
C
301 })
302})