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