1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { expect } from 'chai'
5 import { VideoPrivacy } from '@shared/models'
11 setAccessTokensToServers,
13 } from '@shared/server-commands'
15 describe('Test redundancy constraints', function () {
16 let remoteServer: PeerTubeServer
17 let localServer: PeerTubeServer
18 let servers: PeerTubeServer[]
20 const remoteServerConfig = {
23 check_interval: '1 second',
26 strategy: 'recently-added',
27 min_lifetime: '1 hour',
36 async function uploadWrapper (videoName: string) {
37 // Wait for transcoding
38 const { id } = await localServer.videos.upload({ attributes: { name: 'to transcode', privacy: VideoPrivacy.PRIVATE } })
39 await waitJobs([ localServer ])
41 // Update video to schedule a federation
42 await localServer.videos.update({ id, attributes: { name: videoName, privacy: VideoPrivacy.PUBLIC } })
45 async function getTotalRedundanciesLocalServer () {
46 const body = await localServer.redundancy.listVideos({ target: 'my-videos' })
51 async function getTotalRedundanciesRemoteServer () {
52 const body = await remoteServer.redundancy.listVideos({ target: 'remote-videos' })
57 before(async function () {
61 remoteServer = await createSingleServer(1, remoteServerConfig)
72 localServer = await createSingleServer(2, config)
75 servers = [ remoteServer, localServer ]
77 // Get the access tokens
78 await setAccessTokensToServers(servers)
80 await localServer.videos.upload({ attributes: { name: 'video 1 server 2' } })
82 await waitJobs(servers)
84 // Server 1 and server 2 follow each other
85 await remoteServer.follows.follow({ hosts: [ localServer.url ] })
86 await waitJobs(servers)
87 await remoteServer.redundancy.updateRedundancy({ host: localServer.host, redundancyAllowed: true })
89 await waitJobs(servers)
92 it('Should have redundancy on server 1 but not on server 2 with a nobody filter', async function () {
95 await waitJobs(servers)
96 await remoteServer.servers.waitUntilLog('Duplicated ', 5)
97 await waitJobs(servers)
100 const total = await getTotalRedundanciesRemoteServer()
101 expect(total).to.equal(1)
105 const total = await getTotalRedundanciesLocalServer()
106 expect(total).to.equal(0)
110 it('Should have redundancy on server 1 and on server 2 with an anybody filter', async function () {
116 accept_from: 'anybody'
120 await killallServers([ localServer ])
121 await localServer.run(config)
123 await uploadWrapper('video 2 server 2')
125 await remoteServer.servers.waitUntilLog('Duplicated ', 10)
126 await waitJobs(servers)
129 const total = await getTotalRedundanciesRemoteServer()
130 expect(total).to.equal(2)
134 const total = await getTotalRedundanciesLocalServer()
135 expect(total).to.equal(1)
139 it('Should have redundancy on server 1 but not on server 2 with a followings filter', async function () {
145 accept_from: 'followings'
149 await killallServers([ localServer ])
150 await localServer.run(config)
152 await uploadWrapper('video 3 server 2')
154 await remoteServer.servers.waitUntilLog('Duplicated ', 15)
155 await waitJobs(servers)
158 const total = await getTotalRedundanciesRemoteServer()
159 expect(total).to.equal(3)
163 const total = await getTotalRedundanciesLocalServer()
164 expect(total).to.equal(1)
168 it('Should have redundancy on server 1 and on server 2 with followings filter now server 2 follows server 1', async function () {
171 await localServer.follows.follow({ hosts: [ remoteServer.url ] })
172 await waitJobs(servers)
174 await uploadWrapper('video 4 server 2')
175 await remoteServer.servers.waitUntilLog('Duplicated ', 20)
176 await waitJobs(servers)
179 const total = await getTotalRedundanciesRemoteServer()
180 expect(total).to.equal(4)
184 const total = await getTotalRedundanciesLocalServer()
185 expect(total).to.equal(2)
189 after(async function () {
190 await cleanupTests(servers)