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