1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
8 flushAndRunMultipleServers,
11 setAccessTokensToServers,
15 } from '../../../../shared/extra-utils'
16 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
17 import { addVideoRedundancy, listVideoRedundancies, removeVideoRedundancy, updateRedundancy } from '@shared/extra-utils/server/redundancy'
18 import { VideoPrivacy, VideoRedundanciesTarget, VideoRedundancy } from '@shared/models'
20 const expect = chai.expect
22 describe('Test manage videos redundancy', function () {
23 const targets: VideoRedundanciesTarget[] = [ 'my-videos', 'remote-videos' ]
25 let servers: ServerInfo[]
26 let video1Server2UUID: string
27 let video2Server2UUID: string
28 let redundanciesToRemove: number[] = []
30 before(async function () {
41 check_interval: '1 second',
44 strategy: 'recently-added',
45 min_lifetime: '1 hour',
53 servers = await flushAndRunMultipleServers(3, config)
55 // Get the access tokens
56 await setAccessTokensToServers(servers)
59 const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, { name: 'video 1 server 2' })
60 video1Server2UUID = res.body.video.uuid
64 const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, { name: 'video 2 server 2' })
65 video2Server2UUID = res.body.video.uuid
68 await waitJobs(servers)
70 // Server 1 and server 2 follow each other
71 await doubleFollow(servers[ 0 ], servers[ 1 ])
72 await updateRedundancy(servers[ 0 ].url, servers[ 0 ].accessToken, servers[ 1 ].host, true)
74 await waitJobs(servers)
77 it('Should not have redundancies on server 3', async function () {
78 for (const target of targets) {
79 const res = await listVideoRedundancies({
81 accessToken: servers[2].accessToken,
85 expect(res.body.total).to.equal(0)
86 expect(res.body.data).to.have.lengthOf(0)
90 it('Should not have "remote-videos" redundancies on server 2', async function () {
93 await waitJobs(servers)
94 await waitUntilLog(servers[0], 'Duplicated ', 10)
95 await waitJobs(servers)
97 const res = await listVideoRedundancies({
99 accessToken: servers[1].accessToken,
100 target: 'remote-videos'
103 expect(res.body.total).to.equal(0)
104 expect(res.body.data).to.have.lengthOf(0)
107 it('Should have "my-videos" redundancies on server 2', async function () {
110 const res = await listVideoRedundancies({
112 accessToken: servers[1].accessToken,
116 expect(res.body.total).to.equal(2)
118 const videos = res.body.data as VideoRedundancy[]
119 expect(videos).to.have.lengthOf(2)
121 const videos1 = videos.find(v => v.uuid === video1Server2UUID)
122 const videos2 = videos.find(v => v.uuid === video2Server2UUID)
124 expect(videos1.name).to.equal('video 1 server 2')
125 expect(videos2.name).to.equal('video 2 server 2')
127 expect(videos1.redundancies.files).to.have.lengthOf(4)
128 expect(videos1.redundancies.streamingPlaylists).to.have.lengthOf(1)
130 const redundancies = videos1.redundancies.files.concat(videos1.redundancies.streamingPlaylists)
132 for (const r of redundancies) {
133 expect(r.strategy).to.be.null
134 expect(r.fileUrl).to.exist
135 expect(r.createdAt).to.exist
136 expect(r.updatedAt).to.exist
137 expect(r.expiresOn).to.exist
141 it('Should not have "my-videos" redundancies on server 1', async function () {
142 const res = await listVideoRedundancies({
144 accessToken: servers[0].accessToken,
148 expect(res.body.total).to.equal(0)
149 expect(res.body.data).to.have.lengthOf(0)
152 it('Should have "remote-videos" redundancies on server 1', async function () {
155 const res = await listVideoRedundancies({
157 accessToken: servers[0].accessToken,
158 target: 'remote-videos'
161 expect(res.body.total).to.equal(2)
163 const videos = res.body.data as VideoRedundancy[]
164 expect(videos).to.have.lengthOf(2)
166 const videos1 = videos.find(v => v.uuid === video1Server2UUID)
167 const videos2 = videos.find(v => v.uuid === video2Server2UUID)
169 expect(videos1.name).to.equal('video 1 server 2')
170 expect(videos2.name).to.equal('video 2 server 2')
172 expect(videos1.redundancies.files).to.have.lengthOf(4)
173 expect(videos1.redundancies.streamingPlaylists).to.have.lengthOf(1)
175 const redundancies = videos1.redundancies.files.concat(videos1.redundancies.streamingPlaylists)
177 for (const r of redundancies) {
178 expect(r.strategy).to.equal('recently-added')
179 expect(r.fileUrl).to.exist
180 expect(r.createdAt).to.exist
181 expect(r.updatedAt).to.exist
182 expect(r.expiresOn).to.exist
186 it('Should correctly paginate and sort results', async function () {
188 const res = await listVideoRedundancies({
190 accessToken: servers[0].accessToken,
191 target: 'remote-videos',
197 const videos = res.body.data
198 expect(videos[ 0 ].name).to.equal('video 1 server 2')
199 expect(videos[ 1 ].name).to.equal('video 2 server 2')
203 const res = await listVideoRedundancies({
205 accessToken: servers[0].accessToken,
206 target: 'remote-videos',
212 const videos = res.body.data
213 expect(videos[ 0 ].name).to.equal('video 2 server 2')
214 expect(videos[ 1 ].name).to.equal('video 1 server 2')
218 const res = await listVideoRedundancies({
220 accessToken: servers[0].accessToken,
221 target: 'remote-videos',
227 const videos = res.body.data
228 expect(videos[ 0 ].name).to.equal('video 1 server 2')
232 it('Should manually add a redundancy and list it', async function () {
235 const uuid = (await uploadVideoAndGetId({ server: servers[ 1 ], videoName: 'video 3 server 2', privacy: VideoPrivacy.UNLISTED })).uuid
236 await waitJobs(servers)
237 const videoId = await getLocalIdByUUID(servers[0].url, uuid)
239 await addVideoRedundancy({
241 accessToken: servers[0].accessToken,
245 await waitJobs(servers)
246 await waitUntilLog(servers[0], 'Duplicated ', 15)
247 await waitJobs(servers)
250 const res = await listVideoRedundancies({
252 accessToken: servers[0].accessToken,
253 target: 'remote-videos',
259 const videos = res.body.data
260 expect(videos[ 0 ].name).to.equal('video 3 server 2')
262 const video = videos[ 0 ]
263 expect(video.redundancies.files).to.have.lengthOf(4)
264 expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1)
266 const redundancies = video.redundancies.files.concat(video.redundancies.streamingPlaylists)
268 for (const r of redundancies) {
269 redundanciesToRemove.push(r.id)
271 expect(r.strategy).to.equal('manual')
272 expect(r.fileUrl).to.exist
273 expect(r.createdAt).to.exist
274 expect(r.updatedAt).to.exist
275 expect(r.expiresOn).to.be.null
279 const res = await listVideoRedundancies({
281 accessToken: servers[1].accessToken,
288 const videos = res.body.data
289 expect(videos[ 0 ].name).to.equal('video 3 server 2')
291 const video = videos[ 0 ]
292 expect(video.redundancies.files).to.have.lengthOf(4)
293 expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1)
295 const redundancies = video.redundancies.files.concat(video.redundancies.streamingPlaylists)
297 for (const r of redundancies) {
298 expect(r.strategy).to.be.null
299 expect(r.fileUrl).to.exist
300 expect(r.createdAt).to.exist
301 expect(r.updatedAt).to.exist
302 expect(r.expiresOn).to.be.null
306 it('Should manually remove a redundancy and remove it from the list', async function () {
309 for (const redundancyId of redundanciesToRemove) {
310 await removeVideoRedundancy({
311 url: servers[ 0 ].url,
312 accessToken: servers[ 0 ].accessToken,
318 const res = await listVideoRedundancies({
320 accessToken: servers[0].accessToken,
321 target: 'remote-videos',
327 const videos = res.body.data
328 expect(videos).to.have.lengthOf(2)
330 expect(videos[ 0 ].name).to.equal('video 2 server 2')
332 redundanciesToRemove = []
333 const video = videos[ 0 ]
334 expect(video.redundancies.files).to.have.lengthOf(4)
335 expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1)
337 const redundancies = video.redundancies.files.concat(video.redundancies.streamingPlaylists)
339 for (const r of redundancies) {
340 redundanciesToRemove.push(r.id)
345 it('Should remove another (auto) redundancy', async function () {
347 for (const redundancyId of redundanciesToRemove) {
348 await removeVideoRedundancy({
349 url: servers[ 0 ].url,
350 accessToken: servers[ 0 ].accessToken,
355 const res = await listVideoRedundancies({
357 accessToken: servers[0].accessToken,
358 target: 'remote-videos',
364 const videos = res.body.data
365 expect(videos[ 0 ].name).to.equal('video 1 server 2')
366 expect(videos).to.have.lengthOf(1)
370 after(async function () {
371 await cleanupTests(servers)