1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
9 flushAndRunMultipleServers,
13 updateCustomSubConfig,
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'
25 const expect = chai.expect
27 describe('Test stats (excluding redundancy)', function () {
28 let servers: ServerInfo[] = []
31 password: 'super_password'
34 before(async function () {
37 servers = await flushAndRunMultipleServers(3)
39 await setAccessTokensToServers(servers)
41 await doubleFollow(servers[0], servers[1])
43 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
45 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { fixture: 'video_short.webm' })
46 const videoUUID = resVideo.body.video.uuid
48 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'comment')
50 await viewVideo(servers[0].url, videoUUID)
52 // Wait the video views repeatable job
55 await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
56 await waitJobs(servers)
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
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)
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
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)
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
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)
103 it('Should have the correct total videos stats after an unfollow', async function () {
106 await unfollow(servers[2].url, servers[2].accessToken, servers[0])
107 await waitJobs(servers)
109 const res = await getStats(servers[2].url)
110 const data: ServerStats = res.body
112 expect(data.totalVideos).to.equal(0)
115 it('Should have the correct active users stats', async function () {
116 const server = servers[0]
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)
127 await userLogin(server, user)
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)
137 it('Should correctly count video file sizes if transcoding is enabled', async function () {
140 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
162 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video', fixture: 'video_short.webm' })
164 await waitJobs(servers)
167 const res = await getStats(servers[1].url)
168 const data: ServerStats = res.body
169 expect(data.totalLocalVideoFilesSize).to.equal(0)
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)
180 it('Should have the correct AP stats', async function () {
183 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
189 const res1 = await getStats(servers[1].url)
190 const first = res1.body as ServerStats
192 for (let i = 0; i < 10; i++) {
193 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' })
196 await waitJobs(servers)
200 const res2 = await getStats(servers[1].url)
201 const second: ServerStats = res2.body
203 expect(second.totalActivityPubMessagesProcessed).to.be.greaterThan(first.totalActivityPubMessagesProcessed)
207 const res3 = await getStats(servers[1].url)
208 const third: ServerStats = res3.body
210 expect(third.totalActivityPubMessagesWaiting).to.equal(0)
211 expect(third.activityPubMessagesProcessedPerSecond).to.be.lessThan(second.activityPubMessagesProcessedPerSecond)
214 after(async function () {
215 await cleanupTests(servers)