1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
10 setAccessTokensToServers,
15 } from '@shared/extra-utils'
16 import { VideoPrivacy } from '@shared/models'
18 const expect = chai.expect
20 describe('Test redundancy constraints', function () {
21 let remoteServer: ServerInfo
22 let localServer: ServerInfo
23 let servers: ServerInfo[]
25 const remoteServerConfig = {
28 check_interval: '1 second',
31 strategy: 'recently-added',
32 min_lifetime: '1 hour',
41 async function uploadWrapper (videoName: string) {
42 // Wait for transcoding
43 const res = await uploadVideo(localServer.url, localServer.accessToken, { name: 'to transcode', privacy: VideoPrivacy.PRIVATE })
44 await waitJobs([ localServer ])
46 // Update video to schedule a federation
47 await updateVideo(localServer.url, localServer.accessToken, res.body.video.id, { name: videoName, privacy: VideoPrivacy.PUBLIC })
50 async function getTotalRedundanciesLocalServer () {
51 const body = await localServer.redundancyCommand.listVideos({ target: 'my-videos' })
56 async function getTotalRedundanciesRemoteServer () {
57 const body = await remoteServer.redundancyCommand.listVideos({ target: 'remote-videos' })
62 before(async function () {
66 remoteServer = await flushAndRunServer(1, remoteServerConfig)
77 localServer = await flushAndRunServer(2, config)
80 servers = [ remoteServer, localServer ]
82 // Get the access tokens
83 await setAccessTokensToServers(servers)
85 await uploadVideo(localServer.url, localServer.accessToken, { name: 'video 1 server 2' })
87 await waitJobs(servers)
89 // Server 1 and server 2 follow each other
90 await remoteServer.followsCommand.follow({ targets: [ localServer.url ] })
91 await waitJobs(servers)
92 await remoteServer.redundancyCommand.updateRedundancy({ host: localServer.host, redundancyAllowed: true })
94 await waitJobs(servers)
97 it('Should have redundancy on server 1 but not on server 2 with a nobody filter', async function () {
100 await waitJobs(servers)
101 await waitUntilLog(remoteServer, 'Duplicated ', 5)
102 await waitJobs(servers)
105 const total = await getTotalRedundanciesRemoteServer()
106 expect(total).to.equal(1)
110 const total = await getTotalRedundanciesLocalServer()
111 expect(total).to.equal(0)
115 it('Should have redundancy on server 1 and on server 2 with an anybody filter', async function () {
121 accept_from: 'anybody'
125 await killallServers([ localServer ])
126 await reRunServer(localServer, config)
128 await uploadWrapper('video 2 server 2')
130 await waitUntilLog(remoteServer, 'Duplicated ', 10)
131 await waitJobs(servers)
134 const total = await getTotalRedundanciesRemoteServer()
135 expect(total).to.equal(2)
139 const total = await getTotalRedundanciesLocalServer()
140 expect(total).to.equal(1)
144 it('Should have redundancy on server 1 but not on server 2 with a followings filter', async function () {
150 accept_from: 'followings'
154 killallServers([ localServer ])
155 await reRunServer(localServer, config)
157 await uploadWrapper('video 3 server 2')
159 await waitUntilLog(remoteServer, 'Duplicated ', 15)
160 await waitJobs(servers)
163 const total = await getTotalRedundanciesRemoteServer()
164 expect(total).to.equal(3)
168 const total = await getTotalRedundanciesLocalServer()
169 expect(total).to.equal(1)
173 it('Should have redundancy on server 1 and on server 2 with followings filter now server 2 follows server 1', async function () {
176 await localServer.followsCommand.follow({ targets: [ remoteServer.url ] })
177 await waitJobs(servers)
179 await uploadWrapper('video 4 server 2')
180 await waitUntilLog(remoteServer, 'Duplicated ', 20)
181 await waitJobs(servers)
184 const total = await getTotalRedundanciesRemoteServer()
185 expect(total).to.equal(4)
189 const total = await getTotalRedundanciesLocalServer()
190 expect(total).to.equal(2)
194 after(async function () {
195 await cleanupTests(servers)