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