aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/views/videos-views-cleaner.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-03-24 13:36:47 +0100
committerChocobozzz <chocobozzz@cpy.re>2022-04-15 09:49:35 +0200
commitb211106695bb82f6c32e53306081b5262c3d109d (patch)
treefa187de1c33b0956665f5362e29af6b0f6d8bb57 /server/tests/api/views/videos-views-cleaner.ts
parent69d48ee30c9d47cddf0c3c047dc99a99dcb6e894 (diff)
downloadPeerTube-b211106695bb82f6c32e53306081b5262c3d109d.tar.gz
PeerTube-b211106695bb82f6c32e53306081b5262c3d109d.tar.zst
PeerTube-b211106695bb82f6c32e53306081b5262c3d109d.zip
Support video views/viewers stats in server
* Add "currentTime" and "event" body params to view endpoint * Merge watching and view endpoints * Introduce WatchAction AP activity * Add tables to store viewer information of local videos * Add endpoints to fetch video views/viewers stats of local videos * Refactor views/viewers handlers * Support "views" and "viewers" counters for both VOD and live videos
Diffstat (limited to 'server/tests/api/views/videos-views-cleaner.ts')
-rw-r--r--server/tests/api/views/videos-views-cleaner.ts101
1 files changed, 101 insertions, 0 deletions
diff --git a/server/tests/api/views/videos-views-cleaner.ts b/server/tests/api/views/videos-views-cleaner.ts
new file mode 100644
index 000000000..ef988837f
--- /dev/null
+++ b/server/tests/api/views/videos-views-cleaner.ts
@@ -0,0 +1,101 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
5import { wait } from '@shared/core-utils'
6import {
7 cleanupTests,
8 createMultipleServers,
9 doubleFollow,
10 killallServers,
11 PeerTubeServer,
12 setAccessTokensToServers,
13 waitJobs
14} from '@shared/server-commands'
15
16const expect = chai.expect
17
18describe('Test video views cleaner', function () {
19 let servers: PeerTubeServer[]
20
21 let videoIdServer1: string
22 let videoIdServer2: string
23
24 before(async function () {
25 this.timeout(120000)
26
27 servers = await createMultipleServers(2)
28 await setAccessTokensToServers(servers)
29
30 await doubleFollow(servers[0], servers[1])
31
32 videoIdServer1 = (await servers[0].videos.quickUpload({ name: 'video server 1' })).uuid
33 videoIdServer2 = (await servers[1].videos.quickUpload({ name: 'video server 2' })).uuid
34
35 await waitJobs(servers)
36
37 await servers[0].views.simulateView({ id: videoIdServer1 })
38 await servers[1].views.simulateView({ id: videoIdServer1 })
39 await servers[0].views.simulateView({ id: videoIdServer2 })
40 await servers[1].views.simulateView({ id: videoIdServer2 })
41
42 await waitJobs(servers)
43 })
44
45 it('Should not clean old video views', async function () {
46 this.timeout(50000)
47
48 await killallServers([ servers[0] ])
49
50 await servers[0].run({ views: { videos: { remote: { max_age: '10 days' } } } })
51
52 await wait(6000)
53
54 // Should still have views
55
56 {
57 for (const server of servers) {
58 const total = await server.sql.countVideoViewsOf(videoIdServer1)
59 expect(total).to.equal(2, 'Server ' + server.serverNumber + ' does not have the correct amount of views')
60 }
61 }
62
63 {
64 for (const server of servers) {
65 const total = await server.sql.countVideoViewsOf(videoIdServer2)
66 expect(total).to.equal(2, 'Server ' + server.serverNumber + ' does not have the correct amount of views')
67 }
68 }
69 })
70
71 it('Should clean old video views', async function () {
72 this.timeout(50000)
73
74 await killallServers([ servers[0] ])
75
76 await servers[0].run({ views: { videos: { remote: { max_age: '5 seconds' } } } })
77
78 await wait(6000)
79
80 // Should still have views
81
82 {
83 for (const server of servers) {
84 const total = await server.sql.countVideoViewsOf(videoIdServer1)
85 expect(total).to.equal(2)
86 }
87 }
88
89 {
90 const totalServer1 = await servers[0].sql.countVideoViewsOf(videoIdServer2)
91 expect(totalServer1).to.equal(0)
92
93 const totalServer2 = await servers[1].sql.countVideoViewsOf(videoIdServer2)
94 expect(totalServer2).to.equal(2)
95 }
96 })
97
98 after(async function () {
99 await cleanupTests(servers)
100 })
101})