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