1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
10 flushAndRunMultipleServers,
12 setAccessTokensToServers,
18 } from '@shared/extra-utils'
19 import { ActivityType, VideoPlaylistPrivacy } from '@shared/models'
21 const expect = chai.expect
23 describe('Test stats (excluding redundancy)', function () {
24 let servers: ServerInfo[] = []
28 password: 'super_password'
31 before(async function () {
34 servers = await flushAndRunMultipleServers(3)
36 await setAccessTokensToServers(servers)
38 await doubleFollow(servers[0], servers[1])
40 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
42 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { fixture: 'video_short.webm' })
43 const videoUUID = resVideo.body.video.uuid
45 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'comment')
47 await viewVideo(servers[0].url, videoUUID)
49 // Wait the video views repeatable job
52 await servers[2].followsCommand.follow({ targets: [ servers[0].url ] })
53 await waitJobs(servers)
56 it('Should have the correct stats on instance 1', async function () {
57 const data = await servers[0].statsCommand.get()
59 expect(data.totalLocalVideoComments).to.equal(1)
60 expect(data.totalLocalVideos).to.equal(1)
61 expect(data.totalLocalVideoViews).to.equal(1)
62 expect(data.totalLocalVideoFilesSize).to.equal(218910)
63 expect(data.totalUsers).to.equal(2)
64 expect(data.totalVideoComments).to.equal(1)
65 expect(data.totalVideos).to.equal(1)
66 expect(data.totalInstanceFollowers).to.equal(2)
67 expect(data.totalInstanceFollowing).to.equal(1)
68 expect(data.totalLocalPlaylists).to.equal(0)
71 it('Should have the correct stats on instance 2', async function () {
72 const data = await servers[1].statsCommand.get()
74 expect(data.totalLocalVideoComments).to.equal(0)
75 expect(data.totalLocalVideos).to.equal(0)
76 expect(data.totalLocalVideoViews).to.equal(0)
77 expect(data.totalLocalVideoFilesSize).to.equal(0)
78 expect(data.totalUsers).to.equal(1)
79 expect(data.totalVideoComments).to.equal(1)
80 expect(data.totalVideos).to.equal(1)
81 expect(data.totalInstanceFollowers).to.equal(1)
82 expect(data.totalInstanceFollowing).to.equal(1)
83 expect(data.totalLocalPlaylists).to.equal(0)
86 it('Should have the correct stats on instance 3', async function () {
87 const data = await servers[2].statsCommand.get()
89 expect(data.totalLocalVideoComments).to.equal(0)
90 expect(data.totalLocalVideos).to.equal(0)
91 expect(data.totalLocalVideoViews).to.equal(0)
92 expect(data.totalUsers).to.equal(1)
93 expect(data.totalVideoComments).to.equal(1)
94 expect(data.totalVideos).to.equal(1)
95 expect(data.totalInstanceFollowing).to.equal(1)
96 expect(data.totalInstanceFollowers).to.equal(0)
97 expect(data.totalLocalPlaylists).to.equal(0)
100 it('Should have the correct total videos stats after an unfollow', async function () {
103 await servers[2].followsCommand.unfollow({ target: servers[0] })
104 await waitJobs(servers)
106 const data = await servers[2].statsCommand.get()
108 expect(data.totalVideos).to.equal(0)
111 it('Should have the correct active user stats', async function () {
112 const server = servers[0]
115 const data = await server.statsCommand.get()
117 expect(data.totalDailyActiveUsers).to.equal(1)
118 expect(data.totalWeeklyActiveUsers).to.equal(1)
119 expect(data.totalMonthlyActiveUsers).to.equal(1)
123 await userLogin(server, user)
125 const data = await server.statsCommand.get()
127 expect(data.totalDailyActiveUsers).to.equal(2)
128 expect(data.totalWeeklyActiveUsers).to.equal(2)
129 expect(data.totalMonthlyActiveUsers).to.equal(2)
133 it('Should have the correct active channel stats', async function () {
134 const server = servers[0]
137 const data = await server.statsCommand.get()
139 expect(data.totalLocalDailyActiveVideoChannels).to.equal(1)
140 expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(1)
141 expect(data.totalLocalMonthlyActiveVideoChannels).to.equal(1)
146 name: 'stats_channel',
147 displayName: 'My stats channel'
149 const created = await server.channelsCommand.create({ attributes })
150 channelId = created.id
152 const data = await server.statsCommand.get()
154 expect(data.totalLocalDailyActiveVideoChannels).to.equal(1)
155 expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(1)
156 expect(data.totalLocalMonthlyActiveVideoChannels).to.equal(1)
160 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.webm', channelId })
162 const data = await server.statsCommand.get()
164 expect(data.totalLocalDailyActiveVideoChannels).to.equal(2)
165 expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(2)
166 expect(data.totalLocalMonthlyActiveVideoChannels).to.equal(2)
170 it('Should have the correct playlist stats', async function () {
171 const server = servers[0]
174 const data = await server.statsCommand.get()
175 expect(data.totalLocalPlaylists).to.equal(0)
179 await server.playlistsCommand.create({
181 displayName: 'playlist for count',
182 privacy: VideoPlaylistPrivacy.PUBLIC,
183 videoChannelId: channelId
187 const data = await server.statsCommand.get()
188 expect(data.totalLocalPlaylists).to.equal(1)
192 it('Should correctly count video file sizes if transcoding is enabled', async function () {
195 await servers[0].configCommand.updateCustomSubConfig({
219 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video', fixture: 'video_short.webm' })
221 await waitJobs(servers)
224 const data = await servers[1].statsCommand.get()
225 expect(data.totalLocalVideoFilesSize).to.equal(0)
229 const data = await servers[0].statsCommand.get()
230 expect(data.totalLocalVideoFilesSize).to.be.greaterThan(500000)
231 expect(data.totalLocalVideoFilesSize).to.be.lessThan(600000)
235 it('Should have the correct AP stats', async function () {
238 await servers[0].configCommand.updateCustomSubConfig({
246 const first = await servers[1].statsCommand.get()
248 for (let i = 0; i < 10; i++) {
249 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' })
252 await waitJobs(servers)
256 const second = await servers[1].statsCommand.get()
257 expect(second.totalActivityPubMessagesProcessed).to.be.greaterThan(first.totalActivityPubMessagesProcessed)
259 const apTypes: ActivityType[] = [
260 'Create', 'Update', 'Delete', 'Follow', 'Accept', 'Announce', 'Undo', 'Like', 'Reject', 'View', 'Dislike', 'Flag'
263 const processed = apTypes.reduce(
264 (previous, type) => previous + second['totalActivityPub' + type + 'MessagesSuccesses'],
267 expect(second.totalActivityPubMessagesProcessed).to.equal(processed)
268 expect(second.totalActivityPubMessagesSuccesses).to.equal(processed)
270 expect(second.totalActivityPubMessagesErrors).to.equal(0)
272 for (const apType of apTypes) {
273 expect(second['totalActivityPub' + apType + 'MessagesErrors']).to.equal(0)
278 const third = await servers[1].statsCommand.get()
279 expect(third.totalActivityPubMessagesWaiting).to.equal(0)
280 expect(third.activityPubMessagesProcessedPerSecond).to.be.lessThan(second.activityPubMessagesProcessedPerSecond)
283 after(async function () {
284 await cleanupTests(servers)