]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
b764380a | 2 | |
b764380a | 3 | import 'mocha' |
dab04709 | 4 | import * as chai from 'chai' |
b764380a C |
5 | import { |
6 | cleanupTests, | |
254d3579 | 7 | createMultipleServers, |
4c7e60bc | 8 | doubleFollow, |
254d3579 | 9 | PeerTubeServer, |
4c7e60bc | 10 | RedundancyCommand, |
b764380a | 11 | setAccessTokensToServers, |
6c5065a0 | 12 | waitJobs |
dab04709 C |
13 | } from '@shared/extra-utils' |
14 | import { VideoPrivacy, VideoRedundanciesTarget } from '@shared/models' | |
b764380a C |
15 | |
16 | const expect = chai.expect | |
17 | ||
18 | describe('Test manage videos redundancy', function () { | |
19 | const targets: VideoRedundanciesTarget[] = [ 'my-videos', 'remote-videos' ] | |
20 | ||
254d3579 | 21 | let servers: PeerTubeServer[] |
b764380a C |
22 | let video1Server2UUID: string |
23 | let video2Server2UUID: string | |
24 | let redundanciesToRemove: number[] = [] | |
25 | ||
dab04709 C |
26 | let commands: RedundancyCommand[] |
27 | ||
b764380a C |
28 | before(async function () { |
29 | this.timeout(120000) | |
30 | ||
31 | const config = { | |
32 | transcoding: { | |
33 | hls: { | |
34 | enabled: true | |
35 | } | |
36 | }, | |
37 | redundancy: { | |
38 | videos: { | |
39 | check_interval: '1 second', | |
40 | strategies: [ | |
41 | { | |
42 | strategy: 'recently-added', | |
43 | min_lifetime: '1 hour', | |
44 | size: '10MB', | |
45 | min_views: 0 | |
46 | } | |
47 | ] | |
48 | } | |
49 | } | |
50 | } | |
254d3579 | 51 | servers = await createMultipleServers(3, config) |
b764380a C |
52 | |
53 | // Get the access tokens | |
54 | await setAccessTokensToServers(servers) | |
55 | ||
89d241a7 | 56 | commands = servers.map(s => s.redundancy) |
dab04709 | 57 | |
b764380a | 58 | { |
89d241a7 | 59 | const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video 1 server 2' } }) |
d23dd9fb | 60 | video1Server2UUID = uuid |
b764380a C |
61 | } |
62 | ||
63 | { | |
89d241a7 | 64 | const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video 2 server 2' } }) |
d23dd9fb | 65 | video2Server2UUID = uuid |
b764380a C |
66 | } |
67 | ||
68 | await waitJobs(servers) | |
69 | ||
70 | // Server 1 and server 2 follow each other | |
a1587156 | 71 | await doubleFollow(servers[0], servers[1]) |
dab04709 | 72 | await commands[0].updateRedundancy({ host: servers[1].host, redundancyAllowed: true }) |
b764380a C |
73 | |
74 | await waitJobs(servers) | |
75 | }) | |
76 | ||
77 | it('Should not have redundancies on server 3', async function () { | |
78 | for (const target of targets) { | |
dab04709 | 79 | const body = await commands[2].listVideos({ target }) |
b764380a | 80 | |
dab04709 C |
81 | expect(body.total).to.equal(0) |
82 | expect(body.data).to.have.lengthOf(0) | |
b764380a C |
83 | } |
84 | }) | |
85 | ||
86 | it('Should not have "remote-videos" redundancies on server 2', async function () { | |
87 | this.timeout(120000) | |
88 | ||
89 | await waitJobs(servers) | |
89d241a7 | 90 | await servers[0].servers.waitUntilLog('Duplicated ', 10) |
b764380a C |
91 | await waitJobs(servers) |
92 | ||
dab04709 | 93 | const body = await commands[1].listVideos({ target: 'remote-videos' }) |
b764380a | 94 | |
dab04709 C |
95 | expect(body.total).to.equal(0) |
96 | expect(body.data).to.have.lengthOf(0) | |
b764380a C |
97 | }) |
98 | ||
99 | it('Should have "my-videos" redundancies on server 2', async function () { | |
100 | this.timeout(120000) | |
101 | ||
dab04709 C |
102 | const body = await commands[1].listVideos({ target: 'my-videos' }) |
103 | expect(body.total).to.equal(2) | |
b764380a | 104 | |
dab04709 | 105 | const videos = body.data |
b764380a C |
106 | expect(videos).to.have.lengthOf(2) |
107 | ||
108 | const videos1 = videos.find(v => v.uuid === video1Server2UUID) | |
109 | const videos2 = videos.find(v => v.uuid === video2Server2UUID) | |
110 | ||
111 | expect(videos1.name).to.equal('video 1 server 2') | |
112 | expect(videos2.name).to.equal('video 2 server 2') | |
113 | ||
114 | expect(videos1.redundancies.files).to.have.lengthOf(4) | |
115 | expect(videos1.redundancies.streamingPlaylists).to.have.lengthOf(1) | |
116 | ||
117 | const redundancies = videos1.redundancies.files.concat(videos1.redundancies.streamingPlaylists) | |
118 | ||
119 | for (const r of redundancies) { | |
120 | expect(r.strategy).to.be.null | |
121 | expect(r.fileUrl).to.exist | |
122 | expect(r.createdAt).to.exist | |
123 | expect(r.updatedAt).to.exist | |
124 | expect(r.expiresOn).to.exist | |
125 | } | |
126 | }) | |
127 | ||
128 | it('Should not have "my-videos" redundancies on server 1', async function () { | |
dab04709 | 129 | const body = await commands[0].listVideos({ target: 'my-videos' }) |
b764380a | 130 | |
dab04709 C |
131 | expect(body.total).to.equal(0) |
132 | expect(body.data).to.have.lengthOf(0) | |
b764380a C |
133 | }) |
134 | ||
135 | it('Should have "remote-videos" redundancies on server 1', async function () { | |
136 | this.timeout(120000) | |
137 | ||
dab04709 C |
138 | const body = await commands[0].listVideos({ target: 'remote-videos' }) |
139 | expect(body.total).to.equal(2) | |
b764380a | 140 | |
dab04709 | 141 | const videos = body.data |
b764380a C |
142 | expect(videos).to.have.lengthOf(2) |
143 | ||
144 | const videos1 = videos.find(v => v.uuid === video1Server2UUID) | |
145 | const videos2 = videos.find(v => v.uuid === video2Server2UUID) | |
146 | ||
147 | expect(videos1.name).to.equal('video 1 server 2') | |
148 | expect(videos2.name).to.equal('video 2 server 2') | |
149 | ||
150 | expect(videos1.redundancies.files).to.have.lengthOf(4) | |
151 | expect(videos1.redundancies.streamingPlaylists).to.have.lengthOf(1) | |
152 | ||
153 | const redundancies = videos1.redundancies.files.concat(videos1.redundancies.streamingPlaylists) | |
154 | ||
155 | for (const r of redundancies) { | |
156 | expect(r.strategy).to.equal('recently-added') | |
157 | expect(r.fileUrl).to.exist | |
158 | expect(r.createdAt).to.exist | |
159 | expect(r.updatedAt).to.exist | |
160 | expect(r.expiresOn).to.exist | |
161 | } | |
162 | }) | |
163 | ||
164 | it('Should correctly paginate and sort results', async function () { | |
165 | { | |
dab04709 | 166 | const body = await commands[0].listVideos({ |
b764380a C |
167 | target: 'remote-videos', |
168 | sort: 'name', | |
169 | start: 0, | |
170 | count: 2 | |
171 | }) | |
172 | ||
dab04709 | 173 | const videos = body.data |
a1587156 C |
174 | expect(videos[0].name).to.equal('video 1 server 2') |
175 | expect(videos[1].name).to.equal('video 2 server 2') | |
b764380a C |
176 | } |
177 | ||
178 | { | |
dab04709 | 179 | const body = await commands[0].listVideos({ |
b764380a C |
180 | target: 'remote-videos', |
181 | sort: '-name', | |
182 | start: 0, | |
183 | count: 2 | |
184 | }) | |
185 | ||
dab04709 | 186 | const videos = body.data |
a1587156 C |
187 | expect(videos[0].name).to.equal('video 2 server 2') |
188 | expect(videos[1].name).to.equal('video 1 server 2') | |
b764380a C |
189 | } |
190 | ||
191 | { | |
dab04709 | 192 | const body = await commands[0].listVideos({ |
b764380a C |
193 | target: 'remote-videos', |
194 | sort: '-name', | |
195 | start: 1, | |
196 | count: 1 | |
197 | }) | |
198 | ||
dab04709 | 199 | expect(body.data[0].name).to.equal('video 1 server 2') |
b764380a C |
200 | } |
201 | }) | |
202 | ||
203 | it('Should manually add a redundancy and list it', async function () { | |
204 | this.timeout(120000) | |
205 | ||
89d241a7 | 206 | const uuid = (await servers[1].videos.quickUpload({ name: 'video 3 server 2', privacy: VideoPrivacy.UNLISTED })).uuid |
b764380a | 207 | await waitJobs(servers) |
89d241a7 | 208 | const videoId = await servers[0].videos.getId({ uuid }) |
b764380a | 209 | |
dab04709 | 210 | await commands[0].addVideo({ videoId }) |
b764380a C |
211 | |
212 | await waitJobs(servers) | |
89d241a7 | 213 | await servers[0].servers.waitUntilLog('Duplicated ', 15) |
b764380a C |
214 | await waitJobs(servers) |
215 | ||
216 | { | |
dab04709 | 217 | const body = await commands[0].listVideos({ |
b764380a C |
218 | target: 'remote-videos', |
219 | sort: '-name', | |
220 | start: 0, | |
221 | count: 5 | |
222 | }) | |
223 | ||
dab04709 | 224 | const video = body.data[0] |
b764380a | 225 | |
dab04709 | 226 | expect(video.name).to.equal('video 3 server 2') |
b764380a C |
227 | expect(video.redundancies.files).to.have.lengthOf(4) |
228 | expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1) | |
229 | ||
230 | const redundancies = video.redundancies.files.concat(video.redundancies.streamingPlaylists) | |
231 | ||
232 | for (const r of redundancies) { | |
233 | redundanciesToRemove.push(r.id) | |
234 | ||
235 | expect(r.strategy).to.equal('manual') | |
236 | expect(r.fileUrl).to.exist | |
237 | expect(r.createdAt).to.exist | |
238 | expect(r.updatedAt).to.exist | |
239 | expect(r.expiresOn).to.be.null | |
240 | } | |
241 | } | |
242 | ||
dab04709 | 243 | const body = await commands[1].listVideos({ |
b764380a C |
244 | target: 'my-videos', |
245 | sort: '-name', | |
246 | start: 0, | |
247 | count: 5 | |
248 | }) | |
249 | ||
dab04709 C |
250 | const video = body.data[0] |
251 | expect(video.name).to.equal('video 3 server 2') | |
b764380a C |
252 | expect(video.redundancies.files).to.have.lengthOf(4) |
253 | expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1) | |
254 | ||
255 | const redundancies = video.redundancies.files.concat(video.redundancies.streamingPlaylists) | |
256 | ||
257 | for (const r of redundancies) { | |
258 | expect(r.strategy).to.be.null | |
259 | expect(r.fileUrl).to.exist | |
260 | expect(r.createdAt).to.exist | |
261 | expect(r.updatedAt).to.exist | |
262 | expect(r.expiresOn).to.be.null | |
263 | } | |
264 | }) | |
265 | ||
266 | it('Should manually remove a redundancy and remove it from the list', async function () { | |
267 | this.timeout(120000) | |
268 | ||
269 | for (const redundancyId of redundanciesToRemove) { | |
dab04709 | 270 | await commands[0].removeVideo({ redundancyId }) |
b764380a C |
271 | } |
272 | ||
273 | { | |
dab04709 | 274 | const body = await commands[0].listVideos({ |
b764380a C |
275 | target: 'remote-videos', |
276 | sort: '-name', | |
277 | start: 0, | |
278 | count: 5 | |
279 | }) | |
280 | ||
dab04709 | 281 | const videos = body.data |
b764380a | 282 | |
dab04709 | 283 | expect(videos).to.have.lengthOf(2) |
b764380a | 284 | |
a1587156 | 285 | const video = videos[0] |
dab04709 | 286 | expect(video.name).to.equal('video 2 server 2') |
b764380a C |
287 | expect(video.redundancies.files).to.have.lengthOf(4) |
288 | expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1) | |
289 | ||
290 | const redundancies = video.redundancies.files.concat(video.redundancies.streamingPlaylists) | |
291 | ||
dab04709 | 292 | redundanciesToRemove = redundancies.map(r => r.id) |
b764380a C |
293 | } |
294 | }) | |
295 | ||
296 | it('Should remove another (auto) redundancy', async function () { | |
dab04709 C |
297 | for (const redundancyId of redundanciesToRemove) { |
298 | await commands[0].removeVideo({ redundancyId }) | |
299 | } | |
b764380a | 300 | |
dab04709 C |
301 | const body = await commands[0].listVideos({ |
302 | target: 'remote-videos', | |
303 | sort: '-name', | |
304 | start: 0, | |
305 | count: 5 | |
306 | }) | |
b764380a | 307 | |
dab04709 C |
308 | const videos = body.data |
309 | expect(videos).to.have.lengthOf(1) | |
310 | expect(videos[0].name).to.equal('video 1 server 2') | |
b764380a C |
311 | }) |
312 | ||
313 | after(async function () { | |
314 | await cleanupTests(servers) | |
315 | }) | |
316 | }) |