1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
8 flushAndRunMultipleServers,
12 setAccessTokensToServers,
16 } from '@shared/extra-utils'
17 import { VideoPrivacy, VideoRedundanciesTarget } from '@shared/models'
19 const expect = chai.expect
21 describe('Test manage videos redundancy', function () {
22 const targets: VideoRedundanciesTarget[] = [ 'my-videos', 'remote-videos' ]
24 let servers: ServerInfo[]
25 let video1Server2UUID: string
26 let video2Server2UUID: string
27 let redundanciesToRemove: number[] = []
29 let commands: RedundancyCommand[]
31 before(async function () {
42 check_interval: '1 second',
45 strategy: 'recently-added',
46 min_lifetime: '1 hour',
54 servers = await flushAndRunMultipleServers(3, config)
56 // Get the access tokens
57 await setAccessTokensToServers(servers)
59 commands = servers.map(s => s.redundancyCommand)
62 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' })
63 video1Server2UUID = res.body.video.uuid
67 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 2 server 2' })
68 video2Server2UUID = res.body.video.uuid
71 await waitJobs(servers)
73 // Server 1 and server 2 follow each other
74 await doubleFollow(servers[0], servers[1])
75 await commands[0].updateRedundancy({ host: servers[1].host, redundancyAllowed: true })
77 await waitJobs(servers)
80 it('Should not have redundancies on server 3', async function () {
81 for (const target of targets) {
82 const body = await commands[2].listVideos({ target })
84 expect(body.total).to.equal(0)
85 expect(body.data).to.have.lengthOf(0)
89 it('Should not have "remote-videos" redundancies on server 2', async function () {
92 await waitJobs(servers)
93 await servers[0].serversCommand.waitUntilLog('Duplicated ', 10)
94 await waitJobs(servers)
96 const body = await commands[1].listVideos({ target: 'remote-videos' })
98 expect(body.total).to.equal(0)
99 expect(body.data).to.have.lengthOf(0)
102 it('Should have "my-videos" redundancies on server 2', async function () {
105 const body = await commands[1].listVideos({ target: 'my-videos' })
106 expect(body.total).to.equal(2)
108 const videos = body.data
109 expect(videos).to.have.lengthOf(2)
111 const videos1 = videos.find(v => v.uuid === video1Server2UUID)
112 const videos2 = videos.find(v => v.uuid === video2Server2UUID)
114 expect(videos1.name).to.equal('video 1 server 2')
115 expect(videos2.name).to.equal('video 2 server 2')
117 expect(videos1.redundancies.files).to.have.lengthOf(4)
118 expect(videos1.redundancies.streamingPlaylists).to.have.lengthOf(1)
120 const redundancies = videos1.redundancies.files.concat(videos1.redundancies.streamingPlaylists)
122 for (const r of redundancies) {
123 expect(r.strategy).to.be.null
124 expect(r.fileUrl).to.exist
125 expect(r.createdAt).to.exist
126 expect(r.updatedAt).to.exist
127 expect(r.expiresOn).to.exist
131 it('Should not have "my-videos" redundancies on server 1', async function () {
132 const body = await commands[0].listVideos({ target: 'my-videos' })
134 expect(body.total).to.equal(0)
135 expect(body.data).to.have.lengthOf(0)
138 it('Should have "remote-videos" redundancies on server 1', async function () {
141 const body = await commands[0].listVideos({ target: 'remote-videos' })
142 expect(body.total).to.equal(2)
144 const videos = body.data
145 expect(videos).to.have.lengthOf(2)
147 const videos1 = videos.find(v => v.uuid === video1Server2UUID)
148 const videos2 = videos.find(v => v.uuid === video2Server2UUID)
150 expect(videos1.name).to.equal('video 1 server 2')
151 expect(videos2.name).to.equal('video 2 server 2')
153 expect(videos1.redundancies.files).to.have.lengthOf(4)
154 expect(videos1.redundancies.streamingPlaylists).to.have.lengthOf(1)
156 const redundancies = videos1.redundancies.files.concat(videos1.redundancies.streamingPlaylists)
158 for (const r of redundancies) {
159 expect(r.strategy).to.equal('recently-added')
160 expect(r.fileUrl).to.exist
161 expect(r.createdAt).to.exist
162 expect(r.updatedAt).to.exist
163 expect(r.expiresOn).to.exist
167 it('Should correctly paginate and sort results', async function () {
169 const body = await commands[0].listVideos({
170 target: 'remote-videos',
176 const videos = body.data
177 expect(videos[0].name).to.equal('video 1 server 2')
178 expect(videos[1].name).to.equal('video 2 server 2')
182 const body = await commands[0].listVideos({
183 target: 'remote-videos',
189 const videos = body.data
190 expect(videos[0].name).to.equal('video 2 server 2')
191 expect(videos[1].name).to.equal('video 1 server 2')
195 const body = await commands[0].listVideos({
196 target: 'remote-videos',
202 expect(body.data[0].name).to.equal('video 1 server 2')
206 it('Should manually add a redundancy and list it', async function () {
209 const uuid = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 3 server 2', privacy: VideoPrivacy.UNLISTED })).uuid
210 await waitJobs(servers)
211 const videoId = await getLocalIdByUUID(servers[0].url, uuid)
213 await commands[0].addVideo({ videoId })
215 await waitJobs(servers)
216 await servers[0].serversCommand.waitUntilLog('Duplicated ', 15)
217 await waitJobs(servers)
220 const body = await commands[0].listVideos({
221 target: 'remote-videos',
227 const video = body.data[0]
229 expect(video.name).to.equal('video 3 server 2')
230 expect(video.redundancies.files).to.have.lengthOf(4)
231 expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1)
233 const redundancies = video.redundancies.files.concat(video.redundancies.streamingPlaylists)
235 for (const r of redundancies) {
236 redundanciesToRemove.push(r.id)
238 expect(r.strategy).to.equal('manual')
239 expect(r.fileUrl).to.exist
240 expect(r.createdAt).to.exist
241 expect(r.updatedAt).to.exist
242 expect(r.expiresOn).to.be.null
246 const body = await commands[1].listVideos({
253 const video = body.data[0]
254 expect(video.name).to.equal('video 3 server 2')
255 expect(video.redundancies.files).to.have.lengthOf(4)
256 expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1)
258 const redundancies = video.redundancies.files.concat(video.redundancies.streamingPlaylists)
260 for (const r of redundancies) {
261 expect(r.strategy).to.be.null
262 expect(r.fileUrl).to.exist
263 expect(r.createdAt).to.exist
264 expect(r.updatedAt).to.exist
265 expect(r.expiresOn).to.be.null
269 it('Should manually remove a redundancy and remove it from the list', async function () {
272 for (const redundancyId of redundanciesToRemove) {
273 await commands[0].removeVideo({ redundancyId })
277 const body = await commands[0].listVideos({
278 target: 'remote-videos',
284 const videos = body.data
286 expect(videos).to.have.lengthOf(2)
288 const video = videos[0]
289 expect(video.name).to.equal('video 2 server 2')
290 expect(video.redundancies.files).to.have.lengthOf(4)
291 expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1)
293 const redundancies = video.redundancies.files.concat(video.redundancies.streamingPlaylists)
295 redundanciesToRemove = redundancies.map(r => r.id)
299 it('Should remove another (auto) redundancy', async function () {
300 for (const redundancyId of redundanciesToRemove) {
301 await commands[0].removeVideo({ redundancyId })
304 const body = await commands[0].listVideos({
305 target: 'remote-videos',
311 const videos = body.data
312 expect(videos).to.have.lengthOf(1)
313 expect(videos[0].name).to.equal('video 1 server 2')
316 after(async function () {
317 await cleanupTests(servers)