]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/views/videos-views-cleaner.ts
Cleanup tests imports
[github/Chocobozzz/PeerTube.git] / server / tests / api / views / videos-views-cleaner.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import { expect } from 'chai'
4 import { wait } from '@shared/core-utils'
5 import {
6 cleanupTests,
7 createMultipleServers,
8 doubleFollow,
9 killallServers,
10 PeerTubeServer,
11 setAccessTokensToServers,
12 waitJobs
13 } from '@shared/server-commands'
14
15 describe('Test video views cleaner', function () {
16 let servers: PeerTubeServer[]
17
18 let videoIdServer1: string
19 let videoIdServer2: string
20
21 before(async function () {
22 this.timeout(120000)
23
24 servers = await createMultipleServers(2)
25 await setAccessTokensToServers(servers)
26
27 await doubleFollow(servers[0], servers[1])
28
29 videoIdServer1 = (await servers[0].videos.quickUpload({ name: 'video server 1' })).uuid
30 videoIdServer2 = (await servers[1].videos.quickUpload({ name: 'video server 2' })).uuid
31
32 await waitJobs(servers)
33
34 await servers[0].views.simulateView({ id: videoIdServer1 })
35 await servers[1].views.simulateView({ id: videoIdServer1 })
36 await servers[0].views.simulateView({ id: videoIdServer2 })
37 await servers[1].views.simulateView({ id: videoIdServer2 })
38
39 await waitJobs(servers)
40 })
41
42 it('Should not clean old video views', async function () {
43 this.timeout(50000)
44
45 await killallServers([ servers[0] ])
46
47 await servers[0].run({ views: { videos: { remote: { max_age: '10 days' } } } })
48
49 await wait(6000)
50
51 // Should still have views
52
53 {
54 for (const server of servers) {
55 const total = await server.sql.countVideoViewsOf(videoIdServer1)
56 expect(total).to.equal(2, 'Server ' + server.serverNumber + ' does not have the correct amount of views')
57 }
58 }
59
60 {
61 for (const server of servers) {
62 const total = await server.sql.countVideoViewsOf(videoIdServer2)
63 expect(total).to.equal(2, 'Server ' + server.serverNumber + ' does not have the correct amount of views')
64 }
65 }
66 })
67
68 it('Should clean old video views', async function () {
69 this.timeout(50000)
70
71 await killallServers([ servers[0] ])
72
73 await servers[0].run({ views: { videos: { remote: { max_age: '5 seconds' } } } })
74
75 await wait(6000)
76
77 // Should still have views
78
79 {
80 for (const server of servers) {
81 const total = await server.sql.countVideoViewsOf(videoIdServer1)
82 expect(total).to.equal(2)
83 }
84 }
85
86 {
87 const totalServer1 = await servers[0].sql.countVideoViewsOf(videoIdServer2)
88 expect(totalServer1).to.equal(0)
89
90 const totalServer2 = await servers[1].sql.countVideoViewsOf(videoIdServer2)
91 expect(totalServer2).to.equal(2)
92 }
93 })
94
95 after(async function () {
96 await cleanupTests(servers)
97 })
98 })