1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
8 flushAndRunMultipleServers,
12 setAccessTokensToServers,
17 } from '@shared/extra-utils'
18 import { VideoPrivacy, VideoRedundanciesTarget } 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 let commands: RedundancyCommand[]
32 before(async function () {
43 check_interval: '1 second',
46 strategy: 'recently-added',
47 min_lifetime: '1 hour',
55 servers = await flushAndRunMultipleServers(3, config)
57 // Get the access tokens
58 await setAccessTokensToServers(servers)
60 commands = servers.map(s => s.redundancyCommand)
63 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' })
64 video1Server2UUID = res.body.video.uuid
68 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 2 server 2' })
69 video2Server2UUID = res.body.video.uuid
72 await waitJobs(servers)
74 // Server 1 and server 2 follow each other
75 await doubleFollow(servers[0], servers[1])
76 await commands[0].updateRedundancy({ host: servers[1].host, redundancyAllowed: true })
78 await waitJobs(servers)
81 it('Should not have redundancies on server 3', async function () {
82 for (const target of targets) {
83 const body = await commands[2].listVideos({ target })
85 expect(body.total).to.equal(0)
86 expect(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 body = await commands[1].listVideos({ target: 'remote-videos' })
99 expect(body.total).to.equal(0)
100 expect(body.data).to.have.lengthOf(0)
103 it('Should have "my-videos" redundancies on server 2', async function () {
106 const body = await commands[1].listVideos({ target: 'my-videos' })
107 expect(body.total).to.equal(2)
109 const videos = body.data
110 expect(videos).to.have.lengthOf(2)
112 const videos1 = videos.find(v => v.uuid === video1Server2UUID)
113 const videos2 = videos.find(v => v.uuid === video2Server2UUID)
115 expect(videos1.name).to.equal('video 1 server 2')
116 expect(videos2.name).to.equal('video 2 server 2')
118 expect(videos1.redundancies.files).to.have.lengthOf(4)
119 expect(videos1.redundancies.streamingPlaylists).to.have.lengthOf(1)
121 const redundancies = videos1.redundancies.files.concat(videos1.redundancies.streamingPlaylists)
123 for (const r of redundancies) {
124 expect(r.strategy).to.be.null
125 expect(r.fileUrl).to.exist
126 expect(r.createdAt).to.exist
127 expect(r.updatedAt).to.exist
128 expect(r.expiresOn).to.exist
132 it('Should not have "my-videos" redundancies on server 1', async function () {
133 const body = await commands[0].listVideos({ target: 'my-videos' })
135 expect(body.total).to.equal(0)
136 expect(body.data).to.have.lengthOf(0)
139 it('Should have "remote-videos" redundancies on server 1', async function () {
142 const body = await commands[0].listVideos({ target: 'remote-videos' })
143 expect(body.total).to.equal(2)
145 const videos = body.data
146 expect(videos).to.have.lengthOf(2)
148 const videos1 = videos.find(v => v.uuid === video1Server2UUID)
149 const videos2 = videos.find(v => v.uuid === video2Server2UUID)
151 expect(videos1.name).to.equal('video 1 server 2')
152 expect(videos2.name).to.equal('video 2 server 2')
154 expect(videos1.redundancies.files).to.have.lengthOf(4)
155 expect(videos1.redundancies.streamingPlaylists).to.have.lengthOf(1)
157 const redundancies = videos1.redundancies.files.concat(videos1.redundancies.streamingPlaylists)
159 for (const r of redundancies) {
160 expect(r.strategy).to.equal('recently-added')
161 expect(r.fileUrl).to.exist
162 expect(r.createdAt).to.exist
163 expect(r.updatedAt).to.exist
164 expect(r.expiresOn).to.exist
168 it('Should correctly paginate and sort results', async function () {
170 const body = await commands[0].listVideos({
171 target: 'remote-videos',
177 const videos = body.data
178 expect(videos[0].name).to.equal('video 1 server 2')
179 expect(videos[1].name).to.equal('video 2 server 2')
183 const body = await commands[0].listVideos({
184 target: 'remote-videos',
190 const videos = body.data
191 expect(videos[0].name).to.equal('video 2 server 2')
192 expect(videos[1].name).to.equal('video 1 server 2')
196 const body = await commands[0].listVideos({
197 target: 'remote-videos',
203 expect(body.data[0].name).to.equal('video 1 server 2')
207 it('Should manually add a redundancy and list it', async function () {
210 const uuid = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 3 server 2', privacy: VideoPrivacy.UNLISTED })).uuid
211 await waitJobs(servers)
212 const videoId = await getLocalIdByUUID(servers[0].url, uuid)
214 await commands[0].addVideo({ videoId })
216 await waitJobs(servers)
217 await waitUntilLog(servers[0], 'Duplicated ', 15)
218 await waitJobs(servers)
221 const body = await commands[0].listVideos({
222 target: 'remote-videos',
228 const video = body.data[0]
230 expect(video.name).to.equal('video 3 server 2')
231 expect(video.redundancies.files).to.have.lengthOf(4)
232 expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1)
234 const redundancies = video.redundancies.files.concat(video.redundancies.streamingPlaylists)
236 for (const r of redundancies) {
237 redundanciesToRemove.push(r.id)
239 expect(r.strategy).to.equal('manual')
240 expect(r.fileUrl).to.exist
241 expect(r.createdAt).to.exist
242 expect(r.updatedAt).to.exist
243 expect(r.expiresOn).to.be.null
247 const body = await commands[1].listVideos({
254 const video = body.data[0]
255 expect(video.name).to.equal('video 3 server 2')
256 expect(video.redundancies.files).to.have.lengthOf(4)
257 expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1)
259 const redundancies = video.redundancies.files.concat(video.redundancies.streamingPlaylists)
261 for (const r of redundancies) {
262 expect(r.strategy).to.be.null
263 expect(r.fileUrl).to.exist
264 expect(r.createdAt).to.exist
265 expect(r.updatedAt).to.exist
266 expect(r.expiresOn).to.be.null
270 it('Should manually remove a redundancy and remove it from the list', async function () {
273 for (const redundancyId of redundanciesToRemove) {
274 await commands[0].removeVideo({ redundancyId })
278 const body = await commands[0].listVideos({
279 target: 'remote-videos',
285 const videos = body.data
287 expect(videos).to.have.lengthOf(2)
289 const video = videos[0]
290 expect(video.name).to.equal('video 2 server 2')
291 expect(video.redundancies.files).to.have.lengthOf(4)
292 expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1)
294 const redundancies = video.redundancies.files.concat(video.redundancies.streamingPlaylists)
296 redundanciesToRemove = redundancies.map(r => r.id)
300 it('Should remove another (auto) redundancy', async function () {
301 for (const redundancyId of redundanciesToRemove) {
302 await commands[0].removeVideo({ redundancyId })
305 const body = await commands[0].listVideos({
306 target: 'remote-videos',
312 const videos = body.data
313 expect(videos).to.have.lengthOf(1)
314 expect(videos[0].name).to.equal('video 1 server 2')
317 after(async function () {
318 await cleanupTests(servers)