aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/videos/videos-views-cleaner.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-04-11 17:33:36 +0200
committerChocobozzz <me@florianbigard.com>2019-04-12 08:31:06 +0200
commitcda03765fe366f028897e9b02dd4a0a19af3c935 (patch)
tree4d30303d76f8fd171195a51b1f737a0067987d6c /server/tests/api/videos/videos-views-cleaner.ts
parent7b293f28686319242958dff7315cdd8ad74fc15e (diff)
downloadPeerTube-cda03765fe366f028897e9b02dd4a0a19af3c935.tar.gz
PeerTube-cda03765fe366f028897e9b02dd4a0a19af3c935.tar.zst
PeerTube-cda03765fe366f028897e9b02dd4a0a19af3c935.zip
Add ability to delete old remote views
Diffstat (limited to 'server/tests/api/videos/videos-views-cleaner.ts')
-rw-r--r--server/tests/api/videos/videos-views-cleaner.ts113
1 files changed, 113 insertions, 0 deletions
diff --git a/server/tests/api/videos/videos-views-cleaner.ts b/server/tests/api/videos/videos-views-cleaner.ts
new file mode 100644
index 000000000..9f268c8e6
--- /dev/null
+++ b/server/tests/api/videos/videos-views-cleaner.ts
@@ -0,0 +1,113 @@
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5import {
6 flushAndRunMultipleServers,
7 flushTests,
8 killallServers,
9 reRunServer,
10 runServer,
11 ServerInfo,
12 setAccessTokensToServers,
13 uploadVideo, uploadVideoAndGetId, viewVideo, wait, countVideoViewsOf, doubleFollow, waitJobs
14} from '../../../../shared/utils'
15import { getVideosOverview } from '../../../../shared/utils/overviews/overviews'
16import { VideosOverview } from '../../../../shared/models/overviews'
17import { listMyVideosHistory } from '../../../../shared/utils/videos/video-history'
18
19const expect = chai.expect
20
21describe('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 await flushTests()
31
32 servers = await flushAndRunMultipleServers(2)
33 await setAccessTokensToServers(servers)
34
35 await doubleFollow(servers[0], servers[1])
36
37 videoIdServer1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })).uuid
38 videoIdServer2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })).uuid
39
40 await waitJobs(servers)
41
42 await viewVideo(servers[0].url, videoIdServer1)
43 await viewVideo(servers[1].url, videoIdServer1)
44 await viewVideo(servers[0].url, videoIdServer2)
45 await viewVideo(servers[1].url, videoIdServer2)
46
47 await waitJobs(servers)
48 })
49
50 it('Should not clean old video views', async function () {
51 this.timeout(50000)
52
53 killallServers([ servers[0] ])
54
55 await reRunServer(servers[0], { views: { videos: { remote: { max_age: '10 days' } } } })
56
57 await wait(6000)
58
59 // Should still have views
60
61 {
62 for (const server of servers) {
63 const total = await countVideoViewsOf(server.serverNumber, videoIdServer1)
64 expect(total).to.equal(2)
65 }
66 }
67
68 {
69 for (const server of servers) {
70 const total = await countVideoViewsOf(server.serverNumber, videoIdServer2)
71 expect(total).to.equal(2)
72 }
73 }
74 })
75
76 it('Should clean old video views', async function () {
77 this.timeout(50000)
78
79 this.timeout(50000)
80
81 killallServers([ servers[0] ])
82
83 await reRunServer(servers[0], { views: { videos: { remote: { max_age: '5 seconds' } } } })
84
85 await wait(6000)
86
87 // Should still have views
88
89 {
90 for (const server of servers) {
91 const total = await countVideoViewsOf(server.serverNumber, videoIdServer1)
92 expect(total).to.equal(2)
93 }
94 }
95
96 {
97 const totalServer1 = await countVideoViewsOf(servers[0].serverNumber, videoIdServer2)
98 expect(totalServer1).to.equal(0)
99
100 const totalServer2 = await countVideoViewsOf(servers[1].serverNumber, videoIdServer2)
101 expect(totalServer2).to.equal(2)
102 }
103 })
104
105 after(async function () {
106 killallServers(servers)
107
108 // Keep the logs if the test failed
109 if (this['ok']) {
110 await flushTests()
111 }
112 })
113})