1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { expect } from 'chai'
5 import { cleanupTests, createSingleServer, killallServers, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
6 import { VideoPrivacy } from '@shared/models'
8 describe('Test redundancy constraints', function () {
9 let remoteServer: PeerTubeServer
10 let localServer: PeerTubeServer
11 let servers: PeerTubeServer[]
13 const remoteServerConfig = {
16 check_interval: '1 second',
19 strategy: 'recently-added',
20 min_lifetime: '1 hour',
29 async function uploadWrapper (videoName: string) {
30 // Wait for transcoding
31 const { id } = await localServer.videos.upload({ attributes: { name: 'to transcode', privacy: VideoPrivacy.PRIVATE } })
32 await waitJobs([ localServer ])
34 // Update video to schedule a federation
35 await localServer.videos.update({ id, attributes: { name: videoName, privacy: VideoPrivacy.PUBLIC } })
38 async function getTotalRedundanciesLocalServer () {
39 const body = await localServer.redundancy.listVideos({ target: 'my-videos' })
44 async function getTotalRedundanciesRemoteServer () {
45 const body = await remoteServer.redundancy.listVideos({ target: 'remote-videos' })
50 before(async function () {
54 remoteServer = await createSingleServer(1, remoteServerConfig)
65 localServer = await createSingleServer(2, config)
68 servers = [ remoteServer, localServer ]
70 // Get the access tokens
71 await setAccessTokensToServers(servers)
73 await localServer.videos.upload({ attributes: { name: 'video 1 server 2' } })
75 await waitJobs(servers)
77 // Server 1 and server 2 follow each other
78 await remoteServer.follows.follow({ hosts: [ localServer.url ] })
79 await waitJobs(servers)
80 await remoteServer.redundancy.updateRedundancy({ host: localServer.host, redundancyAllowed: true })
82 await waitJobs(servers)
85 it('Should have redundancy on server 1 but not on server 2 with a nobody filter', async function () {
88 await waitJobs(servers)
89 await remoteServer.servers.waitUntilLog('Duplicated ', 5)
90 await waitJobs(servers)
93 const total = await getTotalRedundanciesRemoteServer()
94 expect(total).to.equal(1)
98 const total = await getTotalRedundanciesLocalServer()
99 expect(total).to.equal(0)
103 it('Should have redundancy on server 1 and on server 2 with an anybody filter', async function () {
109 accept_from: 'anybody'
113 await killallServers([ localServer ])
114 await localServer.run(config)
116 await uploadWrapper('video 2 server 2')
118 await remoteServer.servers.waitUntilLog('Duplicated ', 10)
119 await waitJobs(servers)
122 const total = await getTotalRedundanciesRemoteServer()
123 expect(total).to.equal(2)
127 const total = await getTotalRedundanciesLocalServer()
128 expect(total).to.equal(1)
132 it('Should have redundancy on server 1 but not on server 2 with a followings filter', async function () {
138 accept_from: 'followings'
142 await killallServers([ localServer ])
143 await localServer.run(config)
145 await uploadWrapper('video 3 server 2')
147 await remoteServer.servers.waitUntilLog('Duplicated ', 15)
148 await waitJobs(servers)
151 const total = await getTotalRedundanciesRemoteServer()
152 expect(total).to.equal(3)
156 const total = await getTotalRedundanciesLocalServer()
157 expect(total).to.equal(1)
161 it('Should have redundancy on server 1 and on server 2 with followings filter now server 2 follows server 1', async function () {
164 await localServer.follows.follow({ hosts: [ remoteServer.url ] })
165 await waitJobs(servers)
167 await uploadWrapper('video 4 server 2')
168 await remoteServer.servers.waitUntilLog('Duplicated ', 20)
169 await waitJobs(servers)
172 const total = await getTotalRedundanciesRemoteServer()
173 expect(total).to.equal(4)
177 const total = await getTotalRedundanciesLocalServer()
178 expect(total).to.equal(2)
182 after(async function () {
183 await cleanupTests(servers)