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