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