1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { expect } from 'chai'
11 setAccessTokensToServers,
16 } from '@shared/extra-utils'
17 import { VideoPrivacy } from '@shared/models'
19 describe('Test redundancy constraints', function () {
20 let remoteServer: ServerInfo
21 let localServer: ServerInfo
22 let servers: ServerInfo[]
24 const remoteServerConfig = {
27 check_interval: '1 second',
30 strategy: 'recently-added',
31 min_lifetime: '1 hour',
40 async function uploadWrapper (videoName: string) {
41 // Wait for transcoding
42 const res = await uploadVideo(localServer.url, localServer.accessToken, { name: 'to transcode', privacy: VideoPrivacy.PRIVATE })
43 await waitJobs([ localServer ])
45 // Update video to schedule a federation
46 await updateVideo(localServer.url, localServer.accessToken, res.body.video.id, { name: videoName, privacy: VideoPrivacy.PUBLIC })
49 async function getTotalRedundanciesLocalServer () {
50 const body = await localServer.redundancyCommand.listVideos({ target: 'my-videos' })
55 async function getTotalRedundanciesRemoteServer () {
56 const body = await remoteServer.redundancyCommand.listVideos({ target: 'remote-videos' })
61 before(async function () {
65 remoteServer = await flushAndRunServer(1, remoteServerConfig)
76 localServer = await flushAndRunServer(2, config)
79 servers = [ remoteServer, localServer ]
81 // Get the access tokens
82 await setAccessTokensToServers(servers)
84 await uploadVideo(localServer.url, localServer.accessToken, { name: 'video 1 server 2' })
86 await waitJobs(servers)
88 // Server 1 and server 2 follow each other
89 await remoteServer.followsCommand.follow({ targets: [ localServer.url ] })
90 await waitJobs(servers)
91 await remoteServer.redundancyCommand.updateRedundancy({ host: localServer.host, redundancyAllowed: true })
93 await waitJobs(servers)
96 it('Should have redundancy on server 1 but not on server 2 with a nobody filter', async function () {
99 await waitJobs(servers)
100 await waitUntilLog(remoteServer, 'Duplicated ', 5)
101 await waitJobs(servers)
104 const total = await getTotalRedundanciesRemoteServer()
105 expect(total).to.equal(1)
109 const total = await getTotalRedundanciesLocalServer()
110 expect(total).to.equal(0)
114 it('Should have redundancy on server 1 and on server 2 with an anybody filter', async function () {
120 accept_from: 'anybody'
124 await await killallServers([ localServer ])
125 await reRunServer(localServer, config)
127 await uploadWrapper('video 2 server 2')
129 await waitUntilLog(remoteServer, 'Duplicated ', 10)
130 await waitJobs(servers)
133 const total = await getTotalRedundanciesRemoteServer()
134 expect(total).to.equal(2)
138 const total = await getTotalRedundanciesLocalServer()
139 expect(total).to.equal(1)
143 it('Should have redundancy on server 1 but not on server 2 with a followings filter', async function () {
149 accept_from: 'followings'
153 await killallServers([ localServer ])
154 await reRunServer(localServer, config)
156 await uploadWrapper('video 3 server 2')
158 await waitUntilLog(remoteServer, 'Duplicated ', 15)
159 await waitJobs(servers)
162 const total = await getTotalRedundanciesRemoteServer()
163 expect(total).to.equal(3)
167 const total = await getTotalRedundanciesLocalServer()
168 expect(total).to.equal(1)
172 it('Should have redundancy on server 1 and on server 2 with followings filter now server 2 follows server 1', async function () {
175 await localServer.followsCommand.follow({ targets: [ remoteServer.url ] })
176 await waitJobs(servers)
178 await uploadWrapper('video 4 server 2')
179 await waitUntilLog(remoteServer, 'Duplicated ', 20)
180 await waitJobs(servers)
183 const total = await getTotalRedundanciesRemoteServer()
184 expect(total).to.equal(4)
188 const total = await getTotalRedundanciesLocalServer()
189 expect(total).to.equal(2)
193 after(async function () {
194 await cleanupTests(servers)