]>
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, |
09cababd C |
7 | createUser, |
8 | doubleFollow, | |
9 | flushAndRunMultipleServers, | |
10 | follow, | |
0b84383d C |
11 | ServerInfo, |
12 | unfollow, | |
13 | updateCustomSubConfig, | |
09cababd | 14 | uploadVideo, |
0b84383d | 15 | userLogin, |
09cababd | 16 | viewVideo, |
0b84383d | 17 | wait |
94565d52 | 18 | } from '../../../../shared/extra-utils' |
a1587156 | 19 | import { setAccessTokensToServers } from '../../../../shared/extra-utils/index' |
0b84383d | 20 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' |
94565d52 C |
21 | import { getStats } from '../../../../shared/extra-utils/server/stats' |
22 | import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments' | |
0b84383d | 23 | import { ServerStats } from '../../../../shared/models/server/server-stats.model' |
543442a3 | 24 | import { ActivityType } from '@shared/models' |
09cababd C |
25 | |
26 | const expect = chai.expect | |
27 | ||
4b5384f6 | 28 | describe('Test stats (excluding redundancy)', function () { |
09cababd | 29 | let servers: ServerInfo[] = [] |
3cc665f4 C |
30 | const user = { |
31 | username: 'user1', | |
32 | password: 'super_password' | |
33 | } | |
09cababd C |
34 | |
35 | before(async function () { | |
36 | this.timeout(60000) | |
0b84383d | 37 | |
09cababd | 38 | servers = await flushAndRunMultipleServers(3) |
0b84383d | 39 | |
09cababd C |
40 | await setAccessTokensToServers(servers) |
41 | ||
42 | await doubleFollow(servers[0], servers[1]) | |
43 | ||
a1587156 | 44 | await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) |
09cababd | 45 | |
44b9c0ba | 46 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { fixture: 'video_short.webm' }) |
09cababd C |
47 | const videoUUID = resVideo.body.video.uuid |
48 | ||
49 | await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'comment') | |
50 | ||
51 | await viewVideo(servers[0].url, videoUUID) | |
52 | ||
6b616860 C |
53 | // Wait the video views repeatable job |
54 | await wait(8000) | |
55 | ||
09cababd | 56 | await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken) |
3cd0734f | 57 | await waitJobs(servers) |
09cababd C |
58 | }) |
59 | ||
60 | it('Should have the correct stats on instance 1', async function () { | |
61 | const res = await getStats(servers[0].url) | |
62 | const data: ServerStats = res.body | |
63 | ||
64 | expect(data.totalLocalVideoComments).to.equal(1) | |
65 | expect(data.totalLocalVideos).to.equal(1) | |
66 | expect(data.totalLocalVideoViews).to.equal(1) | |
44b9c0ba | 67 | expect(data.totalLocalVideoFilesSize).to.equal(218910) |
09cababd C |
68 | expect(data.totalUsers).to.equal(2) |
69 | expect(data.totalVideoComments).to.equal(1) | |
70 | expect(data.totalVideos).to.equal(1) | |
71 | expect(data.totalInstanceFollowers).to.equal(2) | |
72 | expect(data.totalInstanceFollowing).to.equal(1) | |
73 | }) | |
74 | ||
75 | it('Should have the correct stats on instance 2', async function () { | |
76 | const res = await getStats(servers[1].url) | |
77 | const data: ServerStats = res.body | |
78 | ||
79 | expect(data.totalLocalVideoComments).to.equal(0) | |
80 | expect(data.totalLocalVideos).to.equal(0) | |
81 | expect(data.totalLocalVideoViews).to.equal(0) | |
848f499d | 82 | expect(data.totalLocalVideoFilesSize).to.equal(0) |
09cababd C |
83 | expect(data.totalUsers).to.equal(1) |
84 | expect(data.totalVideoComments).to.equal(1) | |
85 | expect(data.totalVideos).to.equal(1) | |
86 | expect(data.totalInstanceFollowers).to.equal(1) | |
87 | expect(data.totalInstanceFollowing).to.equal(1) | |
88 | }) | |
89 | ||
90 | it('Should have the correct stats on instance 3', async function () { | |
91 | const res = await getStats(servers[2].url) | |
92 | const data: ServerStats = res.body | |
93 | ||
94 | expect(data.totalLocalVideoComments).to.equal(0) | |
95 | expect(data.totalLocalVideos).to.equal(0) | |
96 | expect(data.totalLocalVideoViews).to.equal(0) | |
97 | expect(data.totalUsers).to.equal(1) | |
98 | expect(data.totalVideoComments).to.equal(1) | |
99 | expect(data.totalVideos).to.equal(1) | |
100 | expect(data.totalInstanceFollowing).to.equal(1) | |
101 | expect(data.totalInstanceFollowers).to.equal(0) | |
102 | }) | |
103 | ||
baab47ca | 104 | it('Should have the correct total videos stats after an unfollow', async function () { |
3cc665f4 C |
105 | this.timeout(15000) |
106 | ||
baab47ca C |
107 | await unfollow(servers[2].url, servers[2].accessToken, servers[0]) |
108 | await waitJobs(servers) | |
109 | ||
110 | const res = await getStats(servers[2].url) | |
111 | const data: ServerStats = res.body | |
112 | ||
113 | expect(data.totalVideos).to.equal(0) | |
114 | }) | |
115 | ||
3cc665f4 C |
116 | it('Should have the correct active users stats', async function () { |
117 | const server = servers[0] | |
118 | ||
119 | { | |
120 | const res = await getStats(server.url) | |
121 | const data: ServerStats = res.body | |
122 | expect(data.totalDailyActiveUsers).to.equal(1) | |
123 | expect(data.totalWeeklyActiveUsers).to.equal(1) | |
124 | expect(data.totalMonthlyActiveUsers).to.equal(1) | |
125 | } | |
126 | ||
127 | { | |
128 | await userLogin(server, user) | |
129 | ||
130 | const res = await getStats(server.url) | |
131 | const data: ServerStats = res.body | |
132 | expect(data.totalDailyActiveUsers).to.equal(2) | |
133 | expect(data.totalWeeklyActiveUsers).to.equal(2) | |
134 | expect(data.totalMonthlyActiveUsers).to.equal(2) | |
135 | } | |
136 | }) | |
137 | ||
0b84383d | 138 | it('Should correctly count video file sizes if transcoding is enabled', async function () { |
54363cff | 139 | this.timeout(60000) |
0b84383d C |
140 | |
141 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { | |
142 | transcoding: { | |
143 | enabled: true, | |
144 | webtorrent: { | |
145 | enabled: true | |
146 | }, | |
147 | hls: { | |
148 | enabled: true | |
149 | }, | |
150 | resolutions: { | |
151 | '0p': false, | |
152 | '240p': false, | |
153 | '360p': false, | |
154 | '480p': false, | |
155 | '720p': false, | |
156 | '1080p': false, | |
b7085c71 | 157 | '1440p': false, |
0b84383d C |
158 | '2160p': false |
159 | } | |
160 | } | |
161 | }) | |
162 | ||
163 | await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video', fixture: 'video_short.webm' }) | |
164 | ||
165 | await waitJobs(servers) | |
166 | ||
167 | { | |
168 | const res = await getStats(servers[1].url) | |
169 | const data: ServerStats = res.body | |
170 | expect(data.totalLocalVideoFilesSize).to.equal(0) | |
171 | } | |
172 | ||
173 | { | |
174 | const res = await getStats(servers[0].url) | |
175 | const data: ServerStats = res.body | |
176 | expect(data.totalLocalVideoFilesSize).to.be.greaterThan(300000) | |
177 | expect(data.totalLocalVideoFilesSize).to.be.lessThan(400000) | |
178 | } | |
179 | }) | |
180 | ||
99afa081 C |
181 | it('Should have the correct AP stats', async function () { |
182 | this.timeout(60000) | |
183 | ||
54363cff C |
184 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { |
185 | transcoding: { | |
186 | enabled: false | |
187 | } | |
188 | }) | |
189 | ||
9e454eba C |
190 | const res1 = await getStats(servers[1].url) |
191 | const first = res1.body as ServerStats | |
192 | ||
99afa081 C |
193 | for (let i = 0; i < 10; i++) { |
194 | await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) | |
195 | } | |
196 | ||
99afa081 C |
197 | await waitJobs(servers) |
198 | ||
94d721ef C |
199 | await wait(6000) |
200 | ||
99afa081 C |
201 | const res2 = await getStats(servers[1].url) |
202 | const second: ServerStats = res2.body | |
203 | ||
99afa081 | 204 | expect(second.totalActivityPubMessagesProcessed).to.be.greaterThan(first.totalActivityPubMessagesProcessed) |
543442a3 C |
205 | const apTypes: ActivityType[] = [ |
206 | 'Create', 'Update', 'Delete', 'Follow', 'Accept', 'Announce', 'Undo', 'Like', 'Reject', 'View', 'Dislike', 'Flag' | |
207 | ] | |
208 | ||
209 | const processed = apTypes.reduce( | |
210 | (previous, type) => previous + second['totalActivityPub' + type + 'MessagesSuccesses'], | |
211 | 0 | |
212 | ) | |
213 | expect(second.totalActivityPubMessagesProcessed).to.equal(processed) | |
214 | expect(second.totalActivityPubMessagesSuccesses).to.equal(processed) | |
215 | ||
216 | expect(second.totalActivityPubMessagesErrors).to.equal(0) | |
217 | ||
218 | for (const apType of apTypes) { | |
219 | expect(second['totalActivityPub' + apType + 'MessagesErrors']).to.equal(0) | |
220 | } | |
99afa081 | 221 | |
94d721ef | 222 | await wait(6000) |
99afa081 C |
223 | |
224 | const res3 = await getStats(servers[1].url) | |
225 | const third: ServerStats = res3.body | |
226 | ||
54363cff | 227 | expect(third.totalActivityPubMessagesWaiting).to.equal(0) |
99afa081 C |
228 | expect(third.activityPubMessagesProcessedPerSecond).to.be.lessThan(second.activityPubMessagesProcessedPerSecond) |
229 | }) | |
230 | ||
7c3b7976 C |
231 | after(async function () { |
232 | await cleanupTests(servers) | |
09cababd C |
233 | }) |
234 | }) |