1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { listVideoRedundancies, updateRedundancy } from '@shared/extra-utils/server/redundancy'
6 import { VideoPrivacy } from '@shared/models'
13 setAccessTokensToServers,
17 } from '../../../../shared/extra-utils'
18 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
20 const expect = chai.expect
22 describe('Test redundancy constraints', function () {
23 let remoteServer: ServerInfo
24 let localServer: ServerInfo
25 let servers: ServerInfo[]
27 const remoteServerConfig = {
30 check_interval: '1 second',
33 strategy: 'recently-added',
34 min_lifetime: '1 hour',
43 async function uploadWrapper (videoName: string) {
44 // Wait for transcoding
45 const res = await uploadVideo(localServer.url, localServer.accessToken, { name: 'to transcode', privacy: VideoPrivacy.PRIVATE })
46 await waitJobs([ localServer ])
48 // Update video to schedule a federation
49 await updateVideo(localServer.url, localServer.accessToken, res.body.video.id, { name: videoName, privacy: VideoPrivacy.PUBLIC })
52 async function getTotalRedundanciesLocalServer () {
53 const res = await listVideoRedundancies({
55 accessToken: localServer.accessToken,
62 async function getTotalRedundanciesRemoteServer () {
63 const res = await listVideoRedundancies({
64 url: remoteServer.url,
65 accessToken: remoteServer.accessToken,
66 target: 'remote-videos'
72 before(async function () {
76 remoteServer = await flushAndRunServer(1, remoteServerConfig)
87 localServer = await flushAndRunServer(2, config)
90 servers = [ remoteServer, localServer ]
92 // Get the access tokens
93 await setAccessTokensToServers(servers)
95 await uploadVideo(localServer.url, localServer.accessToken, { name: 'video 1 server 2' })
97 await waitJobs(servers)
99 // Server 1 and server 2 follow each other
100 await remoteServer.followsCommand.follow({ targets: [ localServer.url ] })
101 await waitJobs(servers)
102 await updateRedundancy(remoteServer.url, remoteServer.accessToken, localServer.host, true)
104 await waitJobs(servers)
107 it('Should have redundancy on server 1 but not on server 2 with a nobody filter', async function () {
110 await waitJobs(servers)
111 await waitUntilLog(remoteServer, 'Duplicated ', 5)
112 await waitJobs(servers)
115 const total = await getTotalRedundanciesRemoteServer()
116 expect(total).to.equal(1)
120 const total = await getTotalRedundanciesLocalServer()
121 expect(total).to.equal(0)
125 it('Should have redundancy on server 1 and on server 2 with an anybody filter', async function () {
131 accept_from: 'anybody'
135 await killallServers([ localServer ])
136 await reRunServer(localServer, config)
138 await uploadWrapper('video 2 server 2')
140 await waitUntilLog(remoteServer, 'Duplicated ', 10)
141 await waitJobs(servers)
144 const total = await getTotalRedundanciesRemoteServer()
145 expect(total).to.equal(2)
149 const total = await getTotalRedundanciesLocalServer()
150 expect(total).to.equal(1)
154 it('Should have redundancy on server 1 but not on server 2 with a followings filter', async function () {
160 accept_from: 'followings'
164 await killallServers([ localServer ])
165 await reRunServer(localServer, config)
167 await uploadWrapper('video 3 server 2')
169 await waitUntilLog(remoteServer, 'Duplicated ', 15)
170 await waitJobs(servers)
173 const total = await getTotalRedundanciesRemoteServer()
174 expect(total).to.equal(3)
178 const total = await getTotalRedundanciesLocalServer()
179 expect(total).to.equal(1)
183 it('Should have redundancy on server 1 and on server 2 with followings filter now server 2 follows server 1', async function () {
186 await localServer.followsCommand.follow({ targets: [ remoteServer.url ] })
187 await waitJobs(servers)
189 await uploadWrapper('video 4 server 2')
190 await waitUntilLog(remoteServer, 'Duplicated ', 20)
191 await waitJobs(servers)
194 const total = await getTotalRedundanciesRemoteServer()
195 expect(total).to.equal(4)
199 const total = await getTotalRedundanciesLocalServer()
200 expect(total).to.equal(2)
204 after(async function () {
205 await cleanupTests(servers)