]>
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 { | |
6 | cleanupTests, | |
7 | createUser, | |
8 | doubleFollow, | |
9 | flushAndRunMultipleServers, | |
10 | follow, | |
11 | ServerInfo, | |
12 | unfollow, | |
13 | updateCustomSubConfig, | |
14 | uploadVideo, | |
15 | userLogin, | |
16 | viewVideo, | |
17 | wait | |
18 | } from '../../../../shared/extra-utils' | |
19 | import { setAccessTokensToServers } from '../../../../shared/extra-utils/index' | |
20 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | |
21 | import { getStats } from '../../../../shared/extra-utils/server/stats' | |
22 | import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments' | |
23 | import { ServerStats } from '../../../../shared/models/server/server-stats.model' | |
24 | ||
25 | const expect = chai.expect | |
26 | ||
27 | describe('Test stats (excluding redundancy)', function () { | |
28 | let servers: ServerInfo[] = [] | |
29 | const user = { | |
30 | username: 'user1', | |
31 | password: 'super_password' | |
32 | } | |
33 | ||
34 | before(async function () { | |
35 | this.timeout(60000) | |
36 | ||
37 | servers = await flushAndRunMultipleServers(3) | |
38 | ||
39 | await setAccessTokensToServers(servers) | |
40 | ||
41 | await doubleFollow(servers[0], servers[1]) | |
42 | ||
43 | await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) | |
44 | ||
45 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { fixture: 'video_short.webm' }) | |
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 | ||
52 | // Wait the video views repeatable job | |
53 | await wait(8000) | |
54 | ||
55 | await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken) | |
56 | await waitJobs(servers) | |
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) | |
66 | expect(data.totalLocalVideoFilesSize).to.equal(218910) | |
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) | |
81 | expect(data.totalLocalVideoFilesSize).to.equal(0) | |
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 | ||
103 | it('Should have the correct total videos stats after an unfollow', async function () { | |
104 | this.timeout(15000) | |
105 | ||
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 | ||
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 | ||
137 | it('Should correctly count video file sizes if transcoding is enabled', async function () { | |
138 | this.timeout(60000) | |
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, | |
156 | '2160p': false | |
157 | } | |
158 | } | |
159 | }) | |
160 | ||
161 | await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video', fixture: 'video_short.webm' }) | |
162 | ||
163 | await waitJobs(servers) | |
164 | ||
165 | { | |
166 | const res = await getStats(servers[1].url) | |
167 | const data: ServerStats = res.body | |
168 | expect(data.totalLocalVideoFilesSize).to.equal(0) | |
169 | } | |
170 | ||
171 | { | |
172 | const res = await getStats(servers[0].url) | |
173 | const data: ServerStats = res.body | |
174 | expect(data.totalLocalVideoFilesSize).to.be.greaterThan(300000) | |
175 | expect(data.totalLocalVideoFilesSize).to.be.lessThan(400000) | |
176 | } | |
177 | }) | |
178 | ||
179 | it('Should have the correct AP stats', async function () { | |
180 | this.timeout(60000) | |
181 | ||
182 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { | |
183 | transcoding: { | |
184 | enabled: false | |
185 | } | |
186 | }) | |
187 | ||
188 | for (let i = 0; i < 10; i++) { | |
189 | await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) | |
190 | } | |
191 | ||
192 | const res1 = await getStats(servers[1].url) | |
193 | const first = res1.body as ServerStats | |
194 | ||
195 | await waitJobs(servers) | |
196 | ||
197 | const res2 = await getStats(servers[1].url) | |
198 | const second: ServerStats = res2.body | |
199 | ||
200 | expect(second.totalActivityPubMessagesProcessed).to.be.greaterThan(first.totalActivityPubMessagesProcessed) | |
201 | ||
202 | await wait(5000) | |
203 | ||
204 | const res3 = await getStats(servers[1].url) | |
205 | const third: ServerStats = res3.body | |
206 | ||
207 | expect(third.totalActivityPubMessagesWaiting).to.equal(0) | |
208 | expect(third.activityPubMessagesProcessedPerSecond).to.be.lessThan(second.activityPubMessagesProcessedPerSecond) | |
209 | }) | |
210 | ||
211 | after(async function () { | |
212 | await cleanupTests(servers) | |
213 | }) | |
214 | }) |