diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-21 15:51:30 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-21 15:51:30 +0200 |
commit | a24bd1ed41b43790bab6ba789580bb4e85f07d85 (patch) | |
tree | a54b0f6c921ba83a6e909cd0ced325b2d4b8863c /server/tests/api/redundancy | |
parent | 5f26f13b3c16ac5ae0a3b0a7142d84a9528cf565 (diff) | |
parent | c63830f15403ac4e750829f27d8bbbdc9a59282c (diff) | |
download | PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.gz PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.zst PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.zip |
Merge branch 'next' into develop
Diffstat (limited to 'server/tests/api/redundancy')
-rw-r--r-- | server/tests/api/redundancy/manage-redundancy.ts | 193 | ||||
-rw-r--r-- | server/tests/api/redundancy/redundancy-constraints.ts | 69 | ||||
-rw-r--r-- | server/tests/api/redundancy/redundancy.ts | 201 |
3 files changed, 173 insertions, 290 deletions
diff --git a/server/tests/api/redundancy/manage-redundancy.ts b/server/tests/api/redundancy/manage-redundancy.ts index 4253124c8..5fd464ded 100644 --- a/server/tests/api/redundancy/manage-redundancy.ts +++ b/server/tests/api/redundancy/manage-redundancy.ts | |||
@@ -1,32 +1,30 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | ||
5 | import { | 5 | import { |
6 | cleanupTests, | 6 | cleanupTests, |
7 | createMultipleServers, | ||
7 | doubleFollow, | 8 | doubleFollow, |
8 | flushAndRunMultipleServers, | 9 | PeerTubeServer, |
9 | getLocalIdByUUID, | 10 | RedundancyCommand, |
10 | ServerInfo, | ||
11 | setAccessTokensToServers, | 11 | setAccessTokensToServers, |
12 | uploadVideo, | 12 | waitJobs |
13 | uploadVideoAndGetId, | 13 | } from '@shared/extra-utils' |
14 | waitUntilLog | 14 | import { VideoPrivacy, VideoRedundanciesTarget } from '@shared/models' |
15 | } from '../../../../shared/extra-utils' | ||
16 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | ||
17 | import { addVideoRedundancy, listVideoRedundancies, removeVideoRedundancy, updateRedundancy } from '@shared/extra-utils/server/redundancy' | ||
18 | import { VideoPrivacy, VideoRedundanciesTarget, VideoRedundancy } from '@shared/models' | ||
19 | 15 | ||
20 | const expect = chai.expect | 16 | const expect = chai.expect |
21 | 17 | ||
22 | describe('Test manage videos redundancy', function () { | 18 | describe('Test manage videos redundancy', function () { |
23 | const targets: VideoRedundanciesTarget[] = [ 'my-videos', 'remote-videos' ] | 19 | const targets: VideoRedundanciesTarget[] = [ 'my-videos', 'remote-videos' ] |
24 | 20 | ||
25 | let servers: ServerInfo[] | 21 | let servers: PeerTubeServer[] |
26 | let video1Server2UUID: string | 22 | let video1Server2UUID: string |
27 | let video2Server2UUID: string | 23 | let video2Server2UUID: string |
28 | let redundanciesToRemove: number[] = [] | 24 | let redundanciesToRemove: number[] = [] |
29 | 25 | ||
26 | let commands: RedundancyCommand[] | ||
27 | |||
30 | before(async function () { | 28 | before(async function () { |
31 | this.timeout(120000) | 29 | this.timeout(120000) |
32 | 30 | ||
@@ -50,40 +48,38 @@ describe('Test manage videos redundancy', function () { | |||
50 | } | 48 | } |
51 | } | 49 | } |
52 | } | 50 | } |
53 | servers = await flushAndRunMultipleServers(3, config) | 51 | servers = await createMultipleServers(3, config) |
54 | 52 | ||
55 | // Get the access tokens | 53 | // Get the access tokens |
56 | await setAccessTokensToServers(servers) | 54 | await setAccessTokensToServers(servers) |
57 | 55 | ||
56 | commands = servers.map(s => s.redundancy) | ||
57 | |||
58 | { | 58 | { |
59 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' }) | 59 | const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video 1 server 2' } }) |
60 | video1Server2UUID = res.body.video.uuid | 60 | video1Server2UUID = uuid |
61 | } | 61 | } |
62 | 62 | ||
63 | { | 63 | { |
64 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 2 server 2' }) | 64 | const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video 2 server 2' } }) |
65 | video2Server2UUID = res.body.video.uuid | 65 | video2Server2UUID = uuid |
66 | } | 66 | } |
67 | 67 | ||
68 | await waitJobs(servers) | 68 | await waitJobs(servers) |
69 | 69 | ||
70 | // Server 1 and server 2 follow each other | 70 | // Server 1 and server 2 follow each other |
71 | await doubleFollow(servers[0], servers[1]) | 71 | await doubleFollow(servers[0], servers[1]) |
72 | await updateRedundancy(servers[0].url, servers[0].accessToken, servers[1].host, true) | 72 | await commands[0].updateRedundancy({ host: servers[1].host, redundancyAllowed: true }) |
73 | 73 | ||
74 | await waitJobs(servers) | 74 | await waitJobs(servers) |
75 | }) | 75 | }) |
76 | 76 | ||
77 | it('Should not have redundancies on server 3', async function () { | 77 | it('Should not have redundancies on server 3', async function () { |
78 | for (const target of targets) { | 78 | for (const target of targets) { |
79 | const res = await listVideoRedundancies({ | 79 | const body = await commands[2].listVideos({ target }) |
80 | url: servers[2].url, | ||
81 | accessToken: servers[2].accessToken, | ||
82 | target | ||
83 | }) | ||
84 | 80 | ||
85 | expect(res.body.total).to.equal(0) | 81 | expect(body.total).to.equal(0) |
86 | expect(res.body.data).to.have.lengthOf(0) | 82 | expect(body.data).to.have.lengthOf(0) |
87 | } | 83 | } |
88 | }) | 84 | }) |
89 | 85 | ||
@@ -91,31 +87,22 @@ describe('Test manage videos redundancy', function () { | |||
91 | this.timeout(120000) | 87 | this.timeout(120000) |
92 | 88 | ||
93 | await waitJobs(servers) | 89 | await waitJobs(servers) |
94 | await waitUntilLog(servers[0], 'Duplicated ', 10) | 90 | await servers[0].servers.waitUntilLog('Duplicated ', 10) |
95 | await waitJobs(servers) | 91 | await waitJobs(servers) |
96 | 92 | ||
97 | const res = await listVideoRedundancies({ | 93 | const body = await commands[1].listVideos({ target: 'remote-videos' }) |
98 | url: servers[1].url, | ||
99 | accessToken: servers[1].accessToken, | ||
100 | target: 'remote-videos' | ||
101 | }) | ||
102 | 94 | ||
103 | expect(res.body.total).to.equal(0) | 95 | expect(body.total).to.equal(0) |
104 | expect(res.body.data).to.have.lengthOf(0) | 96 | expect(body.data).to.have.lengthOf(0) |
105 | }) | 97 | }) |
106 | 98 | ||
107 | it('Should have "my-videos" redundancies on server 2', async function () { | 99 | it('Should have "my-videos" redundancies on server 2', async function () { |
108 | this.timeout(120000) | 100 | this.timeout(120000) |
109 | 101 | ||
110 | const res = await listVideoRedundancies({ | 102 | const body = await commands[1].listVideos({ target: 'my-videos' }) |
111 | url: servers[1].url, | 103 | expect(body.total).to.equal(2) |
112 | accessToken: servers[1].accessToken, | ||
113 | target: 'my-videos' | ||
114 | }) | ||
115 | |||
116 | expect(res.body.total).to.equal(2) | ||
117 | 104 | ||
118 | const videos = res.body.data as VideoRedundancy[] | 105 | const videos = body.data |
119 | expect(videos).to.have.lengthOf(2) | 106 | expect(videos).to.have.lengthOf(2) |
120 | 107 | ||
121 | const videos1 = videos.find(v => v.uuid === video1Server2UUID) | 108 | const videos1 = videos.find(v => v.uuid === video1Server2UUID) |
@@ -139,28 +126,19 @@ describe('Test manage videos redundancy', function () { | |||
139 | }) | 126 | }) |
140 | 127 | ||
141 | it('Should not have "my-videos" redundancies on server 1', async function () { | 128 | it('Should not have "my-videos" redundancies on server 1', async function () { |
142 | const res = await listVideoRedundancies({ | 129 | const body = await commands[0].listVideos({ target: 'my-videos' }) |
143 | url: servers[0].url, | ||
144 | accessToken: servers[0].accessToken, | ||
145 | target: 'my-videos' | ||
146 | }) | ||
147 | 130 | ||
148 | expect(res.body.total).to.equal(0) | 131 | expect(body.total).to.equal(0) |
149 | expect(res.body.data).to.have.lengthOf(0) | 132 | expect(body.data).to.have.lengthOf(0) |
150 | }) | 133 | }) |
151 | 134 | ||
152 | it('Should have "remote-videos" redundancies on server 1', async function () { | 135 | it('Should have "remote-videos" redundancies on server 1', async function () { |
153 | this.timeout(120000) | 136 | this.timeout(120000) |
154 | 137 | ||
155 | const res = await listVideoRedundancies({ | 138 | const body = await commands[0].listVideos({ target: 'remote-videos' }) |
156 | url: servers[0].url, | 139 | expect(body.total).to.equal(2) |
157 | accessToken: servers[0].accessToken, | ||
158 | target: 'remote-videos' | ||
159 | }) | ||
160 | 140 | ||
161 | expect(res.body.total).to.equal(2) | 141 | const videos = body.data |
162 | |||
163 | const videos = res.body.data as VideoRedundancy[] | ||
164 | expect(videos).to.have.lengthOf(2) | 142 | expect(videos).to.have.lengthOf(2) |
165 | 143 | ||
166 | const videos1 = videos.find(v => v.uuid === video1Server2UUID) | 144 | const videos1 = videos.find(v => v.uuid === video1Server2UUID) |
@@ -185,81 +163,67 @@ describe('Test manage videos redundancy', function () { | |||
185 | 163 | ||
186 | it('Should correctly paginate and sort results', async function () { | 164 | it('Should correctly paginate and sort results', async function () { |
187 | { | 165 | { |
188 | const res = await listVideoRedundancies({ | 166 | const body = await commands[0].listVideos({ |
189 | url: servers[0].url, | ||
190 | accessToken: servers[0].accessToken, | ||
191 | target: 'remote-videos', | 167 | target: 'remote-videos', |
192 | sort: 'name', | 168 | sort: 'name', |
193 | start: 0, | 169 | start: 0, |
194 | count: 2 | 170 | count: 2 |
195 | }) | 171 | }) |
196 | 172 | ||
197 | const videos = res.body.data | 173 | const videos = body.data |
198 | expect(videos[0].name).to.equal('video 1 server 2') | 174 | expect(videos[0].name).to.equal('video 1 server 2') |
199 | expect(videos[1].name).to.equal('video 2 server 2') | 175 | expect(videos[1].name).to.equal('video 2 server 2') |
200 | } | 176 | } |
201 | 177 | ||
202 | { | 178 | { |
203 | const res = await listVideoRedundancies({ | 179 | const body = await commands[0].listVideos({ |
204 | url: servers[0].url, | ||
205 | accessToken: servers[0].accessToken, | ||
206 | target: 'remote-videos', | 180 | target: 'remote-videos', |
207 | sort: '-name', | 181 | sort: '-name', |
208 | start: 0, | 182 | start: 0, |
209 | count: 2 | 183 | count: 2 |
210 | }) | 184 | }) |
211 | 185 | ||
212 | const videos = res.body.data | 186 | const videos = body.data |
213 | expect(videos[0].name).to.equal('video 2 server 2') | 187 | expect(videos[0].name).to.equal('video 2 server 2') |
214 | expect(videos[1].name).to.equal('video 1 server 2') | 188 | expect(videos[1].name).to.equal('video 1 server 2') |
215 | } | 189 | } |
216 | 190 | ||
217 | { | 191 | { |
218 | const res = await listVideoRedundancies({ | 192 | const body = await commands[0].listVideos({ |
219 | url: servers[0].url, | ||
220 | accessToken: servers[0].accessToken, | ||
221 | target: 'remote-videos', | 193 | target: 'remote-videos', |
222 | sort: '-name', | 194 | sort: '-name', |
223 | start: 1, | 195 | start: 1, |
224 | count: 1 | 196 | count: 1 |
225 | }) | 197 | }) |
226 | 198 | ||
227 | const videos = res.body.data | 199 | expect(body.data[0].name).to.equal('video 1 server 2') |
228 | expect(videos[0].name).to.equal('video 1 server 2') | ||
229 | } | 200 | } |
230 | }) | 201 | }) |
231 | 202 | ||
232 | it('Should manually add a redundancy and list it', async function () { | 203 | it('Should manually add a redundancy and list it', async function () { |
233 | this.timeout(120000) | 204 | this.timeout(120000) |
234 | 205 | ||
235 | const uuid = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 3 server 2', privacy: VideoPrivacy.UNLISTED })).uuid | 206 | const uuid = (await servers[1].videos.quickUpload({ name: 'video 3 server 2', privacy: VideoPrivacy.UNLISTED })).uuid |
236 | await waitJobs(servers) | 207 | await waitJobs(servers) |
237 | const videoId = await getLocalIdByUUID(servers[0].url, uuid) | 208 | const videoId = await servers[0].videos.getId({ uuid }) |
238 | 209 | ||
239 | await addVideoRedundancy({ | 210 | await commands[0].addVideo({ videoId }) |
240 | url: servers[0].url, | ||
241 | accessToken: servers[0].accessToken, | ||
242 | videoId | ||
243 | }) | ||
244 | 211 | ||
245 | await waitJobs(servers) | 212 | await waitJobs(servers) |
246 | await waitUntilLog(servers[0], 'Duplicated ', 15) | 213 | await servers[0].servers.waitUntilLog('Duplicated ', 15) |
247 | await waitJobs(servers) | 214 | await waitJobs(servers) |
248 | 215 | ||
249 | { | 216 | { |
250 | const res = await listVideoRedundancies({ | 217 | const body = await commands[0].listVideos({ |
251 | url: servers[0].url, | ||
252 | accessToken: servers[0].accessToken, | ||
253 | target: 'remote-videos', | 218 | target: 'remote-videos', |
254 | sort: '-name', | 219 | sort: '-name', |
255 | start: 0, | 220 | start: 0, |
256 | count: 5 | 221 | count: 5 |
257 | }) | 222 | }) |
258 | 223 | ||
259 | const videos = res.body.data | 224 | const video = body.data[0] |
260 | expect(videos[0].name).to.equal('video 3 server 2') | ||
261 | 225 | ||
262 | const video = videos[0] | 226 | expect(video.name).to.equal('video 3 server 2') |
263 | expect(video.redundancies.files).to.have.lengthOf(4) | 227 | expect(video.redundancies.files).to.have.lengthOf(4) |
264 | expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1) | 228 | expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1) |
265 | 229 | ||
@@ -276,19 +240,15 @@ describe('Test manage videos redundancy', function () { | |||
276 | } | 240 | } |
277 | } | 241 | } |
278 | 242 | ||
279 | const res = await listVideoRedundancies({ | 243 | const body = await commands[1].listVideos({ |
280 | url: servers[1].url, | ||
281 | accessToken: servers[1].accessToken, | ||
282 | target: 'my-videos', | 244 | target: 'my-videos', |
283 | sort: '-name', | 245 | sort: '-name', |
284 | start: 0, | 246 | start: 0, |
285 | count: 5 | 247 | count: 5 |
286 | }) | 248 | }) |
287 | 249 | ||
288 | const videos = res.body.data | 250 | const video = body.data[0] |
289 | expect(videos[0].name).to.equal('video 3 server 2') | 251 | expect(video.name).to.equal('video 3 server 2') |
290 | |||
291 | const video = videos[0] | ||
292 | expect(video.redundancies.files).to.have.lengthOf(4) | 252 | expect(video.redundancies.files).to.have.lengthOf(4) |
293 | expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1) | 253 | expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1) |
294 | 254 | ||
@@ -307,64 +267,47 @@ describe('Test manage videos redundancy', function () { | |||
307 | this.timeout(120000) | 267 | this.timeout(120000) |
308 | 268 | ||
309 | for (const redundancyId of redundanciesToRemove) { | 269 | for (const redundancyId of redundanciesToRemove) { |
310 | await removeVideoRedundancy({ | 270 | await commands[0].removeVideo({ redundancyId }) |
311 | url: servers[0].url, | ||
312 | accessToken: servers[0].accessToken, | ||
313 | redundancyId | ||
314 | }) | ||
315 | } | 271 | } |
316 | 272 | ||
317 | { | 273 | { |
318 | const res = await listVideoRedundancies({ | 274 | const body = await commands[0].listVideos({ |
319 | url: servers[0].url, | ||
320 | accessToken: servers[0].accessToken, | ||
321 | target: 'remote-videos', | 275 | target: 'remote-videos', |
322 | sort: '-name', | 276 | sort: '-name', |
323 | start: 0, | 277 | start: 0, |
324 | count: 5 | 278 | count: 5 |
325 | }) | 279 | }) |
326 | 280 | ||
327 | const videos = res.body.data | 281 | const videos = body.data |
328 | expect(videos).to.have.lengthOf(2) | ||
329 | 282 | ||
330 | expect(videos[0].name).to.equal('video 2 server 2') | 283 | expect(videos).to.have.lengthOf(2) |
331 | 284 | ||
332 | redundanciesToRemove = [] | ||
333 | const video = videos[0] | 285 | const video = videos[0] |
286 | expect(video.name).to.equal('video 2 server 2') | ||
334 | expect(video.redundancies.files).to.have.lengthOf(4) | 287 | expect(video.redundancies.files).to.have.lengthOf(4) |
335 | expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1) | 288 | expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1) |
336 | 289 | ||
337 | const redundancies = video.redundancies.files.concat(video.redundancies.streamingPlaylists) | 290 | const redundancies = video.redundancies.files.concat(video.redundancies.streamingPlaylists) |
338 | 291 | ||
339 | for (const r of redundancies) { | 292 | redundanciesToRemove = redundancies.map(r => r.id) |
340 | redundanciesToRemove.push(r.id) | ||
341 | } | ||
342 | } | 293 | } |
343 | }) | 294 | }) |
344 | 295 | ||
345 | it('Should remove another (auto) redundancy', async function () { | 296 | it('Should remove another (auto) redundancy', async function () { |
346 | { | 297 | for (const redundancyId of redundanciesToRemove) { |
347 | for (const redundancyId of redundanciesToRemove) { | 298 | await commands[0].removeVideo({ redundancyId }) |
348 | await removeVideoRedundancy({ | 299 | } |
349 | url: servers[0].url, | ||
350 | accessToken: servers[0].accessToken, | ||
351 | redundancyId | ||
352 | }) | ||
353 | } | ||
354 | 300 | ||
355 | const res = await listVideoRedundancies({ | 301 | const body = await commands[0].listVideos({ |
356 | url: servers[0].url, | 302 | target: 'remote-videos', |
357 | accessToken: servers[0].accessToken, | 303 | sort: '-name', |
358 | target: 'remote-videos', | 304 | start: 0, |
359 | sort: '-name', | 305 | count: 5 |
360 | start: 0, | 306 | }) |
361 | count: 5 | ||
362 | }) | ||
363 | 307 | ||
364 | const videos = res.body.data | 308 | const videos = body.data |
365 | expect(videos[0].name).to.equal('video 1 server 2') | 309 | expect(videos).to.have.lengthOf(1) |
366 | expect(videos).to.have.lengthOf(1) | 310 | expect(videos[0].name).to.equal('video 1 server 2') |
367 | } | ||
368 | }) | 311 | }) |
369 | 312 | ||
370 | after(async function () { | 313 | after(async function () { |
diff --git a/server/tests/api/redundancy/redundancy-constraints.ts b/server/tests/api/redundancy/redundancy-constraints.ts index 1cb1603bc..933a2c776 100644 --- a/server/tests/api/redundancy/redundancy-constraints.ts +++ b/server/tests/api/redundancy/redundancy-constraints.ts | |||
@@ -1,29 +1,14 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import { expect } from 'chai' |
5 | import { listVideoRedundancies, updateRedundancy } from '@shared/extra-utils/server/redundancy' | 5 | import { cleanupTests, createSingleServer, killallServers, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' |
6 | import { VideoPrivacy } from '@shared/models' | 6 | import { VideoPrivacy } from '@shared/models' |
7 | import { | ||
8 | cleanupTests, | ||
9 | flushAndRunServer, | ||
10 | follow, | ||
11 | killallServers, | ||
12 | reRunServer, | ||
13 | ServerInfo, | ||
14 | setAccessTokensToServers, | ||
15 | updateVideo, | ||
16 | uploadVideo, | ||
17 | waitUntilLog | ||
18 | } from '../../../../shared/extra-utils' | ||
19 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | ||
20 | |||
21 | const expect = chai.expect | ||
22 | 7 | ||
23 | describe('Test redundancy constraints', function () { | 8 | describe('Test redundancy constraints', function () { |
24 | let remoteServer: ServerInfo | 9 | let remoteServer: PeerTubeServer |
25 | let localServer: ServerInfo | 10 | let localServer: PeerTubeServer |
26 | let servers: ServerInfo[] | 11 | let servers: PeerTubeServer[] |
27 | 12 | ||
28 | const remoteServerConfig = { | 13 | const remoteServerConfig = { |
29 | redundancy: { | 14 | redundancy: { |
@@ -43,38 +28,30 @@ describe('Test redundancy constraints', function () { | |||
43 | 28 | ||
44 | async function uploadWrapper (videoName: string) { | 29 | async function uploadWrapper (videoName: string) { |
45 | // Wait for transcoding | 30 | // Wait for transcoding |
46 | const res = await uploadVideo(localServer.url, localServer.accessToken, { name: 'to transcode', privacy: VideoPrivacy.PRIVATE }) | 31 | const { id } = await localServer.videos.upload({ attributes: { name: 'to transcode', privacy: VideoPrivacy.PRIVATE } }) |
47 | await waitJobs([ localServer ]) | 32 | await waitJobs([ localServer ]) |
48 | 33 | ||
49 | // Update video to schedule a federation | 34 | // Update video to schedule a federation |
50 | await updateVideo(localServer.url, localServer.accessToken, res.body.video.id, { name: videoName, privacy: VideoPrivacy.PUBLIC }) | 35 | await localServer.videos.update({ id, attributes: { name: videoName, privacy: VideoPrivacy.PUBLIC } }) |
51 | } | 36 | } |
52 | 37 | ||
53 | async function getTotalRedundanciesLocalServer () { | 38 | async function getTotalRedundanciesLocalServer () { |
54 | const res = await listVideoRedundancies({ | 39 | const body = await localServer.redundancy.listVideos({ target: 'my-videos' }) |
55 | url: localServer.url, | ||
56 | accessToken: localServer.accessToken, | ||
57 | target: 'my-videos' | ||
58 | }) | ||
59 | 40 | ||
60 | return res.body.total | 41 | return body.total |
61 | } | 42 | } |
62 | 43 | ||
63 | async function getTotalRedundanciesRemoteServer () { | 44 | async function getTotalRedundanciesRemoteServer () { |
64 | const res = await listVideoRedundancies({ | 45 | const body = await remoteServer.redundancy.listVideos({ target: 'remote-videos' }) |
65 | url: remoteServer.url, | ||
66 | accessToken: remoteServer.accessToken, | ||
67 | target: 'remote-videos' | ||
68 | }) | ||
69 | 46 | ||
70 | return res.body.total | 47 | return body.total |
71 | } | 48 | } |
72 | 49 | ||
73 | before(async function () { | 50 | before(async function () { |
74 | this.timeout(120000) | 51 | this.timeout(120000) |
75 | 52 | ||
76 | { | 53 | { |
77 | remoteServer = await flushAndRunServer(1, remoteServerConfig) | 54 | remoteServer = await createSingleServer(1, remoteServerConfig) |
78 | } | 55 | } |
79 | 56 | ||
80 | { | 57 | { |
@@ -85,7 +62,7 @@ describe('Test redundancy constraints', function () { | |||
85 | } | 62 | } |
86 | } | 63 | } |
87 | } | 64 | } |
88 | localServer = await flushAndRunServer(2, config) | 65 | localServer = await createSingleServer(2, config) |
89 | } | 66 | } |
90 | 67 | ||
91 | servers = [ remoteServer, localServer ] | 68 | servers = [ remoteServer, localServer ] |
@@ -93,14 +70,14 @@ describe('Test redundancy constraints', function () { | |||
93 | // Get the access tokens | 70 | // Get the access tokens |
94 | await setAccessTokensToServers(servers) | 71 | await setAccessTokensToServers(servers) |
95 | 72 | ||
96 | await uploadVideo(localServer.url, localServer.accessToken, { name: 'video 1 server 2' }) | 73 | await localServer.videos.upload({ attributes: { name: 'video 1 server 2' } }) |
97 | 74 | ||
98 | await waitJobs(servers) | 75 | await waitJobs(servers) |
99 | 76 | ||
100 | // Server 1 and server 2 follow each other | 77 | // Server 1 and server 2 follow each other |
101 | await follow(remoteServer.url, [ localServer.url ], remoteServer.accessToken) | 78 | await remoteServer.follows.follow({ hosts: [ localServer.url ] }) |
102 | await waitJobs(servers) | 79 | await waitJobs(servers) |
103 | await updateRedundancy(remoteServer.url, remoteServer.accessToken, localServer.host, true) | 80 | await remoteServer.redundancy.updateRedundancy({ host: localServer.host, redundancyAllowed: true }) |
104 | 81 | ||
105 | await waitJobs(servers) | 82 | await waitJobs(servers) |
106 | }) | 83 | }) |
@@ -109,7 +86,7 @@ describe('Test redundancy constraints', function () { | |||
109 | this.timeout(120000) | 86 | this.timeout(120000) |
110 | 87 | ||
111 | await waitJobs(servers) | 88 | await waitJobs(servers) |
112 | await waitUntilLog(remoteServer, 'Duplicated ', 5) | 89 | await remoteServer.servers.waitUntilLog('Duplicated ', 5) |
113 | await waitJobs(servers) | 90 | await waitJobs(servers) |
114 | 91 | ||
115 | { | 92 | { |
@@ -134,11 +111,11 @@ describe('Test redundancy constraints', function () { | |||
134 | } | 111 | } |
135 | } | 112 | } |
136 | await killallServers([ localServer ]) | 113 | await killallServers([ localServer ]) |
137 | await reRunServer(localServer, config) | 114 | await localServer.run(config) |
138 | 115 | ||
139 | await uploadWrapper('video 2 server 2') | 116 | await uploadWrapper('video 2 server 2') |
140 | 117 | ||
141 | await waitUntilLog(remoteServer, 'Duplicated ', 10) | 118 | await remoteServer.servers.waitUntilLog('Duplicated ', 10) |
142 | await waitJobs(servers) | 119 | await waitJobs(servers) |
143 | 120 | ||
144 | { | 121 | { |
@@ -163,11 +140,11 @@ describe('Test redundancy constraints', function () { | |||
163 | } | 140 | } |
164 | } | 141 | } |
165 | await killallServers([ localServer ]) | 142 | await killallServers([ localServer ]) |
166 | await reRunServer(localServer, config) | 143 | await localServer.run(config) |
167 | 144 | ||
168 | await uploadWrapper('video 3 server 2') | 145 | await uploadWrapper('video 3 server 2') |
169 | 146 | ||
170 | await waitUntilLog(remoteServer, 'Duplicated ', 15) | 147 | await remoteServer.servers.waitUntilLog('Duplicated ', 15) |
171 | await waitJobs(servers) | 148 | await waitJobs(servers) |
172 | 149 | ||
173 | { | 150 | { |
@@ -184,11 +161,11 @@ describe('Test redundancy constraints', function () { | |||
184 | it('Should have redundancy on server 1 and on server 2 with followings filter now server 2 follows server 1', async function () { | 161 | it('Should have redundancy on server 1 and on server 2 with followings filter now server 2 follows server 1', async function () { |
185 | this.timeout(120000) | 162 | this.timeout(120000) |
186 | 163 | ||
187 | await follow(localServer.url, [ remoteServer.url ], localServer.accessToken) | 164 | await localServer.follows.follow({ hosts: [ remoteServer.url ] }) |
188 | await waitJobs(servers) | 165 | await waitJobs(servers) |
189 | 166 | ||
190 | await uploadWrapper('video 4 server 2') | 167 | await uploadWrapper('video 4 server 2') |
191 | await waitUntilLog(remoteServer, 'Duplicated ', 20) | 168 | await remoteServer.servers.waitUntilLog('Duplicated ', 20) |
192 | await waitJobs(servers) | 169 | await waitJobs(servers) |
193 | 170 | ||
194 | { | 171 | { |
diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index 0e0a73b9d..a6559d304 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts | |||
@@ -5,51 +5,29 @@ import * as chai from 'chai' | |||
5 | import { readdir } from 'fs-extra' | 5 | import { readdir } from 'fs-extra' |
6 | import * as magnetUtil from 'magnet-uri' | 6 | import * as magnetUtil from 'magnet-uri' |
7 | import { join } from 'path' | 7 | import { join } from 'path' |
8 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
9 | import { | 8 | import { |
10 | checkSegmentHash, | 9 | checkSegmentHash, |
11 | checkVideoFilesWereRemoved, | 10 | checkVideoFilesWereRemoved, |
12 | cleanupTests, | 11 | cleanupTests, |
12 | createMultipleServers, | ||
13 | doubleFollow, | 13 | doubleFollow, |
14 | flushAndRunMultipleServers, | ||
15 | getFollowingListPaginationAndSort, | ||
16 | getVideo, | ||
17 | getVideoWithToken, | ||
18 | immutableAssign, | ||
19 | killallServers, | 14 | killallServers, |
20 | makeGetRequest, | 15 | makeGetRequest, |
21 | removeVideo, | 16 | PeerTubeServer, |
22 | reRunServer, | ||
23 | root, | 17 | root, |
24 | ServerInfo, | ||
25 | setAccessTokensToServers, | 18 | setAccessTokensToServers, |
26 | unfollow, | ||
27 | updateVideo, | ||
28 | uploadVideo, | ||
29 | viewVideo, | ||
30 | wait, | 19 | wait, |
31 | waitUntilLog | 20 | waitJobs |
32 | } from '../../../../shared/extra-utils' | 21 | } from '@shared/extra-utils' |
33 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | 22 | import { HttpStatusCode, VideoPrivacy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '@shared/models' |
34 | import { | ||
35 | addVideoRedundancy, | ||
36 | listVideoRedundancies, | ||
37 | removeVideoRedundancy, | ||
38 | updateRedundancy | ||
39 | } from '../../../../shared/extra-utils/server/redundancy' | ||
40 | import { getStats } from '../../../../shared/extra-utils/server/stats' | ||
41 | import { ActorFollow } from '../../../../shared/models/actors' | ||
42 | import { VideoRedundancy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '../../../../shared/models/redundancy' | ||
43 | import { ServerStats } from '../../../../shared/models/server/server-stats.model' | ||
44 | import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos' | ||
45 | 23 | ||
46 | const expect = chai.expect | 24 | const expect = chai.expect |
47 | 25 | ||
48 | let servers: ServerInfo[] = [] | 26 | let servers: PeerTubeServer[] = [] |
49 | let video1Server2UUID: string | 27 | let video1Server2UUID: string |
50 | let video1Server2Id: number | 28 | let video1Server2Id: number |
51 | 29 | ||
52 | function checkMagnetWebseeds (file: { magnetUri: string, resolution: { id: number } }, baseWebseeds: string[], server: ServerInfo) { | 30 | function checkMagnetWebseeds (file: { magnetUri: string, resolution: { id: number } }, baseWebseeds: string[], server: PeerTubeServer) { |
53 | const parsed = magnetUtil.decode(file.magnetUri) | 31 | const parsed = magnetUtil.decode(file.magnetUri) |
54 | 32 | ||
55 | for (const ws of baseWebseeds) { | 33 | for (const ws of baseWebseeds) { |
@@ -60,16 +38,18 @@ function checkMagnetWebseeds (file: { magnetUri: string, resolution: { id: numbe | |||
60 | expect(parsed.urlList).to.have.lengthOf(baseWebseeds.length) | 38 | expect(parsed.urlList).to.have.lengthOf(baseWebseeds.length) |
61 | } | 39 | } |
62 | 40 | ||
63 | async function flushAndRunServers (strategy: VideoRedundancyStrategy | null, additionalParams: any = {}, withWebtorrent = true) { | 41 | async function createSingleServers (strategy: VideoRedundancyStrategy | null, additionalParams: any = {}, withWebtorrent = true) { |
64 | const strategies: any[] = [] | 42 | const strategies: any[] = [] |
65 | 43 | ||
66 | if (strategy !== null) { | 44 | if (strategy !== null) { |
67 | strategies.push( | 45 | strategies.push( |
68 | immutableAssign({ | 46 | { |
69 | min_lifetime: '1 hour', | 47 | min_lifetime: '1 hour', |
70 | strategy: strategy, | 48 | strategy: strategy, |
71 | size: '400KB' | 49 | size: '400KB', |
72 | }, additionalParams) | 50 | |
51 | ...additionalParams | ||
52 | } | ||
73 | ) | 53 | ) |
74 | } | 54 | } |
75 | 55 | ||
@@ -90,17 +70,17 @@ async function flushAndRunServers (strategy: VideoRedundancyStrategy | null, add | |||
90 | } | 70 | } |
91 | } | 71 | } |
92 | 72 | ||
93 | servers = await flushAndRunMultipleServers(3, config) | 73 | servers = await createMultipleServers(3, config) |
94 | 74 | ||
95 | // Get the access tokens | 75 | // Get the access tokens |
96 | await setAccessTokensToServers(servers) | 76 | await setAccessTokensToServers(servers) |
97 | 77 | ||
98 | { | 78 | { |
99 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' }) | 79 | const { uuid, id } = await servers[1].videos.upload({ attributes: { name: 'video 1 server 2' } }) |
100 | video1Server2UUID = res.body.video.uuid | 80 | video1Server2UUID = uuid |
101 | video1Server2Id = res.body.video.id | 81 | video1Server2Id = id |
102 | 82 | ||
103 | await viewVideo(servers[1].url, video1Server2UUID) | 83 | await servers[1].videos.view({ id: video1Server2UUID }) |
104 | } | 84 | } |
105 | 85 | ||
106 | await waitJobs(servers) | 86 | await waitJobs(servers) |
@@ -124,9 +104,8 @@ async function check1WebSeed (videoUUID?: string) { | |||
124 | 104 | ||
125 | for (const server of servers) { | 105 | for (const server of servers) { |
126 | // With token to avoid issues with video follow constraints | 106 | // With token to avoid issues with video follow constraints |
127 | const res = await getVideoWithToken(server.url, server.accessToken, videoUUID) | 107 | const video = await server.videos.getWithToken({ id: videoUUID }) |
128 | 108 | ||
129 | const video: VideoDetails = res.body | ||
130 | for (const f of video.files) { | 109 | for (const f of video.files) { |
131 | checkMagnetWebseeds(f, webseeds, server) | 110 | checkMagnetWebseeds(f, webseeds, server) |
132 | } | 111 | } |
@@ -142,22 +121,20 @@ async function check2Webseeds (videoUUID?: string) { | |||
142 | ] | 121 | ] |
143 | 122 | ||
144 | for (const server of servers) { | 123 | for (const server of servers) { |
145 | const res = await getVideo(server.url, videoUUID) | 124 | const video = await server.videos.get({ id: videoUUID }) |
146 | |||
147 | const video: VideoDetails = res.body | ||
148 | 125 | ||
149 | for (const file of video.files) { | 126 | for (const file of video.files) { |
150 | checkMagnetWebseeds(file, webseeds, server) | 127 | checkMagnetWebseeds(file, webseeds, server) |
151 | 128 | ||
152 | await makeGetRequest({ | 129 | await makeGetRequest({ |
153 | url: servers[0].url, | 130 | url: servers[0].url, |
154 | statusCodeExpected: HttpStatusCode.OK_200, | 131 | expectedStatus: HttpStatusCode.OK_200, |
155 | path: '/static/redundancy/' + `${videoUUID}-${file.resolution.id}.mp4`, | 132 | path: '/static/redundancy/' + `${videoUUID}-${file.resolution.id}.mp4`, |
156 | contentType: null | 133 | contentType: null |
157 | }) | 134 | }) |
158 | await makeGetRequest({ | 135 | await makeGetRequest({ |
159 | url: servers[1].url, | 136 | url: servers[1].url, |
160 | statusCodeExpected: HttpStatusCode.OK_200, | 137 | expectedStatus: HttpStatusCode.OK_200, |
161 | path: `/static/webseed/${videoUUID}-${file.resolution.id}.mp4`, | 138 | path: `/static/webseed/${videoUUID}-${file.resolution.id}.mp4`, |
162 | contentType: null | 139 | contentType: null |
163 | }) | 140 | }) |
@@ -184,8 +161,7 @@ async function check0PlaylistRedundancies (videoUUID?: string) { | |||
184 | 161 | ||
185 | for (const server of servers) { | 162 | for (const server of servers) { |
186 | // With token to avoid issues with video follow constraints | 163 | // With token to avoid issues with video follow constraints |
187 | const res = await getVideoWithToken(server.url, server.accessToken, videoUUID) | 164 | const video = await server.videos.getWithToken({ id: videoUUID }) |
188 | const video: VideoDetails = res.body | ||
189 | 165 | ||
190 | expect(video.streamingPlaylists).to.be.an('array') | 166 | expect(video.streamingPlaylists).to.be.an('array') |
191 | expect(video.streamingPlaylists).to.have.lengthOf(1) | 167 | expect(video.streamingPlaylists).to.have.lengthOf(1) |
@@ -197,8 +173,7 @@ async function check1PlaylistRedundancies (videoUUID?: string) { | |||
197 | if (!videoUUID) videoUUID = video1Server2UUID | 173 | if (!videoUUID) videoUUID = video1Server2UUID |
198 | 174 | ||
199 | for (const server of servers) { | 175 | for (const server of servers) { |
200 | const res = await getVideo(server.url, videoUUID) | 176 | const video = await server.videos.get({ id: videoUUID }) |
201 | const video: VideoDetails = res.body | ||
202 | 177 | ||
203 | expect(video.streamingPlaylists).to.have.lengthOf(1) | 178 | expect(video.streamingPlaylists).to.have.lengthOf(1) |
204 | expect(video.streamingPlaylists[0].redundancies).to.have.lengthOf(1) | 179 | expect(video.streamingPlaylists[0].redundancies).to.have.lengthOf(1) |
@@ -211,11 +186,11 @@ async function check1PlaylistRedundancies (videoUUID?: string) { | |||
211 | const baseUrlPlaylist = servers[1].url + '/static/streaming-playlists/hls' | 186 | const baseUrlPlaylist = servers[1].url + '/static/streaming-playlists/hls' |
212 | const baseUrlSegment = servers[0].url + '/static/redundancy/hls' | 187 | const baseUrlSegment = servers[0].url + '/static/redundancy/hls' |
213 | 188 | ||
214 | const res = await getVideo(servers[0].url, videoUUID) | 189 | const video = await servers[0].videos.get({ id: videoUUID }) |
215 | const hlsPlaylist = (res.body as VideoDetails).streamingPlaylists[0] | 190 | const hlsPlaylist = video.streamingPlaylists[0] |
216 | 191 | ||
217 | for (const resolution of [ 240, 360, 480, 720 ]) { | 192 | for (const resolution of [ 240, 360, 480, 720 ]) { |
218 | await checkSegmentHash(baseUrlPlaylist, baseUrlSegment, videoUUID, resolution, hlsPlaylist) | 193 | await checkSegmentHash({ server: servers[1], baseUrlPlaylist, baseUrlSegment, videoUUID, resolution, hlsPlaylist }) |
219 | } | 194 | } |
220 | 195 | ||
221 | const directories = [ | 196 | const directories = [ |
@@ -244,9 +219,7 @@ async function checkStatsGlobal (strategy: VideoRedundancyStrategyWithManual) { | |||
244 | statsLength = 2 | 219 | statsLength = 2 |
245 | } | 220 | } |
246 | 221 | ||
247 | const res = await getStats(servers[0].url) | 222 | const data = await servers[0].stats.get() |
248 | const data: ServerStats = res.body | ||
249 | |||
250 | expect(data.videosRedundancy).to.have.lengthOf(statsLength) | 223 | expect(data.videosRedundancy).to.have.lengthOf(statsLength) |
251 | 224 | ||
252 | const stat = data.videosRedundancy[0] | 225 | const stat = data.videosRedundancy[0] |
@@ -272,14 +245,20 @@ async function checkStatsWithoutRedundancy (strategy: VideoRedundancyStrategyWit | |||
272 | expect(stat.totalVideos).to.equal(0) | 245 | expect(stat.totalVideos).to.equal(0) |
273 | } | 246 | } |
274 | 247 | ||
275 | async function enableRedundancyOnServer1 () { | 248 | async function findServerFollows () { |
276 | await updateRedundancy(servers[0].url, servers[0].accessToken, servers[1].host, true) | 249 | const body = await servers[0].follows.getFollowings({ start: 0, count: 5, sort: '-createdAt' }) |
277 | 250 | const follows = body.data | |
278 | const res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 5, sort: '-createdAt' }) | ||
279 | const follows: ActorFollow[] = res.body.data | ||
280 | const server2 = follows.find(f => f.following.host === `localhost:${servers[1].port}`) | 251 | const server2 = follows.find(f => f.following.host === `localhost:${servers[1].port}`) |
281 | const server3 = follows.find(f => f.following.host === `localhost:${servers[2].port}`) | 252 | const server3 = follows.find(f => f.following.host === `localhost:${servers[2].port}`) |
282 | 253 | ||
254 | return { server2, server3 } | ||
255 | } | ||
256 | |||
257 | async function enableRedundancyOnServer1 () { | ||
258 | await servers[0].redundancy.updateRedundancy({ host: servers[1].host, redundancyAllowed: true }) | ||
259 | |||
260 | const { server2, server3 } = await findServerFollows() | ||
261 | |||
283 | expect(server3).to.not.be.undefined | 262 | expect(server3).to.not.be.undefined |
284 | expect(server3.following.hostRedundancyAllowed).to.be.false | 263 | expect(server3.following.hostRedundancyAllowed).to.be.false |
285 | 264 | ||
@@ -288,12 +267,9 @@ async function enableRedundancyOnServer1 () { | |||
288 | } | 267 | } |
289 | 268 | ||
290 | async function disableRedundancyOnServer1 () { | 269 | async function disableRedundancyOnServer1 () { |
291 | await updateRedundancy(servers[0].url, servers[0].accessToken, servers[1].host, false) | 270 | await servers[0].redundancy.updateRedundancy({ host: servers[1].host, redundancyAllowed: false }) |
292 | 271 | ||
293 | const res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 5, sort: '-createdAt' }) | 272 | const { server2, server3 } = await findServerFollows() |
294 | const follows: ActorFollow[] = res.body.data | ||
295 | const server2 = follows.find(f => f.following.host === `localhost:${servers[1].port}`) | ||
296 | const server3 = follows.find(f => f.following.host === `localhost:${servers[2].port}`) | ||
297 | 273 | ||
298 | expect(server3).to.not.be.undefined | 274 | expect(server3).to.not.be.undefined |
299 | expect(server3.following.hostRedundancyAllowed).to.be.false | 275 | expect(server3.following.hostRedundancyAllowed).to.be.false |
@@ -310,7 +286,7 @@ describe('Test videos redundancy', function () { | |||
310 | before(function () { | 286 | before(function () { |
311 | this.timeout(120000) | 287 | this.timeout(120000) |
312 | 288 | ||
313 | return flushAndRunServers(strategy) | 289 | return createSingleServers(strategy) |
314 | }) | 290 | }) |
315 | 291 | ||
316 | it('Should have 1 webseed on the first video', async function () { | 292 | it('Should have 1 webseed on the first video', async function () { |
@@ -327,7 +303,7 @@ describe('Test videos redundancy', function () { | |||
327 | this.timeout(80000) | 303 | this.timeout(80000) |
328 | 304 | ||
329 | await waitJobs(servers) | 305 | await waitJobs(servers) |
330 | await waitUntilLog(servers[0], 'Duplicated ', 5) | 306 | await servers[0].servers.waitUntilLog('Duplicated ', 5) |
331 | await waitJobs(servers) | 307 | await waitJobs(servers) |
332 | 308 | ||
333 | await check2Webseeds() | 309 | await check2Webseeds() |
@@ -346,7 +322,7 @@ describe('Test videos redundancy', function () { | |||
346 | await check1WebSeed() | 322 | await check1WebSeed() |
347 | await check0PlaylistRedundancies() | 323 | await check0PlaylistRedundancies() |
348 | 324 | ||
349 | await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].internalServerNumber, [ 'videos', join('playlists', 'hls') ]) | 325 | await checkVideoFilesWereRemoved(video1Server2UUID, servers[0], [ 'videos', join('playlists', 'hls') ]) |
350 | }) | 326 | }) |
351 | 327 | ||
352 | after(async function () { | 328 | after(async function () { |
@@ -360,7 +336,7 @@ describe('Test videos redundancy', function () { | |||
360 | before(function () { | 336 | before(function () { |
361 | this.timeout(120000) | 337 | this.timeout(120000) |
362 | 338 | ||
363 | return flushAndRunServers(strategy) | 339 | return createSingleServers(strategy) |
364 | }) | 340 | }) |
365 | 341 | ||
366 | it('Should have 1 webseed on the first video', async function () { | 342 | it('Should have 1 webseed on the first video', async function () { |
@@ -377,7 +353,7 @@ describe('Test videos redundancy', function () { | |||
377 | this.timeout(80000) | 353 | this.timeout(80000) |
378 | 354 | ||
379 | await waitJobs(servers) | 355 | await waitJobs(servers) |
380 | await waitUntilLog(servers[0], 'Duplicated ', 5) | 356 | await servers[0].servers.waitUntilLog('Duplicated ', 5) |
381 | await waitJobs(servers) | 357 | await waitJobs(servers) |
382 | 358 | ||
383 | await check2Webseeds() | 359 | await check2Webseeds() |
@@ -388,7 +364,7 @@ describe('Test videos redundancy', function () { | |||
388 | it('Should unfollow on server 1 and remove duplicated videos', async function () { | 364 | it('Should unfollow on server 1 and remove duplicated videos', async function () { |
389 | this.timeout(80000) | 365 | this.timeout(80000) |
390 | 366 | ||
391 | await unfollow(servers[0].url, servers[0].accessToken, servers[1]) | 367 | await servers[0].follows.unfollow({ target: servers[1] }) |
392 | 368 | ||
393 | await waitJobs(servers) | 369 | await waitJobs(servers) |
394 | await wait(5000) | 370 | await wait(5000) |
@@ -396,7 +372,7 @@ describe('Test videos redundancy', function () { | |||
396 | await check1WebSeed() | 372 | await check1WebSeed() |
397 | await check0PlaylistRedundancies() | 373 | await check0PlaylistRedundancies() |
398 | 374 | ||
399 | await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].internalServerNumber, [ 'videos' ]) | 375 | await checkVideoFilesWereRemoved(video1Server2UUID, servers[0], [ 'videos' ]) |
400 | }) | 376 | }) |
401 | 377 | ||
402 | after(async function () { | 378 | after(async function () { |
@@ -410,7 +386,7 @@ describe('Test videos redundancy', function () { | |||
410 | before(function () { | 386 | before(function () { |
411 | this.timeout(120000) | 387 | this.timeout(120000) |
412 | 388 | ||
413 | return flushAndRunServers(strategy, { min_views: 3 }) | 389 | return createSingleServers(strategy, { min_views: 3 }) |
414 | }) | 390 | }) |
415 | 391 | ||
416 | it('Should have 1 webseed on the first video', async function () { | 392 | it('Should have 1 webseed on the first video', async function () { |
@@ -438,8 +414,8 @@ describe('Test videos redundancy', function () { | |||
438 | it('Should view 2 times the first video to have > min_views config', async function () { | 414 | it('Should view 2 times the first video to have > min_views config', async function () { |
439 | this.timeout(80000) | 415 | this.timeout(80000) |
440 | 416 | ||
441 | await viewVideo(servers[0].url, video1Server2UUID) | 417 | await servers[0].videos.view({ id: video1Server2UUID }) |
442 | await viewVideo(servers[2].url, video1Server2UUID) | 418 | await servers[2].videos.view({ id: video1Server2UUID }) |
443 | 419 | ||
444 | await wait(10000) | 420 | await wait(10000) |
445 | await waitJobs(servers) | 421 | await waitJobs(servers) |
@@ -449,7 +425,7 @@ describe('Test videos redundancy', function () { | |||
449 | this.timeout(80000) | 425 | this.timeout(80000) |
450 | 426 | ||
451 | await waitJobs(servers) | 427 | await waitJobs(servers) |
452 | await waitUntilLog(servers[0], 'Duplicated ', 5) | 428 | await servers[0].servers.waitUntilLog('Duplicated ', 5) |
453 | await waitJobs(servers) | 429 | await waitJobs(servers) |
454 | 430 | ||
455 | await check2Webseeds() | 431 | await check2Webseeds() |
@@ -460,12 +436,12 @@ describe('Test videos redundancy', function () { | |||
460 | it('Should remove the video and the redundancy files', async function () { | 436 | it('Should remove the video and the redundancy files', async function () { |
461 | this.timeout(20000) | 437 | this.timeout(20000) |
462 | 438 | ||
463 | await removeVideo(servers[1].url, servers[1].accessToken, video1Server2UUID) | 439 | await servers[1].videos.remove({ id: video1Server2UUID }) |
464 | 440 | ||
465 | await waitJobs(servers) | 441 | await waitJobs(servers) |
466 | 442 | ||
467 | for (const server of servers) { | 443 | for (const server of servers) { |
468 | await checkVideoFilesWereRemoved(video1Server2UUID, server.internalServerNumber) | 444 | await checkVideoFilesWereRemoved(video1Server2UUID, server) |
469 | } | 445 | } |
470 | }) | 446 | }) |
471 | 447 | ||
@@ -480,7 +456,7 @@ describe('Test videos redundancy', function () { | |||
480 | before(async function () { | 456 | before(async function () { |
481 | this.timeout(120000) | 457 | this.timeout(120000) |
482 | 458 | ||
483 | await flushAndRunServers(strategy, { min_views: 3 }, false) | 459 | await createSingleServers(strategy, { min_views: 3 }, false) |
484 | }) | 460 | }) |
485 | 461 | ||
486 | it('Should have 0 playlist redundancy on the first video', async function () { | 462 | it('Should have 0 playlist redundancy on the first video', async function () { |
@@ -506,14 +482,14 @@ describe('Test videos redundancy', function () { | |||
506 | it('Should have 1 redundancy on the first video', async function () { | 482 | it('Should have 1 redundancy on the first video', async function () { |
507 | this.timeout(160000) | 483 | this.timeout(160000) |
508 | 484 | ||
509 | await viewVideo(servers[0].url, video1Server2UUID) | 485 | await servers[0].videos.view({ id: video1Server2UUID }) |
510 | await viewVideo(servers[2].url, video1Server2UUID) | 486 | await servers[2].videos.view({ id: video1Server2UUID }) |
511 | 487 | ||
512 | await wait(10000) | 488 | await wait(10000) |
513 | await waitJobs(servers) | 489 | await waitJobs(servers) |
514 | 490 | ||
515 | await waitJobs(servers) | 491 | await waitJobs(servers) |
516 | await waitUntilLog(servers[0], 'Duplicated ', 1) | 492 | await servers[0].servers.waitUntilLog('Duplicated ', 1) |
517 | await waitJobs(servers) | 493 | await waitJobs(servers) |
518 | 494 | ||
519 | await check1PlaylistRedundancies() | 495 | await check1PlaylistRedundancies() |
@@ -523,12 +499,12 @@ describe('Test videos redundancy', function () { | |||
523 | it('Should remove the video and the redundancy files', async function () { | 499 | it('Should remove the video and the redundancy files', async function () { |
524 | this.timeout(20000) | 500 | this.timeout(20000) |
525 | 501 | ||
526 | await removeVideo(servers[1].url, servers[1].accessToken, video1Server2UUID) | 502 | await servers[1].videos.remove({ id: video1Server2UUID }) |
527 | 503 | ||
528 | await waitJobs(servers) | 504 | await waitJobs(servers) |
529 | 505 | ||
530 | for (const server of servers) { | 506 | for (const server of servers) { |
531 | await checkVideoFilesWereRemoved(video1Server2UUID, server.internalServerNumber) | 507 | await checkVideoFilesWereRemoved(video1Server2UUID, server) |
532 | } | 508 | } |
533 | }) | 509 | }) |
534 | 510 | ||
@@ -541,7 +517,7 @@ describe('Test videos redundancy', function () { | |||
541 | before(function () { | 517 | before(function () { |
542 | this.timeout(120000) | 518 | this.timeout(120000) |
543 | 519 | ||
544 | return flushAndRunServers(null) | 520 | return createSingleServers(null) |
545 | }) | 521 | }) |
546 | 522 | ||
547 | it('Should have 1 webseed on the first video', async function () { | 523 | it('Should have 1 webseed on the first video', async function () { |
@@ -551,18 +527,14 @@ describe('Test videos redundancy', function () { | |||
551 | }) | 527 | }) |
552 | 528 | ||
553 | it('Should create a redundancy on first video', async function () { | 529 | it('Should create a redundancy on first video', async function () { |
554 | await addVideoRedundancy({ | 530 | await servers[0].redundancy.addVideo({ videoId: video1Server2Id }) |
555 | url: servers[0].url, | ||
556 | accessToken: servers[0].accessToken, | ||
557 | videoId: video1Server2Id | ||
558 | }) | ||
559 | }) | 531 | }) |
560 | 532 | ||
561 | it('Should have 2 webseeds on the first video', async function () { | 533 | it('Should have 2 webseeds on the first video', async function () { |
562 | this.timeout(80000) | 534 | this.timeout(80000) |
563 | 535 | ||
564 | await waitJobs(servers) | 536 | await waitJobs(servers) |
565 | await waitUntilLog(servers[0], 'Duplicated ', 5) | 537 | await servers[0].servers.waitUntilLog('Duplicated ', 5) |
566 | await waitJobs(servers) | 538 | await waitJobs(servers) |
567 | 539 | ||
568 | await check2Webseeds() | 540 | await check2Webseeds() |
@@ -573,22 +545,15 @@ describe('Test videos redundancy', function () { | |||
573 | it('Should manually remove redundancies on server 1 and remove duplicated videos', async function () { | 545 | it('Should manually remove redundancies on server 1 and remove duplicated videos', async function () { |
574 | this.timeout(80000) | 546 | this.timeout(80000) |
575 | 547 | ||
576 | const res = await listVideoRedundancies({ | 548 | const body = await servers[0].redundancy.listVideos({ target: 'remote-videos' }) |
577 | url: servers[0].url, | ||
578 | accessToken: servers[0].accessToken, | ||
579 | target: 'remote-videos' | ||
580 | }) | ||
581 | 549 | ||
582 | const videos = res.body.data as VideoRedundancy[] | 550 | const videos = body.data |
583 | expect(videos).to.have.lengthOf(1) | 551 | expect(videos).to.have.lengthOf(1) |
584 | 552 | ||
585 | const video = videos[0] | 553 | const video = videos[0] |
554 | |||
586 | for (const r of video.redundancies.files.concat(video.redundancies.streamingPlaylists)) { | 555 | for (const r of video.redundancies.files.concat(video.redundancies.streamingPlaylists)) { |
587 | await removeVideoRedundancy({ | 556 | await servers[0].redundancy.removeVideo({ redundancyId: r.id }) |
588 | url: servers[0].url, | ||
589 | accessToken: servers[0].accessToken, | ||
590 | redundancyId: r.id | ||
591 | }) | ||
592 | } | 557 | } |
593 | 558 | ||
594 | await waitJobs(servers) | 559 | await waitJobs(servers) |
@@ -597,7 +562,7 @@ describe('Test videos redundancy', function () { | |||
597 | await check1WebSeed() | 562 | await check1WebSeed() |
598 | await check0PlaylistRedundancies() | 563 | await check0PlaylistRedundancies() |
599 | 564 | ||
600 | await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ 'videos' ]) | 565 | await checkVideoFilesWereRemoved(video1Server2UUID, servers[0], [ 'videos' ]) |
601 | }) | 566 | }) |
602 | 567 | ||
603 | after(async function () { | 568 | after(async function () { |
@@ -608,10 +573,9 @@ describe('Test videos redundancy', function () { | |||
608 | describe('Test expiration', function () { | 573 | describe('Test expiration', function () { |
609 | const strategy = 'recently-added' | 574 | const strategy = 'recently-added' |
610 | 575 | ||
611 | async function checkContains (servers: ServerInfo[], str: string) { | 576 | async function checkContains (servers: PeerTubeServer[], str: string) { |
612 | for (const server of servers) { | 577 | for (const server of servers) { |
613 | const res = await getVideo(server.url, video1Server2UUID) | 578 | const video = await server.videos.get({ id: video1Server2UUID }) |
614 | const video: VideoDetails = res.body | ||
615 | 579 | ||
616 | for (const f of video.files) { | 580 | for (const f of video.files) { |
617 | expect(f.magnetUri).to.contain(str) | 581 | expect(f.magnetUri).to.contain(str) |
@@ -619,10 +583,9 @@ describe('Test videos redundancy', function () { | |||
619 | } | 583 | } |
620 | } | 584 | } |
621 | 585 | ||
622 | async function checkNotContains (servers: ServerInfo[], str: string) { | 586 | async function checkNotContains (servers: PeerTubeServer[], str: string) { |
623 | for (const server of servers) { | 587 | for (const server of servers) { |
624 | const res = await getVideo(server.url, video1Server2UUID) | 588 | const video = await server.videos.get({ id: video1Server2UUID }) |
625 | const video: VideoDetails = res.body | ||
626 | 589 | ||
627 | for (const f of video.files) { | 590 | for (const f of video.files) { |
628 | expect(f.magnetUri).to.not.contain(str) | 591 | expect(f.magnetUri).to.not.contain(str) |
@@ -633,7 +596,7 @@ describe('Test videos redundancy', function () { | |||
633 | before(async function () { | 596 | before(async function () { |
634 | this.timeout(120000) | 597 | this.timeout(120000) |
635 | 598 | ||
636 | await flushAndRunServers(strategy, { min_lifetime: '7 seconds', min_views: 0 }) | 599 | await createSingleServers(strategy, { min_lifetime: '7 seconds', min_views: 0 }) |
637 | 600 | ||
638 | await enableRedundancyOnServer1() | 601 | await enableRedundancyOnServer1() |
639 | }) | 602 | }) |
@@ -656,7 +619,7 @@ describe('Test videos redundancy', function () { | |||
656 | it('Should stop server 1 and expire video redundancy', async function () { | 619 | it('Should stop server 1 and expire video redundancy', async function () { |
657 | this.timeout(80000) | 620 | this.timeout(80000) |
658 | 621 | ||
659 | killallServers([ servers[0] ]) | 622 | await killallServers([ servers[0] ]) |
660 | 623 | ||
661 | await wait(15000) | 624 | await wait(15000) |
662 | 625 | ||
@@ -675,25 +638,25 @@ describe('Test videos redundancy', function () { | |||
675 | before(async function () { | 638 | before(async function () { |
676 | this.timeout(120000) | 639 | this.timeout(120000) |
677 | 640 | ||
678 | await flushAndRunServers(strategy, { min_lifetime: '7 seconds', min_views: 0 }) | 641 | await createSingleServers(strategy, { min_lifetime: '7 seconds', min_views: 0 }) |
679 | 642 | ||
680 | await enableRedundancyOnServer1() | 643 | await enableRedundancyOnServer1() |
681 | 644 | ||
682 | await waitJobs(servers) | 645 | await waitJobs(servers) |
683 | await waitUntilLog(servers[0], 'Duplicated ', 5) | 646 | await servers[0].servers.waitUntilLog('Duplicated ', 5) |
684 | await waitJobs(servers) | 647 | await waitJobs(servers) |
685 | 648 | ||
686 | await check2Webseeds(video1Server2UUID) | 649 | await check2Webseeds(video1Server2UUID) |
687 | await check1PlaylistRedundancies(video1Server2UUID) | 650 | await check1PlaylistRedundancies(video1Server2UUID) |
688 | await checkStatsWith1Redundancy(strategy) | 651 | await checkStatsWith1Redundancy(strategy) |
689 | 652 | ||
690 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 2 server 2', privacy: VideoPrivacy.PRIVATE }) | 653 | const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video 2 server 2', privacy: VideoPrivacy.PRIVATE } }) |
691 | video2Server2UUID = res.body.video.uuid | 654 | video2Server2UUID = uuid |
692 | 655 | ||
693 | // Wait transcoding before federation | 656 | // Wait transcoding before federation |
694 | await waitJobs(servers) | 657 | await waitJobs(servers) |
695 | 658 | ||
696 | await updateVideo(servers[1].url, servers[1].accessToken, video2Server2UUID, { privacy: VideoPrivacy.PUBLIC }) | 659 | await servers[1].videos.update({ id: video2Server2UUID, attributes: { privacy: VideoPrivacy.PUBLIC } }) |
697 | }) | 660 | }) |
698 | 661 | ||
699 | it('Should cache video 2 webseeds on the first video', async function () { | 662 | it('Should cache video 2 webseeds on the first video', async function () { |
@@ -725,8 +688,8 @@ describe('Test videos redundancy', function () { | |||
725 | 688 | ||
726 | await waitJobs(servers) | 689 | await waitJobs(servers) |
727 | 690 | ||
728 | killallServers([ servers[0] ]) | 691 | await killallServers([ servers[0] ]) |
729 | await reRunServer(servers[0], { | 692 | await servers[0].run({ |
730 | redundancy: { | 693 | redundancy: { |
731 | videos: { | 694 | videos: { |
732 | check_interval: '1 second', | 695 | check_interval: '1 second', |
@@ -737,7 +700,7 @@ describe('Test videos redundancy', function () { | |||
737 | 700 | ||
738 | await waitJobs(servers) | 701 | await waitJobs(servers) |
739 | 702 | ||
740 | await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].internalServerNumber, [ join('redundancy', 'hls') ]) | 703 | await checkVideoFilesWereRemoved(video1Server2UUID, servers[0], [ join('redundancy', 'hls') ]) |
741 | }) | 704 | }) |
742 | 705 | ||
743 | after(async function () { | 706 | after(async function () { |