]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/videos/videos-views-cleaner.ts
All API tests in parallel
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / videos-views-cleaner.ts
1 /* tslint:disable:no-unused-expression */
2
3 import * as chai from 'chai'
4 import 'mocha'
5 import {
6 flushAndRunMultipleServers,
7 flushTests,
8 killallServers,
9 reRunServer,
10 flushAndRunServer,
11 ServerInfo,
12 setAccessTokensToServers,
13 uploadVideo, uploadVideoAndGetId, viewVideo, wait, countVideoViewsOf, doubleFollow, waitJobs, cleanupTests, closeAllSequelize
14 } from '../../../../shared/extra-utils'
15 import { getVideosOverview } from '../../../../shared/extra-utils/overviews/overviews'
16 import { VideosOverview } from '../../../../shared/models/overviews'
17 import { listMyVideosHistory } from '../../../../shared/extra-utils/videos/video-history'
18
19 const expect = chai.expect
20
21 describe('Test video views cleaner', function () {
22 let servers: ServerInfo[]
23
24 let videoIdServer1: string
25 let videoIdServer2: string
26
27 before(async function () {
28 this.timeout(50000)
29
30 servers = await flushAndRunMultipleServers(2)
31 await setAccessTokensToServers(servers)
32
33 await doubleFollow(servers[0], servers[1])
34
35 videoIdServer1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })).uuid
36 videoIdServer2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })).uuid
37
38 await waitJobs(servers)
39
40 await viewVideo(servers[0].url, videoIdServer1)
41 await viewVideo(servers[1].url, videoIdServer1)
42 await viewVideo(servers[0].url, videoIdServer2)
43 await viewVideo(servers[1].url, videoIdServer2)
44
45 await waitJobs(servers)
46 })
47
48 it('Should not clean old video views', async function () {
49 this.timeout(50000)
50
51 killallServers([ servers[0] ])
52
53 await reRunServer(servers[0], { views: { videos: { remote: { max_age: '10 days' } } } })
54
55 await wait(6000)
56
57 // Should still have views
58
59 {
60 for (const server of servers) {
61 const total = await countVideoViewsOf(server.internalServerNumber, videoIdServer1)
62 expect(total).to.equal(2)
63 }
64 }
65
66 {
67 for (const server of servers) {
68 const total = await countVideoViewsOf(server.internalServerNumber, videoIdServer2)
69 expect(total).to.equal(2)
70 }
71 }
72 })
73
74 it('Should clean old video views', async function () {
75 this.timeout(50000)
76
77 killallServers([ servers[0] ])
78
79 await reRunServer(servers[0], { views: { videos: { remote: { max_age: '5 seconds' } } } })
80
81 await wait(6000)
82
83 // Should still have views
84
85 {
86 for (const server of servers) {
87 const total = await countVideoViewsOf(server.internalServerNumber, videoIdServer1)
88 expect(total).to.equal(2)
89 }
90 }
91
92 {
93 const totalServer1 = await countVideoViewsOf(servers[0].internalServerNumber, videoIdServer2)
94 expect(totalServer1).to.equal(0)
95
96 const totalServer2 = await countVideoViewsOf(servers[1].internalServerNumber, videoIdServer2)
97 expect(totalServer2).to.equal(2)
98 }
99 })
100
101 after(async function () {
102 await closeAllSequelize(servers)
103
104 await cleanupTests(servers)
105 })
106 })