]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | import { wait } from '@shared/core-utils' | |
6 | import { ActivityType, VideoPlaylistPrivacy } from '@shared/models' | |
7 | import { | |
8 | cleanupTests, | |
9 | createMultipleServers, | |
10 | doubleFollow, | |
11 | PeerTubeServer, | |
12 | setAccessTokensToServers, | |
13 | setDefaultAccountAvatar, | |
14 | setDefaultChannelAvatar, | |
15 | waitJobs | |
16 | } from '@shared/server-commands' | |
17 | ||
18 | const expect = chai.expect | |
19 | ||
20 | describe('Test stats (excluding redundancy)', function () { | |
21 | let servers: PeerTubeServer[] = [] | |
22 | let channelId | |
23 | const user = { | |
24 | username: 'user1', | |
25 | password: 'super_password' | |
26 | } | |
27 | ||
28 | before(async function () { | |
29 | this.timeout(60000) | |
30 | ||
31 | servers = await createMultipleServers(3) | |
32 | ||
33 | await setAccessTokensToServers(servers) | |
34 | await setDefaultChannelAvatar(servers) | |
35 | await setDefaultAccountAvatar(servers) | |
36 | ||
37 | await doubleFollow(servers[0], servers[1]) | |
38 | ||
39 | await servers[0].users.create({ username: user.username, password: user.password }) | |
40 | ||
41 | const { uuid } = await servers[0].videos.upload({ attributes: { fixture: 'video_short.webm' } }) | |
42 | ||
43 | await servers[0].comments.createThread({ videoId: uuid, text: 'comment' }) | |
44 | ||
45 | await servers[0].views.simulateView({ id: uuid }) | |
46 | ||
47 | // Wait the video views repeatable job | |
48 | await wait(8000) | |
49 | ||
50 | await servers[2].follows.follow({ hosts: [ servers[0].url ] }) | |
51 | await waitJobs(servers) | |
52 | }) | |
53 | ||
54 | it('Should have the correct stats on instance 1', async function () { | |
55 | const data = await servers[0].stats.get() | |
56 | ||
57 | expect(data.totalLocalVideoComments).to.equal(1) | |
58 | expect(data.totalLocalVideos).to.equal(1) | |
59 | expect(data.totalLocalVideoViews).to.equal(1) | |
60 | expect(data.totalLocalVideoFilesSize).to.equal(218910) | |
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) | |
66 | expect(data.totalLocalPlaylists).to.equal(0) | |
67 | }) | |
68 | ||
69 | it('Should have the correct stats on instance 2', async function () { | |
70 | const data = await servers[1].stats.get() | |
71 | ||
72 | expect(data.totalLocalVideoComments).to.equal(0) | |
73 | expect(data.totalLocalVideos).to.equal(0) | |
74 | expect(data.totalLocalVideoViews).to.equal(0) | |
75 | expect(data.totalLocalVideoFilesSize).to.equal(0) | |
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) | |
81 | expect(data.totalLocalPlaylists).to.equal(0) | |
82 | }) | |
83 | ||
84 | it('Should have the correct stats on instance 3', async function () { | |
85 | const data = await servers[2].stats.get() | |
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) | |
95 | expect(data.totalLocalPlaylists).to.equal(0) | |
96 | }) | |
97 | ||
98 | it('Should have the correct total videos stats after an unfollow', async function () { | |
99 | this.timeout(15000) | |
100 | ||
101 | await servers[2].follows.unfollow({ target: servers[0] }) | |
102 | await waitJobs(servers) | |
103 | ||
104 | const data = await servers[2].stats.get() | |
105 | ||
106 | expect(data.totalVideos).to.equal(0) | |
107 | }) | |
108 | ||
109 | it('Should have the correct active user stats', async function () { | |
110 | const server = servers[0] | |
111 | ||
112 | { | |
113 | const data = await server.stats.get() | |
114 | ||
115 | expect(data.totalDailyActiveUsers).to.equal(1) | |
116 | expect(data.totalWeeklyActiveUsers).to.equal(1) | |
117 | expect(data.totalMonthlyActiveUsers).to.equal(1) | |
118 | } | |
119 | ||
120 | { | |
121 | await server.login.getAccessToken(user) | |
122 | ||
123 | const data = await server.stats.get() | |
124 | ||
125 | expect(data.totalDailyActiveUsers).to.equal(2) | |
126 | expect(data.totalWeeklyActiveUsers).to.equal(2) | |
127 | expect(data.totalMonthlyActiveUsers).to.equal(2) | |
128 | } | |
129 | }) | |
130 | ||
131 | it('Should have the correct active channel stats', async function () { | |
132 | const server = servers[0] | |
133 | ||
134 | { | |
135 | const data = await server.stats.get() | |
136 | ||
137 | expect(data.totalLocalDailyActiveVideoChannels).to.equal(1) | |
138 | expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(1) | |
139 | expect(data.totalLocalMonthlyActiveVideoChannels).to.equal(1) | |
140 | } | |
141 | ||
142 | { | |
143 | const attributes = { | |
144 | name: 'stats_channel', | |
145 | displayName: 'My stats channel' | |
146 | } | |
147 | const created = await server.channels.create({ attributes }) | |
148 | channelId = created.id | |
149 | ||
150 | const data = await server.stats.get() | |
151 | ||
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 server.videos.upload({ attributes: { fixture: 'video_short.webm', channelId } }) | |
159 | ||
160 | const data = await server.stats.get() | |
161 | ||
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 | { | |
172 | const data = await server.stats.get() | |
173 | expect(data.totalLocalPlaylists).to.equal(0) | |
174 | } | |
175 | ||
176 | { | |
177 | await server.playlists.create({ | |
178 | attributes: { | |
179 | displayName: 'playlist for count', | |
180 | privacy: VideoPlaylistPrivacy.PUBLIC, | |
181 | videoChannelId: channelId | |
182 | } | |
183 | }) | |
184 | ||
185 | const data = await server.stats.get() | |
186 | expect(data.totalLocalPlaylists).to.equal(1) | |
187 | } | |
188 | }) | |
189 | ||
190 | it('Should correctly count video file sizes if transcoding is enabled', async function () { | |
191 | this.timeout(60000) | |
192 | ||
193 | await servers[0].config.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 | '144p': false, | |
206 | '240p': false, | |
207 | '360p': false, | |
208 | '480p': false, | |
209 | '720p': false, | |
210 | '1080p': false, | |
211 | '1440p': false, | |
212 | '2160p': false | |
213 | } | |
214 | } | |
215 | } | |
216 | }) | |
217 | ||
218 | await servers[0].videos.upload({ attributes: { name: 'video', fixture: 'video_short.webm' } }) | |
219 | ||
220 | await waitJobs(servers) | |
221 | ||
222 | { | |
223 | const data = await servers[1].stats.get() | |
224 | expect(data.totalLocalVideoFilesSize).to.equal(0) | |
225 | } | |
226 | ||
227 | { | |
228 | const data = await servers[0].stats.get() | |
229 | expect(data.totalLocalVideoFilesSize).to.be.greaterThan(500000) | |
230 | expect(data.totalLocalVideoFilesSize).to.be.lessThan(600000) | |
231 | } | |
232 | }) | |
233 | ||
234 | it('Should have the correct AP stats', async function () { | |
235 | this.timeout(60000) | |
236 | ||
237 | await servers[0].config.disableTranscoding() | |
238 | ||
239 | const first = await servers[1].stats.get() | |
240 | ||
241 | for (let i = 0; i < 10; i++) { | |
242 | await servers[0].videos.upload({ attributes: { name: 'video' } }) | |
243 | } | |
244 | ||
245 | await waitJobs(servers) | |
246 | ||
247 | await wait(6000) | |
248 | ||
249 | const second = await servers[1].stats.get() | |
250 | expect(second.totalActivityPubMessagesProcessed).to.be.greaterThan(first.totalActivityPubMessagesProcessed) | |
251 | ||
252 | const apTypes: ActivityType[] = [ | |
253 | 'Create', 'Update', 'Delete', 'Follow', 'Accept', 'Announce', 'Undo', 'Like', 'Reject', 'View', 'Dislike', 'Flag' | |
254 | ] | |
255 | ||
256 | const processed = apTypes.reduce( | |
257 | (previous, type) => previous + second['totalActivityPub' + type + 'MessagesSuccesses'], | |
258 | 0 | |
259 | ) | |
260 | expect(second.totalActivityPubMessagesProcessed).to.equal(processed) | |
261 | expect(second.totalActivityPubMessagesSuccesses).to.equal(processed) | |
262 | ||
263 | expect(second.totalActivityPubMessagesErrors).to.equal(0) | |
264 | ||
265 | for (const apType of apTypes) { | |
266 | expect(second['totalActivityPub' + apType + 'MessagesErrors']).to.equal(0) | |
267 | } | |
268 | ||
269 | await wait(6000) | |
270 | ||
271 | const third = await servers[1].stats.get() | |
272 | expect(third.totalActivityPubMessagesWaiting).to.equal(0) | |
273 | expect(third.activityPubMessagesProcessedPerSecond).to.be.lessThan(second.activityPubMessagesProcessedPerSecond) | |
274 | }) | |
275 | ||
276 | after(async function () { | |
277 | await cleanupTests(servers) | |
278 | }) | |
279 | }) |