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