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