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