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