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