diff options
author | Chocobozzz <me@florianbigard.com> | 2019-04-11 17:33:36 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-04-12 08:31:06 +0200 |
commit | cda03765fe366f028897e9b02dd4a0a19af3c935 (patch) | |
tree | 4d30303d76f8fd171195a51b1f737a0067987d6c /server/tests | |
parent | 7b293f28686319242958dff7315cdd8ad74fc15e (diff) | |
download | PeerTube-cda03765fe366f028897e9b02dd4a0a19af3c935.tar.gz PeerTube-cda03765fe366f028897e9b02dd4a0a19af3c935.tar.zst PeerTube-cda03765fe366f028897e9b02dd4a0a19af3c935.zip |
Add ability to delete old remote views
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/api/videos/index.ts | 1 | ||||
-rw-r--r-- | server/tests/api/videos/videos-views-cleaner.ts | 113 |
2 files changed, 114 insertions, 0 deletions
diff --git a/server/tests/api/videos/index.ts b/server/tests/api/videos/index.ts index 4be12ad15..93e1f3e98 100644 --- a/server/tests/api/videos/index.ts +++ b/server/tests/api/videos/index.ts | |||
@@ -18,3 +18,4 @@ import './video-transcoder' | |||
18 | import './videos-filter' | 18 | import './videos-filter' |
19 | import './videos-history' | 19 | import './videos-history' |
20 | import './videos-overview' | 20 | import './videos-overview' |
21 | import './videos-views-cleaner' | ||
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 | |||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | ||
5 | import { | ||
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' | ||
15 | import { getVideosOverview } from '../../../../shared/utils/overviews/overviews' | ||
16 | import { VideosOverview } from '../../../../shared/models/overviews' | ||
17 | import { listMyVideosHistory } from '../../../../shared/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 | 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 | }) | ||