diff options
author | Chocobozzz <me@florianbigard.com> | 2023-08-17 08:59:21 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-08-17 08:59:21 +0200 |
commit | c380e3928517eb5311b38cf257816642617d7a33 (patch) | |
tree | 2ea9b70ebca16b5d109bcce98fe7f944dad89319 /packages/tests/src/api/redundancy/redundancy-constraints.ts | |
parent | a8ca6190fb462bf6eb5685cfc1d8ae444164a487 (diff) | |
parent | 3a4992633ee62d5edfbb484d9c6bcb3cf158489d (diff) | |
download | PeerTube-c380e3928517eb5311b38cf257816642617d7a33.tar.gz PeerTube-c380e3928517eb5311b38cf257816642617d7a33.tar.zst PeerTube-c380e3928517eb5311b38cf257816642617d7a33.zip |
Merge branch 'feature/esm-and-nx' into develop
Diffstat (limited to 'packages/tests/src/api/redundancy/redundancy-constraints.ts')
-rw-r--r-- | packages/tests/src/api/redundancy/redundancy-constraints.ts | 191 |
1 files changed, 191 insertions, 0 deletions
diff --git a/packages/tests/src/api/redundancy/redundancy-constraints.ts b/packages/tests/src/api/redundancy/redundancy-constraints.ts new file mode 100644 index 000000000..24966b270 --- /dev/null +++ b/packages/tests/src/api/redundancy/redundancy-constraints.ts | |||
@@ -0,0 +1,191 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { VideoPrivacy } from '@peertube/peertube-models' | ||
5 | import { | ||
6 | cleanupTests, | ||
7 | createSingleServer, | ||
8 | killallServers, | ||
9 | PeerTubeServer, | ||
10 | setAccessTokensToServers, | ||
11 | waitJobs | ||
12 | } from '@peertube/peertube-server-commands' | ||
13 | |||
14 | describe('Test redundancy constraints', function () { | ||
15 | let remoteServer: PeerTubeServer | ||
16 | let localServer: PeerTubeServer | ||
17 | let servers: PeerTubeServer[] | ||
18 | |||
19 | const remoteServerConfig = { | ||
20 | redundancy: { | ||
21 | videos: { | ||
22 | check_interval: '1 second', | ||
23 | strategies: [ | ||
24 | { | ||
25 | strategy: 'recently-added', | ||
26 | min_lifetime: '1 hour', | ||
27 | size: '100MB', | ||
28 | min_views: 0 | ||
29 | } | ||
30 | ] | ||
31 | } | ||
32 | } | ||
33 | } | ||
34 | |||
35 | async function uploadWrapper (videoName: string) { | ||
36 | // Wait for transcoding | ||
37 | const { id } = await localServer.videos.upload({ attributes: { name: 'to transcode', privacy: VideoPrivacy.PRIVATE } }) | ||
38 | await waitJobs([ localServer ]) | ||
39 | |||
40 | // Update video to schedule a federation | ||
41 | await localServer.videos.update({ id, attributes: { name: videoName, privacy: VideoPrivacy.PUBLIC } }) | ||
42 | } | ||
43 | |||
44 | async function getTotalRedundanciesLocalServer () { | ||
45 | const body = await localServer.redundancy.listVideos({ target: 'my-videos' }) | ||
46 | |||
47 | return body.total | ||
48 | } | ||
49 | |||
50 | async function getTotalRedundanciesRemoteServer () { | ||
51 | const body = await remoteServer.redundancy.listVideos({ target: 'remote-videos' }) | ||
52 | |||
53 | return body.total | ||
54 | } | ||
55 | |||
56 | before(async function () { | ||
57 | this.timeout(120000) | ||
58 | |||
59 | { | ||
60 | remoteServer = await createSingleServer(1, remoteServerConfig) | ||
61 | } | ||
62 | |||
63 | { | ||
64 | const config = { | ||
65 | remote_redundancy: { | ||
66 | videos: { | ||
67 | accept_from: 'nobody' | ||
68 | } | ||
69 | } | ||
70 | } | ||
71 | localServer = await createSingleServer(2, config) | ||
72 | } | ||
73 | |||
74 | servers = [ remoteServer, localServer ] | ||
75 | |||
76 | // Get the access tokens | ||
77 | await setAccessTokensToServers(servers) | ||
78 | |||
79 | await localServer.videos.upload({ attributes: { name: 'video 1 server 2' } }) | ||
80 | |||
81 | await waitJobs(servers) | ||
82 | |||
83 | // Server 1 and server 2 follow each other | ||
84 | await remoteServer.follows.follow({ hosts: [ localServer.url ] }) | ||
85 | await waitJobs(servers) | ||
86 | await remoteServer.redundancy.updateRedundancy({ host: localServer.host, redundancyAllowed: true }) | ||
87 | |||
88 | await waitJobs(servers) | ||
89 | }) | ||
90 | |||
91 | it('Should have redundancy on server 1 but not on server 2 with a nobody filter', async function () { | ||
92 | this.timeout(120000) | ||
93 | |||
94 | await waitJobs(servers) | ||
95 | await remoteServer.servers.waitUntilLog('Duplicated ', 5) | ||
96 | await waitJobs(servers) | ||
97 | |||
98 | { | ||
99 | const total = await getTotalRedundanciesRemoteServer() | ||
100 | expect(total).to.equal(1) | ||
101 | } | ||
102 | |||
103 | { | ||
104 | const total = await getTotalRedundanciesLocalServer() | ||
105 | expect(total).to.equal(0) | ||
106 | } | ||
107 | }) | ||
108 | |||
109 | it('Should have redundancy on server 1 and on server 2 with an anybody filter', async function () { | ||
110 | this.timeout(120000) | ||
111 | |||
112 | const config = { | ||
113 | remote_redundancy: { | ||
114 | videos: { | ||
115 | accept_from: 'anybody' | ||
116 | } | ||
117 | } | ||
118 | } | ||
119 | await killallServers([ localServer ]) | ||
120 | await localServer.run(config) | ||
121 | |||
122 | await uploadWrapper('video 2 server 2') | ||
123 | |||
124 | await remoteServer.servers.waitUntilLog('Duplicated ', 10) | ||
125 | await waitJobs(servers) | ||
126 | |||
127 | { | ||
128 | const total = await getTotalRedundanciesRemoteServer() | ||
129 | expect(total).to.equal(2) | ||
130 | } | ||
131 | |||
132 | { | ||
133 | const total = await getTotalRedundanciesLocalServer() | ||
134 | expect(total).to.equal(1) | ||
135 | } | ||
136 | }) | ||
137 | |||
138 | it('Should have redundancy on server 1 but not on server 2 with a followings filter', async function () { | ||
139 | this.timeout(120000) | ||
140 | |||
141 | const config = { | ||
142 | remote_redundancy: { | ||
143 | videos: { | ||
144 | accept_from: 'followings' | ||
145 | } | ||
146 | } | ||
147 | } | ||
148 | await killallServers([ localServer ]) | ||
149 | await localServer.run(config) | ||
150 | |||
151 | await uploadWrapper('video 3 server 2') | ||
152 | |||
153 | await remoteServer.servers.waitUntilLog('Duplicated ', 15) | ||
154 | await waitJobs(servers) | ||
155 | |||
156 | { | ||
157 | const total = await getTotalRedundanciesRemoteServer() | ||
158 | expect(total).to.equal(3) | ||
159 | } | ||
160 | |||
161 | { | ||
162 | const total = await getTotalRedundanciesLocalServer() | ||
163 | expect(total).to.equal(1) | ||
164 | } | ||
165 | }) | ||
166 | |||
167 | it('Should have redundancy on server 1 and on server 2 with followings filter now server 2 follows server 1', async function () { | ||
168 | this.timeout(120000) | ||
169 | |||
170 | await localServer.follows.follow({ hosts: [ remoteServer.url ] }) | ||
171 | await waitJobs(servers) | ||
172 | |||
173 | await uploadWrapper('video 4 server 2') | ||
174 | await remoteServer.servers.waitUntilLog('Duplicated ', 20) | ||
175 | await waitJobs(servers) | ||
176 | |||
177 | { | ||
178 | const total = await getTotalRedundanciesRemoteServer() | ||
179 | expect(total).to.equal(4) | ||
180 | } | ||
181 | |||
182 | { | ||
183 | const total = await getTotalRedundanciesLocalServer() | ||
184 | expect(total).to.equal(2) | ||
185 | } | ||
186 | }) | ||
187 | |||
188 | after(async function () { | ||
189 | await cleanupTests(servers) | ||
190 | }) | ||
191 | }) | ||