1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { expect } from 'chai'
11 setAccessTokensToServers,
15 } from '@shared/extra-utils'
16 import { VideoPrivacy } from '@shared/models'
18 describe('Test redundancy constraints', function () {
19 let remoteServer: ServerInfo
20 let localServer: ServerInfo
21 let servers: ServerInfo[]
23 const remoteServerConfig = {
26 check_interval: '1 second',
29 strategy: 'recently-added',
30 min_lifetime: '1 hour',
39 async function uploadWrapper (videoName: string) {
40 // Wait for transcoding
41 const res = await uploadVideo(localServer.url, localServer.accessToken, { name: 'to transcode', privacy: VideoPrivacy.PRIVATE })
42 await waitJobs([ localServer ])
44 // Update video to schedule a federation
45 await updateVideo(localServer.url, localServer.accessToken, res.body.video.id, { name: videoName, privacy: VideoPrivacy.PUBLIC })
48 async function getTotalRedundanciesLocalServer () {
49 const body = await localServer.redundancyCommand.listVideos({ target: 'my-videos' })
54 async function getTotalRedundanciesRemoteServer () {
55 const body = await remoteServer.redundancyCommand.listVideos({ target: 'remote-videos' })
60 before(async function () {
64 remoteServer = await flushAndRunServer(1, remoteServerConfig)
75 localServer = await flushAndRunServer(2, config)
78 servers = [ remoteServer, localServer ]
80 // Get the access tokens
81 await setAccessTokensToServers(servers)
83 await uploadVideo(localServer.url, localServer.accessToken, { name: 'video 1 server 2' })
85 await waitJobs(servers)
87 // Server 1 and server 2 follow each other
88 await remoteServer.followsCommand.follow({ targets: [ localServer.url ] })
89 await waitJobs(servers)
90 await remoteServer.redundancyCommand.updateRedundancy({ host: localServer.host, redundancyAllowed: true })
92 await waitJobs(servers)
95 it('Should have redundancy on server 1 but not on server 2 with a nobody filter', async function () {
98 await waitJobs(servers)
99 await remoteServer.serversCommand.waitUntilLog('Duplicated ', 5)
100 await waitJobs(servers)
103 const total = await getTotalRedundanciesRemoteServer()
104 expect(total).to.equal(1)
108 const total = await getTotalRedundanciesLocalServer()
109 expect(total).to.equal(0)
113 it('Should have redundancy on server 1 and on server 2 with an anybody filter', async function () {
119 accept_from: 'anybody'
123 await await killallServers([ localServer ])
124 await reRunServer(localServer, config)
126 await uploadWrapper('video 2 server 2')
128 await remoteServer.serversCommand.waitUntilLog('Duplicated ', 10)
129 await waitJobs(servers)
132 const total = await getTotalRedundanciesRemoteServer()
133 expect(total).to.equal(2)
137 const total = await getTotalRedundanciesLocalServer()
138 expect(total).to.equal(1)
142 it('Should have redundancy on server 1 but not on server 2 with a followings filter', async function () {
148 accept_from: 'followings'
152 await killallServers([ localServer ])
153 await reRunServer(localServer, config)
155 await uploadWrapper('video 3 server 2')
157 await remoteServer.serversCommand.waitUntilLog('Duplicated ', 15)
158 await waitJobs(servers)
161 const total = await getTotalRedundanciesRemoteServer()
162 expect(total).to.equal(3)
166 const total = await getTotalRedundanciesLocalServer()
167 expect(total).to.equal(1)
171 it('Should have redundancy on server 1 and on server 2 with followings filter now server 2 follows server 1', async function () {
174 await localServer.followsCommand.follow({ targets: [ remoteServer.url ] })
175 await waitJobs(servers)
177 await uploadWrapper('video 4 server 2')
178 await remoteServer.serversCommand.waitUntilLog('Duplicated ', 20)
179 await waitJobs(servers)
182 const total = await getTotalRedundanciesRemoteServer()
183 expect(total).to.equal(4)
187 const total = await getTotalRedundanciesLocalServer()
188 expect(total).to.equal(2)
192 after(async function () {
193 await cleanupTests(servers)