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