1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
4 import { VideoPrivacy } from '@shared/models'
10 setAccessTokensToServers,
12 } from '@shared/server-commands'
14 describe('Test redundancy constraints', function () {
15 let remoteServer: PeerTubeServer
16 let localServer: PeerTubeServer
17 let servers: PeerTubeServer[]
19 const remoteServerConfig = {
22 check_interval: '1 second',
25 strategy: 'recently-added',
26 min_lifetime: '1 hour',
35 async function uploadWrapper (videoName: string) {
36 // Wait for transcoding
37 const { id } = await localServer.videos.upload({ attributes: { name: 'to transcode', privacy: VideoPrivacy.PRIVATE } })
38 await waitJobs([ localServer ])
40 // Update video to schedule a federation
41 await localServer.videos.update({ id, attributes: { name: videoName, privacy: VideoPrivacy.PUBLIC } })
44 async function getTotalRedundanciesLocalServer () {
45 const body = await localServer.redundancy.listVideos({ target: 'my-videos' })
50 async function getTotalRedundanciesRemoteServer () {
51 const body = await remoteServer.redundancy.listVideos({ target: 'remote-videos' })
56 before(async function () {
60 remoteServer = await createSingleServer(1, remoteServerConfig)
71 localServer = await createSingleServer(2, config)
74 servers = [ remoteServer, localServer ]
76 // Get the access tokens
77 await setAccessTokensToServers(servers)
79 await localServer.videos.upload({ attributes: { name: 'video 1 server 2' } })
81 await waitJobs(servers)
83 // Server 1 and server 2 follow each other
84 await remoteServer.follows.follow({ hosts: [ localServer.url ] })
85 await waitJobs(servers)
86 await remoteServer.redundancy.updateRedundancy({ host: localServer.host, redundancyAllowed: true })
88 await waitJobs(servers)
91 it('Should have redundancy on server 1 but not on server 2 with a nobody filter', async function () {
94 await waitJobs(servers)
95 await remoteServer.servers.waitUntilLog('Duplicated ', 5)
96 await waitJobs(servers)
99 const total = await getTotalRedundanciesRemoteServer()
100 expect(total).to.equal(1)
104 const total = await getTotalRedundanciesLocalServer()
105 expect(total).to.equal(0)
109 it('Should have redundancy on server 1 and on server 2 with an anybody filter', async function () {
115 accept_from: 'anybody'
119 await killallServers([ localServer ])
120 await localServer.run(config)
122 await uploadWrapper('video 2 server 2')
124 await remoteServer.servers.waitUntilLog('Duplicated ', 10)
125 await waitJobs(servers)
128 const total = await getTotalRedundanciesRemoteServer()
129 expect(total).to.equal(2)
133 const total = await getTotalRedundanciesLocalServer()
134 expect(total).to.equal(1)
138 it('Should have redundancy on server 1 but not on server 2 with a followings filter', async function () {
144 accept_from: 'followings'
148 await killallServers([ localServer ])
149 await localServer.run(config)
151 await uploadWrapper('video 3 server 2')
153 await remoteServer.servers.waitUntilLog('Duplicated ', 15)
154 await waitJobs(servers)
157 const total = await getTotalRedundanciesRemoteServer()
158 expect(total).to.equal(3)
162 const total = await getTotalRedundanciesLocalServer()
163 expect(total).to.equal(1)
167 it('Should have redundancy on server 1 and on server 2 with followings filter now server 2 follows server 1', async function () {
170 await localServer.follows.follow({ hosts: [ remoteServer.url ] })
171 await waitJobs(servers)
173 await uploadWrapper('video 4 server 2')
174 await remoteServer.servers.waitUntilLog('Duplicated ', 20)
175 await waitJobs(servers)
178 const total = await getTotalRedundanciesRemoteServer()
179 expect(total).to.equal(4)
183 const total = await getTotalRedundanciesLocalServer()
184 expect(total).to.equal(2)
188 after(async function () {
189 await cleanupTests(servers)