]>
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' |
c55e3d72 C |
5 | import { wait } from '@shared/core-utils' |
6 | import { ActivityType, VideoPlaylistPrivacy } from '@shared/models' | |
09cababd | 7 | import { |
7c3b7976 | 8 | cleanupTests, |
254d3579 | 9 | createMultipleServers, |
4c7e60bc | 10 | doubleFollow, |
254d3579 | 11 | PeerTubeServer, |
c3d29f69 | 12 | setAccessTokensToServers, |
c3d29f69 | 13 | waitJobs |
bf54587a | 14 | } from '@shared/server-commands' |
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, | |
8dd754c7 | 201 | '144p': false, |
65e6e260 C |
202 | '240p': false, |
203 | '360p': false, | |
204 | '480p': false, | |
205 | '720p': false, | |
206 | '1080p': false, | |
207 | '1440p': false, | |
208 | '2160p': false | |
209 | } | |
0b84383d C |
210 | } |
211 | } | |
212 | }) | |
213 | ||
89d241a7 | 214 | await servers[0].videos.upload({ attributes: { name: 'video', fixture: 'video_short.webm' } }) |
0b84383d C |
215 | |
216 | await waitJobs(servers) | |
217 | ||
218 | { | |
89d241a7 | 219 | const data = await servers[1].stats.get() |
0b84383d C |
220 | expect(data.totalLocalVideoFilesSize).to.equal(0) |
221 | } | |
222 | ||
223 | { | |
89d241a7 | 224 | const data = await servers[0].stats.get() |
fe19f600 RK |
225 | expect(data.totalLocalVideoFilesSize).to.be.greaterThan(500000) |
226 | expect(data.totalLocalVideoFilesSize).to.be.lessThan(600000) | |
0b84383d C |
227 | } |
228 | }) | |
229 | ||
99afa081 C |
230 | it('Should have the correct AP stats', async function () { |
231 | this.timeout(60000) | |
232 | ||
c729caf6 | 233 | await servers[0].config.disableTranscoding() |
54363cff | 234 | |
89d241a7 | 235 | const first = await servers[1].stats.get() |
9e454eba | 236 | |
99afa081 | 237 | for (let i = 0; i < 10; i++) { |
89d241a7 | 238 | await servers[0].videos.upload({ attributes: { name: 'video' } }) |
99afa081 C |
239 | } |
240 | ||
99afa081 C |
241 | await waitJobs(servers) |
242 | ||
94d721ef C |
243 | await wait(6000) |
244 | ||
89d241a7 | 245 | const second = await servers[1].stats.get() |
99afa081 | 246 | expect(second.totalActivityPubMessagesProcessed).to.be.greaterThan(first.totalActivityPubMessagesProcessed) |
bc809041 | 247 | |
543442a3 C |
248 | const apTypes: ActivityType[] = [ |
249 | 'Create', 'Update', 'Delete', 'Follow', 'Accept', 'Announce', 'Undo', 'Like', 'Reject', 'View', 'Dislike', 'Flag' | |
250 | ] | |
251 | ||
252 | const processed = apTypes.reduce( | |
253 | (previous, type) => previous + second['totalActivityPub' + type + 'MessagesSuccesses'], | |
254 | 0 | |
255 | ) | |
256 | expect(second.totalActivityPubMessagesProcessed).to.equal(processed) | |
257 | expect(second.totalActivityPubMessagesSuccesses).to.equal(processed) | |
258 | ||
259 | expect(second.totalActivityPubMessagesErrors).to.equal(0) | |
260 | ||
261 | for (const apType of apTypes) { | |
262 | expect(second['totalActivityPub' + apType + 'MessagesErrors']).to.equal(0) | |
263 | } | |
99afa081 | 264 | |
94d721ef | 265 | await wait(6000) |
99afa081 | 266 | |
89d241a7 | 267 | const third = await servers[1].stats.get() |
54363cff | 268 | expect(third.totalActivityPubMessagesWaiting).to.equal(0) |
99afa081 C |
269 | expect(third.activityPubMessagesProcessedPerSecond).to.be.lessThan(second.activityPubMessagesProcessedPerSecond) |
270 | }) | |
271 | ||
7c3b7976 C |
272 | after(async function () { |
273 | await cleanupTests(servers) | |
09cababd C |
274 | }) |
275 | }) |