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