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'
14 setAccessTokensToServers,
18 } from '../../../../shared/extra-utils'
19 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
21 const expect = chai.expect
23 describe('Test redundancy constraints', function () {
24 let remoteServer: ServerInfo
25 let localServer: ServerInfo
26 let servers: ServerInfo[]
28 const remoteServerConfig = {
31 check_interval: '1 second',
34 strategy: 'recently-added',
35 min_lifetime: '1 hour',
44 async function uploadWrapper (videoName: string) {
45 // Wait for transcoding
46 const res = await uploadVideo(localServer.url, localServer.accessToken, { name: 'to transcode', privacy: VideoPrivacy.PRIVATE })
47 await waitJobs([ localServer ])
49 // Update video to schedule a federation
50 await updateVideo(localServer.url, localServer.accessToken, res.body.video.id, { name: videoName, privacy: VideoPrivacy.PUBLIC })
53 async function getTotalRedundanciesLocalServer () {
54 const res = await listVideoRedundancies({
56 accessToken: localServer.accessToken,
63 async function getTotalRedundanciesRemoteServer () {
64 const res = await listVideoRedundancies({
65 url: remoteServer.url,
66 accessToken: remoteServer.accessToken,
67 target: 'remote-videos'
73 before(async function () {
77 remoteServer = await flushAndRunServer(1, remoteServerConfig)
88 localServer = await flushAndRunServer(2, config)
91 servers = [ remoteServer, localServer ]
93 // Get the access tokens
94 await setAccessTokensToServers(servers)
96 await uploadVideo(localServer.url, localServer.accessToken, { name: 'video 1 server 2' })
98 await waitJobs(servers)
100 // Server 1 and server 2 follow each other
101 await follow(remoteServer.url, [ localServer.url ], remoteServer.accessToken)
102 await waitJobs(servers)
103 await updateRedundancy(remoteServer.url, remoteServer.accessToken, localServer.host, true)
105 await waitJobs(servers)
108 it('Should have redundancy on server 1 but not on server 2 with a nobody filter', async function () {
111 await waitJobs(servers)
112 await waitUntilLog(remoteServer, 'Duplicated ', 5)
113 await waitJobs(servers)
116 const total = await getTotalRedundanciesRemoteServer()
117 expect(total).to.equal(1)
121 const total = await getTotalRedundanciesLocalServer()
122 expect(total).to.equal(0)
126 it('Should have redundancy on server 1 and on server 2 with an anybody filter', async function () {
132 accept_from: 'anybody'
136 await killallServers([ localServer ])
137 await reRunServer(localServer, config)
139 await uploadWrapper('video 2 server 2')
141 await waitUntilLog(remoteServer, 'Duplicated ', 10)
142 await waitJobs(servers)
145 const total = await getTotalRedundanciesRemoteServer()
146 expect(total).to.equal(2)
150 const total = await getTotalRedundanciesLocalServer()
151 expect(total).to.equal(1)
155 it('Should have redundancy on server 1 but not on server 2 with a followings filter', async function () {
161 accept_from: 'followings'
165 await killallServers([ localServer ])
166 await reRunServer(localServer, config)
168 await uploadWrapper('video 3 server 2')
170 await waitUntilLog(remoteServer, 'Duplicated ', 15)
171 await waitJobs(servers)
174 const total = await getTotalRedundanciesRemoteServer()
175 expect(total).to.equal(3)
179 const total = await getTotalRedundanciesLocalServer()
180 expect(total).to.equal(1)
184 it('Should have redundancy on server 1 and on server 2 with followings filter now server 2 follows server 1', async function () {
187 await follow(localServer.url, [ remoteServer.url ], localServer.accessToken)
188 await waitJobs(servers)
190 await uploadWrapper('video 4 server 2')
191 await waitUntilLog(remoteServer, 'Duplicated ', 20)
192 await waitJobs(servers)
195 const total = await getTotalRedundanciesRemoteServer()
196 expect(total).to.equal(4)
200 const total = await getTotalRedundanciesLocalServer()
201 expect(total).to.equal(2)
205 after(async function () {
206 await cleanupTests(servers)