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