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