1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
12 setAccessTokensToServers,
15 } from '../../../../shared/extra-utils'
16 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
17 import { listVideoRedundancies, updateRedundancy } from '@shared/extra-utils/server/redundancy'
19 const expect = chai.expect
21 describe('Test redundancy constraints', function () {
22 let remoteServer: ServerInfo
23 let localServer: ServerInfo
24 let servers: ServerInfo[]
26 async function getTotalRedundanciesLocalServer () {
27 const res = await listVideoRedundancies({
29 accessToken: localServer.accessToken,
36 async function getTotalRedundanciesRemoteServer () {
37 const res = await listVideoRedundancies({
38 url: remoteServer.url,
39 accessToken: remoteServer.accessToken,
40 target: 'remote-videos'
46 before(async function () {
53 check_interval: '1 second',
56 strategy: 'recently-added',
57 min_lifetime: '1 hour',
65 remoteServer = await flushAndRunServer(1, config)
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 follow(remoteServer.url, [ localServer.url ], remoteServer.accessToken)
90 await waitJobs(servers)
91 await updateRedundancy(remoteServer.url, remoteServer.accessToken, localServer.host, 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 killallServers([ localServer ])
125 await reRunServer(localServer, config)
127 await uploadVideo(localServer.url, localServer.accessToken, { name: 'video 2 server 2' })
129 await waitJobs(servers)
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 await killallServers([ localServer ])
155 await reRunServer(localServer, config)
157 await uploadVideo(localServer.url, localServer.accessToken, { name: 'video 3 server 2' })
159 await waitJobs(servers)
160 await waitUntilLog(remoteServer, 'Duplicated ', 15)
161 await waitJobs(servers)
164 const total = await getTotalRedundanciesRemoteServer()
165 expect(total).to.equal(3)
169 const total = await getTotalRedundanciesLocalServer()
170 expect(total).to.equal(1)
174 it('Should have redundancy on server 1 and on server 2 with followings filter now server 2 follows server 1', async function () {
177 await follow(localServer.url, [ remoteServer.url ], localServer.accessToken)
178 await waitJobs(servers)
180 await uploadVideo(localServer.url, localServer.accessToken, { name: 'video 4 server 2' })
182 await waitJobs(servers)
183 await waitUntilLog(remoteServer, 'Duplicated ', 20)
184 await waitJobs(servers)
187 const total = await getTotalRedundanciesRemoteServer()
188 expect(total).to.equal(4)
192 const total = await getTotalRedundanciesLocalServer()
193 expect(total).to.equal(2)
197 after(async function () {
198 await cleanupTests(servers)