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