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