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