]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import { | |
5 | cleanupTests, | |
6 | flushAndRunServer, | |
7 | killallServers, | |
8 | reRunServer, | |
9 | ServerInfo, | |
10 | setAccessTokensToServers, | |
11 | updateVideo, | |
12 | uploadVideo, | |
13 | waitJobs, | |
14 | waitUntilLog | |
15 | } from '@shared/extra-utils' | |
16 | import { VideoPrivacy } from '@shared/models' | |
17 | ||
18 | const expect = chai.expect | |
19 | ||
20 | describe('Test redundancy constraints', function () { | |
21 | let remoteServer: ServerInfo | |
22 | let localServer: ServerInfo | |
23 | let servers: ServerInfo[] | |
24 | ||
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 | ||
50 | async function getTotalRedundanciesLocalServer () { | |
51 | const body = await localServer.redundancyCommand.listVideos({ target: 'my-videos' }) | |
52 | ||
53 | return body.total | |
54 | } | |
55 | ||
56 | async function getTotalRedundanciesRemoteServer () { | |
57 | const body = await remoteServer.redundancyCommand.listVideos({ target: 'remote-videos' }) | |
58 | ||
59 | return body.total | |
60 | } | |
61 | ||
62 | before(async function () { | |
63 | this.timeout(120000) | |
64 | ||
65 | { | |
66 | remoteServer = await flushAndRunServer(1, remoteServerConfig) | |
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 | |
90 | await remoteServer.followsCommand.follow({ targets: [ localServer.url ] }) | |
91 | await waitJobs(servers) | |
92 | await remoteServer.redundancyCommand.updateRedundancy({ host: localServer.host, redundancyAllowed: true }) | |
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 | ||
128 | await uploadWrapper('video 2 server 2') | |
129 | ||
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 | } | |
154 | killallServers([ localServer ]) | |
155 | await reRunServer(localServer, config) | |
156 | ||
157 | await uploadWrapper('video 3 server 2') | |
158 | ||
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 | ||
176 | await localServer.followsCommand.follow({ targets: [ remoteServer.url ] }) | |
177 | await waitJobs(servers) | |
178 | ||
179 | await uploadWrapper('video 4 server 2') | |
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 | }) |