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