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