]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
09cababd | 2 | |
09cababd | 3 | import 'mocha' |
0b84383d | 4 | import * as chai from 'chai' |
09cababd | 5 | import { |
fe19f600 | 6 | addVideoChannel, |
7c3b7976 | 7 | cleanupTests, |
09cababd | 8 | createUser, |
fe19f600 | 9 | createVideoPlaylist, |
09cababd C |
10 | doubleFollow, |
11 | flushAndRunMultipleServers, | |
12 | follow, | |
0b84383d C |
13 | ServerInfo, |
14 | unfollow, | |
15 | updateCustomSubConfig, | |
09cababd | 16 | uploadVideo, |
0b84383d | 17 | userLogin, |
09cababd | 18 | viewVideo, |
0b84383d | 19 | wait |
94565d52 | 20 | } from '../../../../shared/extra-utils' |
a1587156 | 21 | import { setAccessTokensToServers } from '../../../../shared/extra-utils/index' |
0b84383d | 22 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' |
94565d52 C |
23 | import { getStats } from '../../../../shared/extra-utils/server/stats' |
24 | import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments' | |
0b84383d | 25 | import { ServerStats } from '../../../../shared/models/server/server-stats.model' |
fe19f600 | 26 | import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' |
543442a3 | 27 | import { ActivityType } from '@shared/models' |
09cababd C |
28 | |
29 | const expect = chai.expect | |
30 | ||
4b5384f6 | 31 | describe('Test stats (excluding redundancy)', function () { |
09cababd | 32 | let servers: ServerInfo[] = [] |
fe19f600 | 33 | let channelId |
3cc665f4 C |
34 | const user = { |
35 | username: 'user1', | |
36 | password: 'super_password' | |
37 | } | |
09cababd C |
38 | |
39 | before(async function () { | |
40 | this.timeout(60000) | |
0b84383d | 41 | |
09cababd | 42 | servers = await flushAndRunMultipleServers(3) |
0b84383d | 43 | |
09cababd C |
44 | await setAccessTokensToServers(servers) |
45 | ||
46 | await doubleFollow(servers[0], servers[1]) | |
47 | ||
a1587156 | 48 | await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) |
09cababd | 49 | |
44b9c0ba | 50 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { fixture: 'video_short.webm' }) |
09cababd C |
51 | const videoUUID = resVideo.body.video.uuid |
52 | ||
53 | await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'comment') | |
54 | ||
55 | await viewVideo(servers[0].url, videoUUID) | |
56 | ||
6b616860 C |
57 | // Wait the video views repeatable job |
58 | await wait(8000) | |
59 | ||
09cababd | 60 | await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken) |
3cd0734f | 61 | await waitJobs(servers) |
09cababd C |
62 | }) |
63 | ||
64 | it('Should have the correct stats on instance 1', async function () { | |
65 | const res = await getStats(servers[0].url) | |
66 | const data: ServerStats = res.body | |
67 | ||
68 | expect(data.totalLocalVideoComments).to.equal(1) | |
69 | expect(data.totalLocalVideos).to.equal(1) | |
70 | expect(data.totalLocalVideoViews).to.equal(1) | |
44b9c0ba | 71 | expect(data.totalLocalVideoFilesSize).to.equal(218910) |
09cababd C |
72 | expect(data.totalUsers).to.equal(2) |
73 | expect(data.totalVideoComments).to.equal(1) | |
74 | expect(data.totalVideos).to.equal(1) | |
75 | expect(data.totalInstanceFollowers).to.equal(2) | |
76 | expect(data.totalInstanceFollowing).to.equal(1) | |
fe19f600 | 77 | expect(data.totalLocalPlaylists).to.equal(0) |
09cababd C |
78 | }) |
79 | ||
80 | it('Should have the correct stats on instance 2', async function () { | |
81 | const res = await getStats(servers[1].url) | |
82 | const data: ServerStats = res.body | |
83 | ||
84 | expect(data.totalLocalVideoComments).to.equal(0) | |
85 | expect(data.totalLocalVideos).to.equal(0) | |
86 | expect(data.totalLocalVideoViews).to.equal(0) | |
848f499d | 87 | expect(data.totalLocalVideoFilesSize).to.equal(0) |
09cababd C |
88 | expect(data.totalUsers).to.equal(1) |
89 | expect(data.totalVideoComments).to.equal(1) | |
90 | expect(data.totalVideos).to.equal(1) | |
91 | expect(data.totalInstanceFollowers).to.equal(1) | |
92 | expect(data.totalInstanceFollowing).to.equal(1) | |
fe19f600 | 93 | expect(data.totalLocalPlaylists).to.equal(0) |
09cababd C |
94 | }) |
95 | ||
96 | it('Should have the correct stats on instance 3', async function () { | |
97 | const res = await getStats(servers[2].url) | |
98 | const data: ServerStats = res.body | |
99 | ||
100 | expect(data.totalLocalVideoComments).to.equal(0) | |
101 | expect(data.totalLocalVideos).to.equal(0) | |
102 | expect(data.totalLocalVideoViews).to.equal(0) | |
103 | expect(data.totalUsers).to.equal(1) | |
104 | expect(data.totalVideoComments).to.equal(1) | |
105 | expect(data.totalVideos).to.equal(1) | |
106 | expect(data.totalInstanceFollowing).to.equal(1) | |
107 | expect(data.totalInstanceFollowers).to.equal(0) | |
fe19f600 | 108 | expect(data.totalLocalPlaylists).to.equal(0) |
09cababd C |
109 | }) |
110 | ||
baab47ca | 111 | it('Should have the correct total videos stats after an unfollow', async function () { |
3cc665f4 C |
112 | this.timeout(15000) |
113 | ||
baab47ca C |
114 | await unfollow(servers[2].url, servers[2].accessToken, servers[0]) |
115 | await waitJobs(servers) | |
116 | ||
117 | const res = await getStats(servers[2].url) | |
118 | const data: ServerStats = res.body | |
119 | ||
120 | expect(data.totalVideos).to.equal(0) | |
121 | }) | |
122 | ||
fe19f600 | 123 | it('Should have the correct active user stats', async function () { |
3cc665f4 C |
124 | const server = servers[0] |
125 | ||
126 | { | |
127 | const res = await getStats(server.url) | |
128 | const data: ServerStats = res.body | |
129 | expect(data.totalDailyActiveUsers).to.equal(1) | |
130 | expect(data.totalWeeklyActiveUsers).to.equal(1) | |
131 | expect(data.totalMonthlyActiveUsers).to.equal(1) | |
132 | } | |
133 | ||
134 | { | |
135 | await userLogin(server, user) | |
136 | ||
137 | const res = await getStats(server.url) | |
138 | const data: ServerStats = res.body | |
139 | expect(data.totalDailyActiveUsers).to.equal(2) | |
140 | expect(data.totalWeeklyActiveUsers).to.equal(2) | |
141 | expect(data.totalMonthlyActiveUsers).to.equal(2) | |
142 | } | |
143 | }) | |
144 | ||
fe19f600 RK |
145 | it('Should have the correct active channel stats', async function () { |
146 | const server = servers[0] | |
147 | ||
148 | { | |
149 | const res = await getStats(server.url) | |
150 | const data: ServerStats = res.body | |
151 | expect(data.totalLocalDailyActiveVideoChannels).to.equal(1) | |
152 | expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(1) | |
153 | expect(data.totalLocalMonthlyActiveVideoChannels).to.equal(1) | |
154 | } | |
155 | ||
156 | { | |
157 | const channelAttributes = { | |
158 | name: 'stats_channel', | |
159 | displayName: 'My stats channel' | |
160 | } | |
161 | const resChannel = await addVideoChannel(server.url, server.accessToken, channelAttributes) | |
162 | channelId = resChannel.body.videoChannel.id | |
163 | ||
164 | const res = await getStats(server.url) | |
165 | const data: ServerStats = res.body | |
166 | expect(data.totalLocalDailyActiveVideoChannels).to.equal(1) | |
167 | expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(1) | |
168 | expect(data.totalLocalMonthlyActiveVideoChannels).to.equal(1) | |
169 | } | |
170 | ||
171 | { | |
172 | await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.webm', channelId }) | |
173 | ||
174 | const res = await getStats(server.url) | |
175 | const data: ServerStats = res.body | |
176 | expect(data.totalLocalDailyActiveVideoChannels).to.equal(2) | |
177 | expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(2) | |
178 | expect(data.totalLocalMonthlyActiveVideoChannels).to.equal(2) | |
179 | } | |
180 | }) | |
181 | ||
182 | it('Should have the correct playlist stats', async function () { | |
183 | const server = servers[0] | |
184 | ||
185 | { | |
186 | const resStats = await getStats(server.url) | |
187 | const dataStats: ServerStats = resStats.body | |
188 | expect(dataStats.totalLocalPlaylists).to.equal(0) | |
189 | } | |
190 | ||
191 | { | |
192 | await createVideoPlaylist({ | |
193 | url: server.url, | |
194 | token: server.accessToken, | |
195 | playlistAttrs: { | |
196 | displayName: 'playlist for count', | |
197 | privacy: VideoPlaylistPrivacy.PUBLIC, | |
198 | videoChannelId: channelId | |
199 | } | |
200 | }) | |
201 | ||
202 | const resStats = await getStats(server.url) | |
203 | const dataStats: ServerStats = resStats.body | |
204 | expect(dataStats.totalLocalPlaylists).to.equal(1) | |
205 | } | |
206 | }) | |
207 | ||
0b84383d | 208 | it('Should correctly count video file sizes if transcoding is enabled', async function () { |
54363cff | 209 | this.timeout(60000) |
0b84383d C |
210 | |
211 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { | |
212 | transcoding: { | |
213 | enabled: true, | |
214 | webtorrent: { | |
215 | enabled: true | |
216 | }, | |
217 | hls: { | |
218 | enabled: true | |
219 | }, | |
220 | resolutions: { | |
221 | '0p': false, | |
222 | '240p': false, | |
223 | '360p': false, | |
224 | '480p': false, | |
225 | '720p': false, | |
226 | '1080p': false, | |
b7085c71 | 227 | '1440p': false, |
0b84383d C |
228 | '2160p': false |
229 | } | |
230 | } | |
231 | }) | |
232 | ||
233 | await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video', fixture: 'video_short.webm' }) | |
234 | ||
235 | await waitJobs(servers) | |
236 | ||
237 | { | |
238 | const res = await getStats(servers[1].url) | |
239 | const data: ServerStats = res.body | |
240 | expect(data.totalLocalVideoFilesSize).to.equal(0) | |
241 | } | |
242 | ||
243 | { | |
244 | const res = await getStats(servers[0].url) | |
245 | const data: ServerStats = res.body | |
fe19f600 RK |
246 | expect(data.totalLocalVideoFilesSize).to.be.greaterThan(500000) |
247 | expect(data.totalLocalVideoFilesSize).to.be.lessThan(600000) | |
0b84383d C |
248 | } |
249 | }) | |
250 | ||
99afa081 C |
251 | it('Should have the correct AP stats', async function () { |
252 | this.timeout(60000) | |
253 | ||
54363cff C |
254 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { |
255 | transcoding: { | |
256 | enabled: false | |
257 | } | |
258 | }) | |
259 | ||
9e454eba C |
260 | const res1 = await getStats(servers[1].url) |
261 | const first = res1.body as ServerStats | |
262 | ||
99afa081 C |
263 | for (let i = 0; i < 10; i++) { |
264 | await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) | |
265 | } | |
266 | ||
99afa081 C |
267 | await waitJobs(servers) |
268 | ||
94d721ef C |
269 | await wait(6000) |
270 | ||
99afa081 C |
271 | const res2 = await getStats(servers[1].url) |
272 | const second: ServerStats = res2.body | |
273 | ||
99afa081 | 274 | expect(second.totalActivityPubMessagesProcessed).to.be.greaterThan(first.totalActivityPubMessagesProcessed) |
543442a3 C |
275 | const apTypes: ActivityType[] = [ |
276 | 'Create', 'Update', 'Delete', 'Follow', 'Accept', 'Announce', 'Undo', 'Like', 'Reject', 'View', 'Dislike', 'Flag' | |
277 | ] | |
278 | ||
279 | const processed = apTypes.reduce( | |
280 | (previous, type) => previous + second['totalActivityPub' + type + 'MessagesSuccesses'], | |
281 | 0 | |
282 | ) | |
283 | expect(second.totalActivityPubMessagesProcessed).to.equal(processed) | |
284 | expect(second.totalActivityPubMessagesSuccesses).to.equal(processed) | |
285 | ||
286 | expect(second.totalActivityPubMessagesErrors).to.equal(0) | |
287 | ||
288 | for (const apType of apTypes) { | |
289 | expect(second['totalActivityPub' + apType + 'MessagesErrors']).to.equal(0) | |
290 | } | |
99afa081 | 291 | |
94d721ef | 292 | await wait(6000) |
99afa081 C |
293 | |
294 | const res3 = await getStats(servers[1].url) | |
295 | const third: ServerStats = res3.body | |
296 | ||
54363cff | 297 | expect(third.totalActivityPubMessagesWaiting).to.equal(0) |
99afa081 C |
298 | expect(third.activityPubMessagesProcessedPerSecond).to.be.lessThan(second.activityPubMessagesProcessedPerSecond) |
299 | }) | |
300 | ||
7c3b7976 C |
301 | after(async function () { |
302 | await cleanupTests(servers) | |
09cababd C |
303 | }) |
304 | }) |