aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/redundancy/manage-redundancy.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/redundancy/manage-redundancy.ts')
-rw-r--r--server/tests/api/redundancy/manage-redundancy.ts165
1 files changed, 56 insertions, 109 deletions
diff --git a/server/tests/api/redundancy/manage-redundancy.ts b/server/tests/api/redundancy/manage-redundancy.ts
index 4253124c8..363e4cbfe 100644
--- a/server/tests/api/redundancy/manage-redundancy.ts
+++ b/server/tests/api/redundancy/manage-redundancy.ts
@@ -1,21 +1,21 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import * as chai from 'chai'
4import 'mocha' 3import 'mocha'
4import * as chai from 'chai'
5import { 5import {
6 cleanupTests, 6 cleanupTests,
7 doubleFollow, 7 doubleFollow,
8 flushAndRunMultipleServers, 8 flushAndRunMultipleServers,
9 getLocalIdByUUID, 9 getLocalIdByUUID,
10 RedundancyCommand,
10 ServerInfo, 11 ServerInfo,
11 setAccessTokensToServers, 12 setAccessTokensToServers,
12 uploadVideo, 13 uploadVideo,
13 uploadVideoAndGetId, 14 uploadVideoAndGetId,
15 waitJobs,
14 waitUntilLog 16 waitUntilLog
15} from '../../../../shared/extra-utils' 17} from '@shared/extra-utils'
16import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 18import { VideoPrivacy, VideoRedundanciesTarget } from '@shared/models'
17import { addVideoRedundancy, listVideoRedundancies, removeVideoRedundancy, updateRedundancy } from '@shared/extra-utils/server/redundancy'
18import { VideoPrivacy, VideoRedundanciesTarget, VideoRedundancy } from '@shared/models'
19 19
20const expect = chai.expect 20const expect = chai.expect
21 21
@@ -27,6 +27,8 @@ describe('Test manage videos redundancy', function () {
27 let video2Server2UUID: string 27 let video2Server2UUID: string
28 let redundanciesToRemove: number[] = [] 28 let redundanciesToRemove: number[] = []
29 29
30 let commands: RedundancyCommand[]
31
30 before(async function () { 32 before(async function () {
31 this.timeout(120000) 33 this.timeout(120000)
32 34
@@ -55,6 +57,8 @@ describe('Test manage videos redundancy', function () {
55 // Get the access tokens 57 // Get the access tokens
56 await setAccessTokensToServers(servers) 58 await setAccessTokensToServers(servers)
57 59
60 commands = servers.map(s => s.redundancyCommand)
61
58 { 62 {
59 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' }) 63 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' })
60 video1Server2UUID = res.body.video.uuid 64 video1Server2UUID = res.body.video.uuid
@@ -69,21 +73,17 @@ describe('Test manage videos redundancy', function () {
69 73
70 // Server 1 and server 2 follow each other 74 // Server 1 and server 2 follow each other
71 await doubleFollow(servers[0], servers[1]) 75 await doubleFollow(servers[0], servers[1])
72 await updateRedundancy(servers[0].url, servers[0].accessToken, servers[1].host, true) 76 await commands[0].updateRedundancy({ host: servers[1].host, redundancyAllowed: true })
73 77
74 await waitJobs(servers) 78 await waitJobs(servers)
75 }) 79 })
76 80
77 it('Should not have redundancies on server 3', async function () { 81 it('Should not have redundancies on server 3', async function () {
78 for (const target of targets) { 82 for (const target of targets) {
79 const res = await listVideoRedundancies({ 83 const body = await commands[2].listVideos({ target })
80 url: servers[2].url,
81 accessToken: servers[2].accessToken,
82 target
83 })
84 84
85 expect(res.body.total).to.equal(0) 85 expect(body.total).to.equal(0)
86 expect(res.body.data).to.have.lengthOf(0) 86 expect(body.data).to.have.lengthOf(0)
87 } 87 }
88 }) 88 })
89 89
@@ -94,28 +94,19 @@ describe('Test manage videos redundancy', function () {
94 await waitUntilLog(servers[0], 'Duplicated ', 10) 94 await waitUntilLog(servers[0], 'Duplicated ', 10)
95 await waitJobs(servers) 95 await waitJobs(servers)
96 96
97 const res = await listVideoRedundancies({ 97 const body = await commands[1].listVideos({ target: 'remote-videos' })
98 url: servers[1].url,
99 accessToken: servers[1].accessToken,
100 target: 'remote-videos'
101 })
102 98
103 expect(res.body.total).to.equal(0) 99 expect(body.total).to.equal(0)
104 expect(res.body.data).to.have.lengthOf(0) 100 expect(body.data).to.have.lengthOf(0)
105 }) 101 })
106 102
107 it('Should have "my-videos" redundancies on server 2', async function () { 103 it('Should have "my-videos" redundancies on server 2', async function () {
108 this.timeout(120000) 104 this.timeout(120000)
109 105
110 const res = await listVideoRedundancies({ 106 const body = await commands[1].listVideos({ target: 'my-videos' })
111 url: servers[1].url, 107 expect(body.total).to.equal(2)
112 accessToken: servers[1].accessToken,
113 target: 'my-videos'
114 })
115
116 expect(res.body.total).to.equal(2)
117 108
118 const videos = res.body.data as VideoRedundancy[] 109 const videos = body.data
119 expect(videos).to.have.lengthOf(2) 110 expect(videos).to.have.lengthOf(2)
120 111
121 const videos1 = videos.find(v => v.uuid === video1Server2UUID) 112 const videos1 = videos.find(v => v.uuid === video1Server2UUID)
@@ -139,28 +130,19 @@ describe('Test manage videos redundancy', function () {
139 }) 130 })
140 131
141 it('Should not have "my-videos" redundancies on server 1', async function () { 132 it('Should not have "my-videos" redundancies on server 1', async function () {
142 const res = await listVideoRedundancies({ 133 const body = await commands[0].listVideos({ target: 'my-videos' })
143 url: servers[0].url,
144 accessToken: servers[0].accessToken,
145 target: 'my-videos'
146 })
147 134
148 expect(res.body.total).to.equal(0) 135 expect(body.total).to.equal(0)
149 expect(res.body.data).to.have.lengthOf(0) 136 expect(body.data).to.have.lengthOf(0)
150 }) 137 })
151 138
152 it('Should have "remote-videos" redundancies on server 1', async function () { 139 it('Should have "remote-videos" redundancies on server 1', async function () {
153 this.timeout(120000) 140 this.timeout(120000)
154 141
155 const res = await listVideoRedundancies({ 142 const body = await commands[0].listVideos({ target: 'remote-videos' })
156 url: servers[0].url, 143 expect(body.total).to.equal(2)
157 accessToken: servers[0].accessToken,
158 target: 'remote-videos'
159 })
160 144
161 expect(res.body.total).to.equal(2) 145 const videos = body.data
162
163 const videos = res.body.data as VideoRedundancy[]
164 expect(videos).to.have.lengthOf(2) 146 expect(videos).to.have.lengthOf(2)
165 147
166 const videos1 = videos.find(v => v.uuid === video1Server2UUID) 148 const videos1 = videos.find(v => v.uuid === video1Server2UUID)
@@ -185,47 +167,40 @@ describe('Test manage videos redundancy', function () {
185 167
186 it('Should correctly paginate and sort results', async function () { 168 it('Should correctly paginate and sort results', async function () {
187 { 169 {
188 const res = await listVideoRedundancies({ 170 const body = await commands[0].listVideos({
189 url: servers[0].url,
190 accessToken: servers[0].accessToken,
191 target: 'remote-videos', 171 target: 'remote-videos',
192 sort: 'name', 172 sort: 'name',
193 start: 0, 173 start: 0,
194 count: 2 174 count: 2
195 }) 175 })
196 176
197 const videos = res.body.data 177 const videos = body.data
198 expect(videos[0].name).to.equal('video 1 server 2') 178 expect(videos[0].name).to.equal('video 1 server 2')
199 expect(videos[1].name).to.equal('video 2 server 2') 179 expect(videos[1].name).to.equal('video 2 server 2')
200 } 180 }
201 181
202 { 182 {
203 const res = await listVideoRedundancies({ 183 const body = await commands[0].listVideos({
204 url: servers[0].url,
205 accessToken: servers[0].accessToken,
206 target: 'remote-videos', 184 target: 'remote-videos',
207 sort: '-name', 185 sort: '-name',
208 start: 0, 186 start: 0,
209 count: 2 187 count: 2
210 }) 188 })
211 189
212 const videos = res.body.data 190 const videos = body.data
213 expect(videos[0].name).to.equal('video 2 server 2') 191 expect(videos[0].name).to.equal('video 2 server 2')
214 expect(videos[1].name).to.equal('video 1 server 2') 192 expect(videos[1].name).to.equal('video 1 server 2')
215 } 193 }
216 194
217 { 195 {
218 const res = await listVideoRedundancies({ 196 const body = await commands[0].listVideos({
219 url: servers[0].url,
220 accessToken: servers[0].accessToken,
221 target: 'remote-videos', 197 target: 'remote-videos',
222 sort: '-name', 198 sort: '-name',
223 start: 1, 199 start: 1,
224 count: 1 200 count: 1
225 }) 201 })
226 202
227 const videos = res.body.data 203 expect(body.data[0].name).to.equal('video 1 server 2')
228 expect(videos[0].name).to.equal('video 1 server 2')
229 } 204 }
230 }) 205 })
231 206
@@ -236,30 +211,23 @@ describe('Test manage videos redundancy', function () {
236 await waitJobs(servers) 211 await waitJobs(servers)
237 const videoId = await getLocalIdByUUID(servers[0].url, uuid) 212 const videoId = await getLocalIdByUUID(servers[0].url, uuid)
238 213
239 await addVideoRedundancy({ 214 await commands[0].addVideo({ videoId })
240 url: servers[0].url,
241 accessToken: servers[0].accessToken,
242 videoId
243 })
244 215
245 await waitJobs(servers) 216 await waitJobs(servers)
246 await waitUntilLog(servers[0], 'Duplicated ', 15) 217 await waitUntilLog(servers[0], 'Duplicated ', 15)
247 await waitJobs(servers) 218 await waitJobs(servers)
248 219
249 { 220 {
250 const res = await listVideoRedundancies({ 221 const body = await commands[0].listVideos({
251 url: servers[0].url,
252 accessToken: servers[0].accessToken,
253 target: 'remote-videos', 222 target: 'remote-videos',
254 sort: '-name', 223 sort: '-name',
255 start: 0, 224 start: 0,
256 count: 5 225 count: 5
257 }) 226 })
258 227
259 const videos = res.body.data 228 const video = body.data[0]
260 expect(videos[0].name).to.equal('video 3 server 2')
261 229
262 const video = videos[0] 230 expect(video.name).to.equal('video 3 server 2')
263 expect(video.redundancies.files).to.have.lengthOf(4) 231 expect(video.redundancies.files).to.have.lengthOf(4)
264 expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1) 232 expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1)
265 233
@@ -276,19 +244,15 @@ describe('Test manage videos redundancy', function () {
276 } 244 }
277 } 245 }
278 246
279 const res = await listVideoRedundancies({ 247 const body = await commands[1].listVideos({
280 url: servers[1].url,
281 accessToken: servers[1].accessToken,
282 target: 'my-videos', 248 target: 'my-videos',
283 sort: '-name', 249 sort: '-name',
284 start: 0, 250 start: 0,
285 count: 5 251 count: 5
286 }) 252 })
287 253
288 const videos = res.body.data 254 const video = body.data[0]
289 expect(videos[0].name).to.equal('video 3 server 2') 255 expect(video.name).to.equal('video 3 server 2')
290
291 const video = videos[0]
292 expect(video.redundancies.files).to.have.lengthOf(4) 256 expect(video.redundancies.files).to.have.lengthOf(4)
293 expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1) 257 expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1)
294 258
@@ -307,64 +271,47 @@ describe('Test manage videos redundancy', function () {
307 this.timeout(120000) 271 this.timeout(120000)
308 272
309 for (const redundancyId of redundanciesToRemove) { 273 for (const redundancyId of redundanciesToRemove) {
310 await removeVideoRedundancy({ 274 await commands[0].removeVideo({ redundancyId })
311 url: servers[0].url,
312 accessToken: servers[0].accessToken,
313 redundancyId
314 })
315 } 275 }
316 276
317 { 277 {
318 const res = await listVideoRedundancies({ 278 const body = await commands[0].listVideos({
319 url: servers[0].url,
320 accessToken: servers[0].accessToken,
321 target: 'remote-videos', 279 target: 'remote-videos',
322 sort: '-name', 280 sort: '-name',
323 start: 0, 281 start: 0,
324 count: 5 282 count: 5
325 }) 283 })
326 284
327 const videos = res.body.data 285 const videos = body.data
328 expect(videos).to.have.lengthOf(2)
329 286
330 expect(videos[0].name).to.equal('video 2 server 2') 287 expect(videos).to.have.lengthOf(2)
331 288
332 redundanciesToRemove = []
333 const video = videos[0] 289 const video = videos[0]
290 expect(video.name).to.equal('video 2 server 2')
334 expect(video.redundancies.files).to.have.lengthOf(4) 291 expect(video.redundancies.files).to.have.lengthOf(4)
335 expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1) 292 expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1)
336 293
337 const redundancies = video.redundancies.files.concat(video.redundancies.streamingPlaylists) 294 const redundancies = video.redundancies.files.concat(video.redundancies.streamingPlaylists)
338 295
339 for (const r of redundancies) { 296 redundanciesToRemove = redundancies.map(r => r.id)
340 redundanciesToRemove.push(r.id)
341 }
342 } 297 }
343 }) 298 })
344 299
345 it('Should remove another (auto) redundancy', async function () { 300 it('Should remove another (auto) redundancy', async function () {
346 { 301 for (const redundancyId of redundanciesToRemove) {
347 for (const redundancyId of redundanciesToRemove) { 302 await commands[0].removeVideo({ redundancyId })
348 await removeVideoRedundancy({ 303 }
349 url: servers[0].url,
350 accessToken: servers[0].accessToken,
351 redundancyId
352 })
353 }
354 304
355 const res = await listVideoRedundancies({ 305 const body = await commands[0].listVideos({
356 url: servers[0].url, 306 target: 'remote-videos',
357 accessToken: servers[0].accessToken, 307 sort: '-name',
358 target: 'remote-videos', 308 start: 0,
359 sort: '-name', 309 count: 5
360 start: 0, 310 })
361 count: 5
362 })
363 311
364 const videos = res.body.data 312 const videos = body.data
365 expect(videos[0].name).to.equal('video 1 server 2') 313 expect(videos).to.have.lengthOf(1)
366 expect(videos).to.have.lengthOf(1) 314 expect(videos[0].name).to.equal('video 1 server 2')
367 }
368 }) 315 })
369 316
370 after(async function () { 317 after(async function () {