]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import { expect } from 'chai' | |
5 | import { VideoPrivacy } from '@shared/models' | |
6 | import { | |
7 | cleanupTests, | |
8 | createSingleServer, | |
9 | killallServers, | |
10 | PeerTubeServer, | |
11 | setAccessTokensToServers, | |
12 | waitJobs | |
13 | } from '@shared/server-commands' | |
14 | ||
15 | describe('Test redundancy constraints', function () { | |
16 | let remoteServer: PeerTubeServer | |
17 | let localServer: PeerTubeServer | |
18 | let servers: PeerTubeServer[] | |
19 | ||
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 | |
38 | const { id } = await localServer.videos.upload({ attributes: { name: 'to transcode', privacy: VideoPrivacy.PRIVATE } }) | |
39 | await waitJobs([ localServer ]) | |
40 | ||
41 | // Update video to schedule a federation | |
42 | await localServer.videos.update({ id, attributes: { name: videoName, privacy: VideoPrivacy.PUBLIC } }) | |
43 | } | |
44 | ||
45 | async function getTotalRedundanciesLocalServer () { | |
46 | const body = await localServer.redundancy.listVideos({ target: 'my-videos' }) | |
47 | ||
48 | return body.total | |
49 | } | |
50 | ||
51 | async function getTotalRedundanciesRemoteServer () { | |
52 | const body = await remoteServer.redundancy.listVideos({ target: 'remote-videos' }) | |
53 | ||
54 | return body.total | |
55 | } | |
56 | ||
57 | before(async function () { | |
58 | this.timeout(120000) | |
59 | ||
60 | { | |
61 | remoteServer = await createSingleServer(1, remoteServerConfig) | |
62 | } | |
63 | ||
64 | { | |
65 | const config = { | |
66 | remote_redundancy: { | |
67 | videos: { | |
68 | accept_from: 'nobody' | |
69 | } | |
70 | } | |
71 | } | |
72 | localServer = await createSingleServer(2, config) | |
73 | } | |
74 | ||
75 | servers = [ remoteServer, localServer ] | |
76 | ||
77 | // Get the access tokens | |
78 | await setAccessTokensToServers(servers) | |
79 | ||
80 | await localServer.videos.upload({ attributes: { name: 'video 1 server 2' } }) | |
81 | ||
82 | await waitJobs(servers) | |
83 | ||
84 | // Server 1 and server 2 follow each other | |
85 | await remoteServer.follows.follow({ hosts: [ localServer.url ] }) | |
86 | await waitJobs(servers) | |
87 | await remoteServer.redundancy.updateRedundancy({ host: localServer.host, redundancyAllowed: true }) | |
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) | |
96 | await remoteServer.servers.waitUntilLog('Duplicated ', 5) | |
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 | } | |
120 | await killallServers([ localServer ]) | |
121 | await localServer.run(config) | |
122 | ||
123 | await uploadWrapper('video 2 server 2') | |
124 | ||
125 | await remoteServer.servers.waitUntilLog('Duplicated ', 10) | |
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 | } | |
149 | await killallServers([ localServer ]) | |
150 | await localServer.run(config) | |
151 | ||
152 | await uploadWrapper('video 3 server 2') | |
153 | ||
154 | await remoteServer.servers.waitUntilLog('Duplicated ', 15) | |
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 | ||
171 | await localServer.follows.follow({ hosts: [ remoteServer.url ] }) | |
172 | await waitJobs(servers) | |
173 | ||
174 | await uploadWrapper('video 4 server 2') | |
175 | await remoteServer.servers.waitUntilLog('Duplicated ', 20) | |
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 | }) |