]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/redundancy/redundancy-constraints.ts
Introduce channels command
[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 waitUntilLog
16 } from '@shared/extra-utils'
17 import { VideoPrivacy } from '@shared/models'
18
19 describe('Test redundancy constraints', function () {
20 let remoteServer: ServerInfo
21 let localServer: ServerInfo
22 let servers: ServerInfo[]
23
24 const remoteServerConfig = {
25 redundancy: {
26 videos: {
27 check_interval: '1 second',
28 strategies: [
29 {
30 strategy: 'recently-added',
31 min_lifetime: '1 hour',
32 size: '100MB',
33 min_views: 0
34 }
35 ]
36 }
37 }
38 }
39
40 async function uploadWrapper (videoName: string) {
41 // Wait for transcoding
42 const res = await uploadVideo(localServer.url, localServer.accessToken, { name: 'to transcode', privacy: VideoPrivacy.PRIVATE })
43 await waitJobs([ localServer ])
44
45 // Update video to schedule a federation
46 await updateVideo(localServer.url, localServer.accessToken, res.body.video.id, { name: videoName, privacy: VideoPrivacy.PUBLIC })
47 }
48
49 async function getTotalRedundanciesLocalServer () {
50 const body = await localServer.redundancyCommand.listVideos({ target: 'my-videos' })
51
52 return body.total
53 }
54
55 async function getTotalRedundanciesRemoteServer () {
56 const body = await remoteServer.redundancyCommand.listVideos({ target: 'remote-videos' })
57
58 return body.total
59 }
60
61 before(async function () {
62 this.timeout(120000)
63
64 {
65 remoteServer = await flushAndRunServer(1, remoteServerConfig)
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 remoteServer.followsCommand.follow({ targets: [ localServer.url ] })
90 await waitJobs(servers)
91 await remoteServer.redundancyCommand.updateRedundancy({ host: localServer.host, redundancyAllowed: 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 uploadWrapper('video 2 server 2')
128
129 await waitUntilLog(remoteServer, 'Duplicated ', 10)
130 await waitJobs(servers)
131
132 {
133 const total = await getTotalRedundanciesRemoteServer()
134 expect(total).to.equal(2)
135 }
136
137 {
138 const total = await getTotalRedundanciesLocalServer()
139 expect(total).to.equal(1)
140 }
141 })
142
143 it('Should have redundancy on server 1 but not on server 2 with a followings filter', async function () {
144 this.timeout(120000)
145
146 const config = {
147 remote_redundancy: {
148 videos: {
149 accept_from: 'followings'
150 }
151 }
152 }
153 killallServers([ localServer ])
154 await reRunServer(localServer, config)
155
156 await uploadWrapper('video 3 server 2')
157
158 await waitUntilLog(remoteServer, 'Duplicated ', 15)
159 await waitJobs(servers)
160
161 {
162 const total = await getTotalRedundanciesRemoteServer()
163 expect(total).to.equal(3)
164 }
165
166 {
167 const total = await getTotalRedundanciesLocalServer()
168 expect(total).to.equal(1)
169 }
170 })
171
172 it('Should have redundancy on server 1 and on server 2 with followings filter now server 2 follows server 1', async function () {
173 this.timeout(120000)
174
175 await localServer.followsCommand.follow({ targets: [ remoteServer.url ] })
176 await waitJobs(servers)
177
178 await uploadWrapper('video 4 server 2')
179 await waitUntilLog(remoteServer, 'Duplicated ', 20)
180 await waitJobs(servers)
181
182 {
183 const total = await getTotalRedundanciesRemoteServer()
184 expect(total).to.equal(4)
185 }
186
187 {
188 const total = await getTotalRedundanciesLocalServer()
189 expect(total).to.equal(2)
190 }
191 })
192
193 after(async function () {
194 await cleanupTests(servers)
195 })
196 })