aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/object-storage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-05-23 10:49:45 +0200
committerChocobozzz <me@florianbigard.com>2023-05-23 10:49:45 +0200
commitf89189907bbdff6c4bc6d3460ed9ef4c49515f17 (patch)
treec55e50e3fc02ae9b3f2d1d19d95160af98cc7d7c /server/tests/api/object-storage
parent41cde76bbf5ac16a90b5f158672523069db74009 (diff)
downloadPeerTube-f89189907bbdff6c4bc6d3460ed9ef4c49515f17.tar.gz
PeerTube-f89189907bbdff6c4bc6d3460ed9ef4c49515f17.tar.zst
PeerTube-f89189907bbdff6c4bc6d3460ed9ef4c49515f17.zip
Prevent object storage mock conflicts
When running tests in parallel
Diffstat (limited to 'server/tests/api/object-storage')
-rw-r--r--server/tests/api/object-storage/live.ts58
-rw-r--r--server/tests/api/object-storage/video-imports.ts13
-rw-r--r--server/tests/api/object-storage/videos.ts50
3 files changed, 65 insertions, 56 deletions
diff --git a/server/tests/api/object-storage/live.ts b/server/tests/api/object-storage/live.ts
index 7f8db40e5..07ff4763b 100644
--- a/server/tests/api/object-storage/live.ts
+++ b/server/tests/api/object-storage/live.ts
@@ -36,7 +36,14 @@ async function createLive (server: PeerTubeServer, permanent: boolean) {
36 return uuid 36 return uuid
37} 37}
38 38
39async function checkFilesExist (servers: PeerTubeServer[], videoUUID: string, numberOfFiles: number) { 39async function checkFilesExist (options: {
40 servers: PeerTubeServer[]
41 videoUUID: string
42 numberOfFiles: number
43 objectStorage: ObjectStorageCommand
44}) {
45 const { servers, videoUUID, numberOfFiles, objectStorage } = options
46
40 for (const server of servers) { 47 for (const server of servers) {
41 const video = await server.videos.get({ id: videoUUID }) 48 const video = await server.videos.get({ id: videoUUID })
42 49
@@ -47,14 +54,21 @@ async function checkFilesExist (servers: PeerTubeServer[], videoUUID: string, nu
47 expect(files).to.have.lengthOf(numberOfFiles) 54 expect(files).to.have.lengthOf(numberOfFiles)
48 55
49 for (const file of files) { 56 for (const file of files) {
50 expectStartWith(file.fileUrl, ObjectStorageCommand.getMockPlaylistBaseUrl()) 57 expectStartWith(file.fileUrl, objectStorage.getMockPlaylistBaseUrl())
51 58
52 await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 }) 59 await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
53 } 60 }
54 } 61 }
55} 62}
56 63
57async function checkFilesCleanup (server: PeerTubeServer, videoUUID: string, resolutions: number[]) { 64async function checkFilesCleanup (options: {
65 server: PeerTubeServer
66 videoUUID: string
67 resolutions: number[]
68 objectStorage: ObjectStorageCommand
69}) {
70 const { server, videoUUID, resolutions, objectStorage } = options
71
58 const resolutionFiles = resolutions.map((_value, i) => `${i}.m3u8`) 72 const resolutionFiles = resolutions.map((_value, i) => `${i}.m3u8`)
59 73
60 for (const playlistName of [ 'master.m3u8' ].concat(resolutionFiles)) { 74 for (const playlistName of [ 'master.m3u8' ].concat(resolutionFiles)) {
@@ -62,7 +76,7 @@ async function checkFilesCleanup (server: PeerTubeServer, videoUUID: string, res
62 videoUUID, 76 videoUUID,
63 playlistName, 77 playlistName,
64 expectedStatus: HttpStatusCode.NOT_FOUND_404, 78 expectedStatus: HttpStatusCode.NOT_FOUND_404,
65 objectStorage: true 79 objectStorage
66 }) 80 })
67 } 81 }
68 82
@@ -70,7 +84,7 @@ async function checkFilesCleanup (server: PeerTubeServer, videoUUID: string, res
70 videoUUID, 84 videoUUID,
71 playlistNumber: 0, 85 playlistNumber: 0,
72 segment: 0, 86 segment: 0,
73 objectStorage: true, 87 objectStorage,
74 expectedStatus: HttpStatusCode.NOT_FOUND_404 88 expectedStatus: HttpStatusCode.NOT_FOUND_404
75 }) 89 })
76} 90}
@@ -80,13 +94,13 @@ describe('Object storage for lives', function () {
80 94
81 let servers: PeerTubeServer[] 95 let servers: PeerTubeServer[]
82 let sqlCommandServer1: SQLCommand 96 let sqlCommandServer1: SQLCommand
97 const objectStorage = new ObjectStorageCommand()
83 98
84 before(async function () { 99 before(async function () {
85 this.timeout(120000) 100 this.timeout(120000)
86 101
87 await ObjectStorageCommand.prepareDefaultMockBuckets() 102 await objectStorage.prepareDefaultMockBuckets()
88 103 servers = await createMultipleServers(2, objectStorage.getDefaultMockConfig())
89 servers = await createMultipleServers(2, ObjectStorageCommand.getDefaultMockConfig())
90 104
91 await setAccessTokensToServers(servers) 105 await setAccessTokensToServers(servers)
92 await setDefaultVideoChannel(servers) 106 await setDefaultVideoChannel(servers)
@@ -119,7 +133,7 @@ describe('Object storage for lives', function () {
119 liveVideoId: videoUUID, 133 liveVideoId: videoUUID,
120 resolutions: [ 720 ], 134 resolutions: [ 720 ],
121 transcoded: false, 135 transcoded: false,
122 objectStorage: true 136 objectStorage
123 }) 137 })
124 138
125 await stopFfmpeg(ffmpegCommand) 139 await stopFfmpeg(ffmpegCommand)
@@ -131,11 +145,11 @@ describe('Object storage for lives', function () {
131 await waitUntilLiveReplacedByReplayOnAllServers(servers, videoUUID) 145 await waitUntilLiveReplacedByReplayOnAllServers(servers, videoUUID)
132 await waitJobs(servers) 146 await waitJobs(servers)
133 147
134 await checkFilesExist(servers, videoUUID, 1) 148 await checkFilesExist({ servers, videoUUID, numberOfFiles: 1, objectStorage })
135 }) 149 })
136 150
137 it('Should have cleaned up live files from object storage', async function () { 151 it('Should have cleaned up live files from object storage', async function () {
138 await checkFilesCleanup(servers[0], videoUUID, [ 720 ]) 152 await checkFilesCleanup({ server: servers[0], videoUUID, resolutions: [ 720 ], objectStorage })
139 }) 153 })
140 }) 154 })
141 155
@@ -166,7 +180,7 @@ describe('Object storage for lives', function () {
166 liveVideoId: videoUUIDNonPermanent, 180 liveVideoId: videoUUIDNonPermanent,
167 resolutions, 181 resolutions,
168 transcoded: true, 182 transcoded: true,
169 objectStorage: true 183 objectStorage
170 }) 184 })
171 185
172 await stopFfmpeg(ffmpegCommand) 186 await stopFfmpeg(ffmpegCommand)
@@ -178,11 +192,11 @@ describe('Object storage for lives', function () {
178 await waitUntilLiveReplacedByReplayOnAllServers(servers, videoUUIDNonPermanent) 192 await waitUntilLiveReplacedByReplayOnAllServers(servers, videoUUIDNonPermanent)
179 await waitJobs(servers) 193 await waitJobs(servers)
180 194
181 await checkFilesExist(servers, videoUUIDNonPermanent, 5) 195 await checkFilesExist({ servers, videoUUID: videoUUIDNonPermanent, numberOfFiles: 5, objectStorage })
182 }) 196 })
183 197
184 it('Should have cleaned up live files from object storage', async function () { 198 it('Should have cleaned up live files from object storage', async function () {
185 await checkFilesCleanup(servers[0], videoUUIDNonPermanent, resolutions) 199 await checkFilesCleanup({ server: servers[0], videoUUID: videoUUIDNonPermanent, resolutions, objectStorage })
186 }) 200 })
187 }) 201 })
188 202
@@ -206,7 +220,7 @@ describe('Object storage for lives', function () {
206 liveVideoId: videoUUIDPermanent, 220 liveVideoId: videoUUIDPermanent,
207 resolutions, 221 resolutions,
208 transcoded: true, 222 transcoded: true,
209 objectStorage: true 223 objectStorage
210 }) 224 })
211 225
212 await stopFfmpeg(ffmpegCommand) 226 await stopFfmpeg(ffmpegCommand)
@@ -221,11 +235,11 @@ describe('Object storage for lives', function () {
221 const videoLiveDetails = await servers[0].videos.get({ id: videoUUIDPermanent }) 235 const videoLiveDetails = await servers[0].videos.get({ id: videoUUIDPermanent })
222 const replay = await findExternalSavedVideo(servers[0], videoLiveDetails) 236 const replay = await findExternalSavedVideo(servers[0], videoLiveDetails)
223 237
224 await checkFilesExist(servers, replay.uuid, 5) 238 await checkFilesExist({ servers, videoUUID: replay.uuid, numberOfFiles: 5, objectStorage })
225 }) 239 })
226 240
227 it('Should have cleaned up live files from object storage', async function () { 241 it('Should have cleaned up live files from object storage', async function () {
228 await checkFilesCleanup(servers[0], videoUUIDPermanent, resolutions) 242 await checkFilesCleanup({ server: servers[0], videoUUID: videoUUIDPermanent, resolutions, objectStorage })
229 }) 243 })
230 }) 244 })
231 }) 245 })
@@ -238,9 +252,10 @@ describe('Object storage for lives', function () {
238 this.timeout(120000) 252 this.timeout(120000)
239 253
240 const port = await mockObjectStorageProxy.initialize() 254 const port = await mockObjectStorageProxy.initialize()
241 baseMockUrl = `http://127.0.0.1:${port}/streaming-playlists` 255 const bucketName = objectStorage.getMockStreamingPlaylistsBucketName()
256 baseMockUrl = `http://127.0.0.1:${port}/${bucketName}`
242 257
243 await ObjectStorageCommand.createMockBucket('streaming-playlists') 258 await objectStorage.prepareDefaultMockBuckets()
244 259
245 const config = { 260 const config = {
246 object_storage: { 261 object_storage: {
@@ -251,7 +266,7 @@ describe('Object storage for lives', function () {
251 credentials: ObjectStorageCommand.getMockCredentialsConfig(), 266 credentials: ObjectStorageCommand.getMockCredentialsConfig(),
252 267
253 streaming_playlists: { 268 streaming_playlists: {
254 bucket_name: 'streaming-playlists', 269 bucket_name: bucketName,
255 prefix: '', 270 prefix: '',
256 base_url: baseMockUrl 271 base_url: baseMockUrl
257 } 272 }
@@ -279,7 +294,7 @@ describe('Object storage for lives', function () {
279 liveVideoId: videoUUIDPermanent, 294 liveVideoId: videoUUIDPermanent,
280 resolutions: [ 720 ], 295 resolutions: [ 720 ],
281 transcoded: true, 296 transcoded: true,
282 objectStorage: true, 297 objectStorage,
283 objectStorageBaseUrl: baseMockUrl 298 objectStorageBaseUrl: baseMockUrl
284 }) 299 })
285 300
@@ -289,6 +304,7 @@ describe('Object storage for lives', function () {
289 304
290 after(async function () { 305 after(async function () {
291 await sqlCommandServer1.cleanup() 306 await sqlCommandServer1.cleanup()
307 await objectStorage.cleanupMock()
292 308
293 await cleanupTests(servers) 309 await cleanupTests(servers)
294 }) 310 })
diff --git a/server/tests/api/object-storage/video-imports.ts b/server/tests/api/object-storage/video-imports.ts
index d5fd91b6a..57150e5a6 100644
--- a/server/tests/api/object-storage/video-imports.ts
+++ b/server/tests/api/object-storage/video-imports.ts
@@ -32,13 +32,14 @@ describe('Object storage for video import', function () {
32 if (areMockObjectStorageTestsDisabled()) return 32 if (areMockObjectStorageTestsDisabled()) return
33 33
34 let server: PeerTubeServer 34 let server: PeerTubeServer
35 const objectStorage = new ObjectStorageCommand()
35 36
36 before(async function () { 37 before(async function () {
37 this.timeout(120000) 38 this.timeout(120000)
38 39
39 await ObjectStorageCommand.prepareDefaultMockBuckets() 40 await objectStorage.prepareDefaultMockBuckets()
40 41
41 server = await createSingleServer(1, ObjectStorageCommand.getDefaultMockConfig()) 42 server = await createSingleServer(1, objectStorage.getDefaultMockConfig())
42 43
43 await setAccessTokensToServers([ server ]) 44 await setAccessTokensToServers([ server ])
44 await setDefaultVideoChannel([ server ]) 45 await setDefaultVideoChannel([ server ])
@@ -64,7 +65,7 @@ describe('Object storage for video import', function () {
64 expect(video.streamingPlaylists).to.have.lengthOf(0) 65 expect(video.streamingPlaylists).to.have.lengthOf(0)
65 66
66 const fileUrl = video.files[0].fileUrl 67 const fileUrl = video.files[0].fileUrl
67 expectStartWith(fileUrl, ObjectStorageCommand.getMockWebTorrentBaseUrl()) 68 expectStartWith(fileUrl, objectStorage.getMockWebVideosBaseUrl())
68 69
69 await makeRawRequest({ url: fileUrl, expectedStatus: HttpStatusCode.OK_200 }) 70 await makeRawRequest({ url: fileUrl, expectedStatus: HttpStatusCode.OK_200 })
70 }) 71 })
@@ -89,13 +90,13 @@ describe('Object storage for video import', function () {
89 expect(video.streamingPlaylists[0].files).to.have.lengthOf(5) 90 expect(video.streamingPlaylists[0].files).to.have.lengthOf(5)
90 91
91 for (const file of video.files) { 92 for (const file of video.files) {
92 expectStartWith(file.fileUrl, ObjectStorageCommand.getMockWebTorrentBaseUrl()) 93 expectStartWith(file.fileUrl, objectStorage.getMockWebVideosBaseUrl())
93 94
94 await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 }) 95 await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
95 } 96 }
96 97
97 for (const file of video.streamingPlaylists[0].files) { 98 for (const file of video.streamingPlaylists[0].files) {
98 expectStartWith(file.fileUrl, ObjectStorageCommand.getMockPlaylistBaseUrl()) 99 expectStartWith(file.fileUrl, objectStorage.getMockPlaylistBaseUrl())
99 100
100 await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 }) 101 await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
101 } 102 }
@@ -103,6 +104,8 @@ describe('Object storage for video import', function () {
103 }) 104 })
104 105
105 after(async function () { 106 after(async function () {
107 await objectStorage.cleanupMock()
108
106 await cleanupTests([ server ]) 109 await cleanupTests([ server ])
107 }) 110 })
108}) 111})
diff --git a/server/tests/api/object-storage/videos.ts b/server/tests/api/object-storage/videos.ts
index 77ed78ae1..f837d9966 100644
--- a/server/tests/api/object-storage/videos.ts
+++ b/server/tests/api/object-storage/videos.ts
@@ -145,6 +145,7 @@ function runTestSuite (options: {
145 145
146 let servers: PeerTubeServer[] 146 let servers: PeerTubeServer[]
147 let sqlCommands: SQLCommand[] = [] 147 let sqlCommands: SQLCommand[] = []
148 const objectStorage = new ObjectStorageCommand()
148 149
149 let keptUrls: string[] = [] 150 let keptUrls: string[] = []
150 151
@@ -159,8 +160,8 @@ function runTestSuite (options: {
159 ? `http://127.0.0.1:${port}` 160 ? `http://127.0.0.1:${port}`
160 : undefined 161 : undefined
161 162
162 await ObjectStorageCommand.createMockBucket(options.playlistBucket) 163 await objectStorage.createMockBucket(options.playlistBucket)
163 await ObjectStorageCommand.createMockBucket(options.webtorrentBucket) 164 await objectStorage.createMockBucket(options.webtorrentBucket)
164 165
165 const config = { 166 const config = {
166 object_storage: { 167 object_storage: {
@@ -275,6 +276,7 @@ function runTestSuite (options: {
275 276
276 after(async function () { 277 after(async function () {
277 await mockObjectStorageProxy.terminate() 278 await mockObjectStorageProxy.terminate()
279 await objectStorage.cleanupMock()
278 280
279 for (const sqlCommand of sqlCommands) { 281 for (const sqlCommand of sqlCommands) {
280 await sqlCommand.cleanup() 282 await sqlCommand.cleanup()
@@ -287,26 +289,12 @@ function runTestSuite (options: {
287describe('Object storage for videos', function () { 289describe('Object storage for videos', function () {
288 if (areMockObjectStorageTestsDisabled()) return 290 if (areMockObjectStorageTestsDisabled()) return
289 291
292 const objectStorage = new ObjectStorageCommand()
293
290 describe('Test config', function () { 294 describe('Test config', function () {
291 let server: PeerTubeServer 295 let server: PeerTubeServer
292 296
293 const baseConfig = { 297 const baseConfig = objectStorage.getDefaultMockConfig()
294 object_storage: {
295 enabled: true,
296 endpoint: 'http://' + ObjectStorageCommand.getMockEndpointHost(),
297 region: ObjectStorageCommand.getMockRegion(),
298
299 credentials: ObjectStorageCommand.getMockCredentialsConfig(),
300
301 streaming_playlists: {
302 bucket_name: ObjectStorageCommand.DEFAULT_PLAYLIST_MOCK_BUCKET
303 },
304
305 videos: {
306 bucket_name: ObjectStorageCommand.DEFAULT_WEBTORRENT_MOCK_BUCKET
307 }
308 }
309 }
310 298
311 const badCredentials = { 299 const badCredentials = {
312 access_key_id: 'AKIAIOSFODNN7EXAMPLE', 300 access_key_id: 'AKIAIOSFODNN7EXAMPLE',
@@ -334,7 +322,7 @@ describe('Object storage for videos', function () {
334 it('Should fail with bad credentials', async function () { 322 it('Should fail with bad credentials', async function () {
335 this.timeout(60000) 323 this.timeout(60000)
336 324
337 await ObjectStorageCommand.prepareDefaultMockBuckets() 325 await objectStorage.prepareDefaultMockBuckets()
338 326
339 const config = merge({}, baseConfig, { 327 const config = merge({}, baseConfig, {
340 object_storage: { 328 object_storage: {
@@ -358,7 +346,7 @@ describe('Object storage for videos', function () {
358 it('Should succeed with credentials from env', async function () { 346 it('Should succeed with credentials from env', async function () {
359 this.timeout(60000) 347 this.timeout(60000)
360 348
361 await ObjectStorageCommand.prepareDefaultMockBuckets() 349 await objectStorage.prepareDefaultMockBuckets()
362 350
363 const config = merge({}, baseConfig, { 351 const config = merge({}, baseConfig, {
364 object_storage: { 352 object_storage: {
@@ -385,25 +373,27 @@ describe('Object storage for videos', function () {
385 await waitJobs([ server ], { skipDelayed: true }) 373 await waitJobs([ server ], { skipDelayed: true })
386 const video = await server.videos.get({ id: uuid }) 374 const video = await server.videos.get({ id: uuid })
387 375
388 expectStartWith(video.files[0].fileUrl, ObjectStorageCommand.getMockWebTorrentBaseUrl()) 376 expectStartWith(video.files[0].fileUrl, objectStorage.getMockWebVideosBaseUrl())
389 }) 377 })
390 378
391 after(async function () { 379 after(async function () {
380 await objectStorage.cleanupMock()
381
392 await cleanupTests([ server ]) 382 await cleanupTests([ server ])
393 }) 383 })
394 }) 384 })
395 385
396 describe('Test simple object storage', function () { 386 describe('Test simple object storage', function () {
397 runTestSuite({ 387 runTestSuite({
398 playlistBucket: 'streaming-playlists', 388 playlistBucket: objectStorage.getMockBucketName('streaming-playlists'),
399 webtorrentBucket: 'videos' 389 webtorrentBucket: objectStorage.getMockBucketName('videos')
400 }) 390 })
401 }) 391 })
402 392
403 describe('Test object storage with prefix', function () { 393 describe('Test object storage with prefix', function () {
404 runTestSuite({ 394 runTestSuite({
405 playlistBucket: 'mybucket', 395 playlistBucket: objectStorage.getMockBucketName('mybucket'),
406 webtorrentBucket: 'mybucket', 396 webtorrentBucket: objectStorage.getMockBucketName('mybucket'),
407 397
408 playlistPrefix: 'streaming-playlists_', 398 playlistPrefix: 'streaming-playlists_',
409 webtorrentPrefix: 'webtorrent_' 399 webtorrentPrefix: 'webtorrent_'
@@ -412,8 +402,8 @@ describe('Object storage for videos', function () {
412 402
413 describe('Test object storage with prefix and base URL', function () { 403 describe('Test object storage with prefix and base URL', function () {
414 runTestSuite({ 404 runTestSuite({
415 playlistBucket: 'mybucket', 405 playlistBucket: objectStorage.getMockBucketName('mybucket'),
416 webtorrentBucket: 'mybucket', 406 webtorrentBucket: objectStorage.getMockBucketName('mybucket'),
417 407
418 playlistPrefix: 'streaming-playlists/', 408 playlistPrefix: 'streaming-playlists/',
419 webtorrentPrefix: 'webtorrent/', 409 webtorrentPrefix: 'webtorrent/',
@@ -440,8 +430,8 @@ describe('Object storage for videos', function () {
440 430
441 runTestSuite({ 431 runTestSuite({
442 maxUploadPart, 432 maxUploadPart,
443 playlistBucket: 'streaming-playlists', 433 playlistBucket: objectStorage.getMockBucketName('streaming-playlists'),
444 webtorrentBucket: 'videos', 434 webtorrentBucket: objectStorage.getMockBucketName('videos'),
445 fixture 435 fixture
446 }) 436 })
447 }) 437 })