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