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