]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/redundancy/redundancy-constraints.ts
shared/ typescript types dir server-commands
[github/Chocobozzz/PeerTube.git] / server / tests / api / redundancy / redundancy-constraints.ts
CommitLineData
8c9e7875
C
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
8c9e7875 3import 'mocha'
a5461888 4import { expect } from 'chai'
bf54587a 5import { cleanupTests, createSingleServer, killallServers, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/server-commands'
dab04709 6import { VideoPrivacy } from '@shared/models'
8c9e7875 7
8c9e7875 8describe('Test redundancy constraints', function () {
254d3579
C
9 let remoteServer: PeerTubeServer
10 let localServer: PeerTubeServer
11 let servers: PeerTubeServer[]
8c9e7875 12
6949a1a1
C
13 const remoteServerConfig = {
14 redundancy: {
15 videos: {
16 check_interval: '1 second',
17 strategies: [
18 {
19 strategy: 'recently-added',
20 min_lifetime: '1 hour',
21 size: '100MB',
22 min_views: 0
23 }
24 ]
25 }
26 }
27 }
28
29 async function uploadWrapper (videoName: string) {
30 // Wait for transcoding
89d241a7 31 const { id } = await localServer.videos.upload({ attributes: { name: 'to transcode', privacy: VideoPrivacy.PRIVATE } })
6949a1a1
C
32 await waitJobs([ localServer ])
33
34 // Update video to schedule a federation
89d241a7 35 await localServer.videos.update({ id, attributes: { name: videoName, privacy: VideoPrivacy.PUBLIC } })
6949a1a1
C
36 }
37
8c9e7875 38 async function getTotalRedundanciesLocalServer () {
89d241a7 39 const body = await localServer.redundancy.listVideos({ target: 'my-videos' })
8c9e7875 40
dab04709 41 return body.total
8c9e7875
C
42 }
43
44 async function getTotalRedundanciesRemoteServer () {
89d241a7 45 const body = await remoteServer.redundancy.listVideos({ target: 'remote-videos' })
8c9e7875 46
dab04709 47 return body.total
8c9e7875
C
48 }
49
50 before(async function () {
51 this.timeout(120000)
52
53 {
254d3579 54 remoteServer = await createSingleServer(1, remoteServerConfig)
8c9e7875
C
55 }
56
57 {
58 const config = {
59 remote_redundancy: {
60 videos: {
61 accept_from: 'nobody'
62 }
63 }
64 }
254d3579 65 localServer = await createSingleServer(2, config)
8c9e7875
C
66 }
67
68 servers = [ remoteServer, localServer ]
69
70 // Get the access tokens
71 await setAccessTokensToServers(servers)
72
89d241a7 73 await localServer.videos.upload({ attributes: { name: 'video 1 server 2' } })
8c9e7875
C
74
75 await waitJobs(servers)
76
77 // Server 1 and server 2 follow each other
4d029ef8 78 await remoteServer.follows.follow({ hosts: [ localServer.url ] })
8c9e7875 79 await waitJobs(servers)
89d241a7 80 await remoteServer.redundancy.updateRedundancy({ host: localServer.host, redundancyAllowed: true })
8c9e7875
C
81
82 await waitJobs(servers)
83 })
84
85 it('Should have redundancy on server 1 but not on server 2 with a nobody filter', async function () {
86 this.timeout(120000)
87
88 await waitJobs(servers)
89d241a7 89 await remoteServer.servers.waitUntilLog('Duplicated ', 5)
8c9e7875
C
90 await waitJobs(servers)
91
92 {
93 const total = await getTotalRedundanciesRemoteServer()
94 expect(total).to.equal(1)
95 }
96
97 {
98 const total = await getTotalRedundanciesLocalServer()
99 expect(total).to.equal(0)
100 }
101 })
102
103 it('Should have redundancy on server 1 and on server 2 with an anybody filter', async function () {
104 this.timeout(120000)
105
106 const config = {
107 remote_redundancy: {
108 videos: {
109 accept_from: 'anybody'
110 }
111 }
112 }
c0e8b12e 113 await killallServers([ localServer ])
254d3579 114 await localServer.run(config)
8c9e7875 115
6949a1a1 116 await uploadWrapper('video 2 server 2')
8c9e7875 117
89d241a7 118 await remoteServer.servers.waitUntilLog('Duplicated ', 10)
8c9e7875
C
119 await waitJobs(servers)
120
121 {
122 const total = await getTotalRedundanciesRemoteServer()
123 expect(total).to.equal(2)
124 }
125
126 {
127 const total = await getTotalRedundanciesLocalServer()
128 expect(total).to.equal(1)
129 }
130 })
131
132 it('Should have redundancy on server 1 but not on server 2 with a followings filter', async function () {
133 this.timeout(120000)
134
135 const config = {
136 remote_redundancy: {
137 videos: {
138 accept_from: 'followings'
139 }
140 }
141 }
9293139f 142 await killallServers([ localServer ])
254d3579 143 await localServer.run(config)
8c9e7875 144
6949a1a1 145 await uploadWrapper('video 3 server 2')
8c9e7875 146
89d241a7 147 await remoteServer.servers.waitUntilLog('Duplicated ', 15)
8c9e7875
C
148 await waitJobs(servers)
149
150 {
151 const total = await getTotalRedundanciesRemoteServer()
152 expect(total).to.equal(3)
153 }
154
155 {
156 const total = await getTotalRedundanciesLocalServer()
157 expect(total).to.equal(1)
158 }
159 })
160
161 it('Should have redundancy on server 1 and on server 2 with followings filter now server 2 follows server 1', async function () {
162 this.timeout(120000)
163
4d029ef8 164 await localServer.follows.follow({ hosts: [ remoteServer.url ] })
8c9e7875
C
165 await waitJobs(servers)
166
6949a1a1 167 await uploadWrapper('video 4 server 2')
89d241a7 168 await remoteServer.servers.waitUntilLog('Duplicated ', 20)
8c9e7875
C
169 await waitJobs(servers)
170
171 {
172 const total = await getTotalRedundanciesRemoteServer()
173 expect(total).to.equal(4)
174 }
175
176 {
177 const total = await getTotalRedundanciesLocalServer()
178 expect(total).to.equal(2)
179 }
180 })
181
182 after(async function () {
183 await cleanupTests(servers)
184 })
185})