]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/redundancy/manage-redundancy.ts
fixes video not played from defined parameters in embed service (#5023)
[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
b764380a 3import 'mocha'
dab04709 4import * as chai from 'chai'
b764380a
C
5import {
6 cleanupTests,
254d3579 7 createMultipleServers,
4c7e60bc 8 doubleFollow,
254d3579 9 PeerTubeServer,
4c7e60bc 10 RedundancyCommand,
b764380a 11 setAccessTokensToServers,
6c5065a0 12 waitJobs
bf54587a 13} from '@shared/server-commands'
dab04709 14import { VideoPrivacy, VideoRedundanciesTarget } from '@shared/models'
b764380a
C
15
16const expect = chai.expect
17
18describe('Test manage videos redundancy', function () {
19 const targets: VideoRedundanciesTarget[] = [ 'my-videos', 'remote-videos' ]
20
254d3579 21 let servers: PeerTubeServer[]
b764380a
C
22 let video1Server2UUID: string
23 let video2Server2UUID: string
24 let redundanciesToRemove: number[] = []
25
dab04709
C
26 let commands: RedundancyCommand[]
27
b764380a
C
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 }
254d3579 51 servers = await createMultipleServers(3, config)
b764380a
C
52
53 // Get the access tokens
54 await setAccessTokensToServers(servers)
55
89d241a7 56 commands = servers.map(s => s.redundancy)
dab04709 57
b764380a 58 {
89d241a7 59 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video 1 server 2' } })
d23dd9fb 60 video1Server2UUID = uuid
b764380a
C
61 }
62
63 {
89d241a7 64 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video 2 server 2' } })
d23dd9fb 65 video2Server2UUID = uuid
b764380a
C
66 }
67
68 await waitJobs(servers)
69
70 // Server 1 and server 2 follow each other
a1587156 71 await doubleFollow(servers[0], servers[1])
bae61627 72 await doubleFollow(servers[0], servers[2])
dab04709 73 await commands[0].updateRedundancy({ host: servers[1].host, redundancyAllowed: true })
b764380a
C
74
75 await waitJobs(servers)
76 })
77
78 it('Should not have redundancies on server 3', async function () {
79 for (const target of targets) {
dab04709 80 const body = await commands[2].listVideos({ target })
b764380a 81
dab04709
C
82 expect(body.total).to.equal(0)
83 expect(body.data).to.have.lengthOf(0)
b764380a
C
84 }
85 })
86
bae61627
C
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
b764380a
C
97 it('Should not have "remote-videos" redundancies on server 2', async function () {
98 this.timeout(120000)
99
100 await waitJobs(servers)
89d241a7 101 await servers[0].servers.waitUntilLog('Duplicated ', 10)
b764380a
C
102 await waitJobs(servers)
103
dab04709 104 const body = await commands[1].listVideos({ target: 'remote-videos' })
b764380a 105
dab04709
C
106 expect(body.total).to.equal(0)
107 expect(body.data).to.have.lengthOf(0)
b764380a
C
108 })
109
110 it('Should have "my-videos" redundancies on server 2', async function () {
111 this.timeout(120000)
112
dab04709
C
113 const body = await commands[1].listVideos({ target: 'my-videos' })
114 expect(body.total).to.equal(2)
b764380a 115
dab04709 116 const videos = body.data
b764380a
C
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 () {
dab04709 140 const body = await commands[0].listVideos({ target: 'my-videos' })
b764380a 141
dab04709
C
142 expect(body.total).to.equal(0)
143 expect(body.data).to.have.lengthOf(0)
b764380a
C
144 })
145
146 it('Should have "remote-videos" redundancies on server 1', async function () {
147 this.timeout(120000)
148
dab04709
C
149 const body = await commands[0].listVideos({ target: 'remote-videos' })
150 expect(body.total).to.equal(2)
b764380a 151
dab04709 152 const videos = body.data
b764380a
C
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 {
dab04709 177 const body = await commands[0].listVideos({
b764380a
C
178 target: 'remote-videos',
179 sort: 'name',
180 start: 0,
181 count: 2
182 })
183
dab04709 184 const videos = body.data
a1587156
C
185 expect(videos[0].name).to.equal('video 1 server 2')
186 expect(videos[1].name).to.equal('video 2 server 2')
b764380a
C
187 }
188
189 {
dab04709 190 const body = await commands[0].listVideos({
b764380a
C
191 target: 'remote-videos',
192 sort: '-name',
193 start: 0,
194 count: 2
195 })
196
dab04709 197 const videos = body.data
a1587156
C
198 expect(videos[0].name).to.equal('video 2 server 2')
199 expect(videos[1].name).to.equal('video 1 server 2')
b764380a
C
200 }
201
202 {
dab04709 203 const body = await commands[0].listVideos({
b764380a
C
204 target: 'remote-videos',
205 sort: '-name',
206 start: 1,
207 count: 1
208 })
209
dab04709 210 expect(body.data[0].name).to.equal('video 1 server 2')
b764380a
C
211 }
212 })
213
214 it('Should manually add a redundancy and list it', async function () {
215 this.timeout(120000)
216
89d241a7 217 const uuid = (await servers[1].videos.quickUpload({ name: 'video 3 server 2', privacy: VideoPrivacy.UNLISTED })).uuid
b764380a 218 await waitJobs(servers)
89d241a7 219 const videoId = await servers[0].videos.getId({ uuid })
b764380a 220
dab04709 221 await commands[0].addVideo({ videoId })
b764380a
C
222
223 await waitJobs(servers)
89d241a7 224 await servers[0].servers.waitUntilLog('Duplicated ', 15)
b764380a
C
225 await waitJobs(servers)
226
227 {
dab04709 228 const body = await commands[0].listVideos({
b764380a
C
229 target: 'remote-videos',
230 sort: '-name',
231 start: 0,
232 count: 5
233 })
234
dab04709 235 const video = body.data[0]
b764380a 236
dab04709 237 expect(video.name).to.equal('video 3 server 2')
b764380a
C
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
dab04709 254 const body = await commands[1].listVideos({
b764380a
C
255 target: 'my-videos',
256 sort: '-name',
257 start: 0,
258 count: 5
259 })
260
dab04709
C
261 const video = body.data[0]
262 expect(video.name).to.equal('video 3 server 2')
b764380a
C
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) {
dab04709 281 await commands[0].removeVideo({ redundancyId })
b764380a
C
282 }
283
284 {
dab04709 285 const body = await commands[0].listVideos({
b764380a
C
286 target: 'remote-videos',
287 sort: '-name',
288 start: 0,
289 count: 5
290 })
291
dab04709 292 const videos = body.data
b764380a 293
dab04709 294 expect(videos).to.have.lengthOf(2)
b764380a 295
a1587156 296 const video = videos[0]
dab04709 297 expect(video.name).to.equal('video 2 server 2')
b764380a
C
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
dab04709 303 redundanciesToRemove = redundancies.map(r => r.id)
b764380a
C
304 }
305 })
306
307 it('Should remove another (auto) redundancy', async function () {
dab04709
C
308 for (const redundancyId of redundanciesToRemove) {
309 await commands[0].removeVideo({ redundancyId })
310 }
b764380a 311
dab04709
C
312 const body = await commands[0].listVideos({
313 target: 'remote-videos',
314 sort: '-name',
315 start: 0,
316 count: 5
317 })
b764380a 318
dab04709
C
319 const videos = body.data
320 expect(videos).to.have.lengthOf(1)
321 expect(videos[0].name).to.equal('video 1 server 2')
b764380a
C
322 })
323
324 after(async function () {
325 await cleanupTests(servers)
326 })
327})