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