diff options
author | Chocobozzz <me@florianbigard.com> | 2023-04-21 15:00:01 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2023-05-09 08:57:34 +0200 |
commit | d102de1b38f2877463529c3b27bd35ffef4fd8bf (patch) | |
tree | 31fa0bdf26ad7a2ee46d600d804a6f03260266c8 /server/tests/api/object-storage | |
parent | 2fe978744e5b74eb824e4d79c1bb9b840169f125 (diff) | |
download | PeerTube-d102de1b38f2877463529c3b27bd35ffef4fd8bf.tar.gz PeerTube-d102de1b38f2877463529c3b27bd35ffef4fd8bf.tar.zst PeerTube-d102de1b38f2877463529c3b27bd35ffef4fd8bf.zip |
Add runner server tests
Diffstat (limited to 'server/tests/api/object-storage')
-rw-r--r-- | server/tests/api/object-storage/live.ts | 19 | ||||
-rw-r--r-- | server/tests/api/object-storage/video-static-file-privacy.ts | 8 | ||||
-rw-r--r-- | server/tests/api/object-storage/videos.ts | 30 |
3 files changed, 38 insertions, 19 deletions
diff --git a/server/tests/api/object-storage/live.ts b/server/tests/api/object-storage/live.ts index 588e0a8d7..c430cd0a0 100644 --- a/server/tests/api/object-storage/live.ts +++ b/server/tests/api/object-storage/live.ts | |||
@@ -1,7 +1,7 @@ | |||
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 { expect } from 'chai' | 3 | import { expect } from 'chai' |
4 | import { expectStartWith, MockObjectStorageProxy, testVideoResolutions } from '@server/tests/shared' | 4 | import { expectStartWith, MockObjectStorageProxy, SQLCommand, testLiveVideoResolutions } from '@server/tests/shared' |
5 | import { areMockObjectStorageTestsDisabled } from '@shared/core-utils' | 5 | import { areMockObjectStorageTestsDisabled } from '@shared/core-utils' |
6 | import { HttpStatusCode, LiveVideoCreate, VideoPrivacy } from '@shared/models' | 6 | import { HttpStatusCode, LiveVideoCreate, VideoPrivacy } from '@shared/models' |
7 | import { | 7 | import { |
@@ -79,6 +79,7 @@ describe('Object storage for lives', function () { | |||
79 | if (areMockObjectStorageTestsDisabled()) return | 79 | if (areMockObjectStorageTestsDisabled()) return |
80 | 80 | ||
81 | let servers: PeerTubeServer[] | 81 | let servers: PeerTubeServer[] |
82 | let sqlCommandServer1: SQLCommand | ||
82 | 83 | ||
83 | before(async function () { | 84 | before(async function () { |
84 | this.timeout(120000) | 85 | this.timeout(120000) |
@@ -92,6 +93,8 @@ describe('Object storage for lives', function () { | |||
92 | await doubleFollow(servers[0], servers[1]) | 93 | await doubleFollow(servers[0], servers[1]) |
93 | 94 | ||
94 | await servers[0].config.enableTranscoding() | 95 | await servers[0].config.enableTranscoding() |
96 | |||
97 | sqlCommandServer1 = new SQLCommand(servers[0]) | ||
95 | }) | 98 | }) |
96 | 99 | ||
97 | describe('Without live transcoding', function () { | 100 | describe('Without live transcoding', function () { |
@@ -109,8 +112,9 @@ describe('Object storage for lives', function () { | |||
109 | const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUID }) | 112 | const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUID }) |
110 | await waitUntilLivePublishedOnAllServers(servers, videoUUID) | 113 | await waitUntilLivePublishedOnAllServers(servers, videoUUID) |
111 | 114 | ||
112 | await testVideoResolutions({ | 115 | await testLiveVideoResolutions({ |
113 | originServer: servers[0], | 116 | originServer: servers[0], |
117 | sqlCommand: sqlCommandServer1, | ||
114 | servers, | 118 | servers, |
115 | liveVideoId: videoUUID, | 119 | liveVideoId: videoUUID, |
116 | resolutions: [ 720 ], | 120 | resolutions: [ 720 ], |
@@ -155,8 +159,9 @@ describe('Object storage for lives', function () { | |||
155 | const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUIDNonPermanent }) | 159 | const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUIDNonPermanent }) |
156 | await waitUntilLivePublishedOnAllServers(servers, videoUUIDNonPermanent) | 160 | await waitUntilLivePublishedOnAllServers(servers, videoUUIDNonPermanent) |
157 | 161 | ||
158 | await testVideoResolutions({ | 162 | await testLiveVideoResolutions({ |
159 | originServer: servers[0], | 163 | originServer: servers[0], |
164 | sqlCommand: sqlCommandServer1, | ||
160 | servers, | 165 | servers, |
161 | liveVideoId: videoUUIDNonPermanent, | 166 | liveVideoId: videoUUIDNonPermanent, |
162 | resolutions, | 167 | resolutions, |
@@ -194,8 +199,9 @@ describe('Object storage for lives', function () { | |||
194 | const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUIDPermanent }) | 199 | const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUIDPermanent }) |
195 | await waitUntilLivePublishedOnAllServers(servers, videoUUIDPermanent) | 200 | await waitUntilLivePublishedOnAllServers(servers, videoUUIDPermanent) |
196 | 201 | ||
197 | await testVideoResolutions({ | 202 | await testLiveVideoResolutions({ |
198 | originServer: servers[0], | 203 | originServer: servers[0], |
204 | sqlCommand: sqlCommandServer1, | ||
199 | servers, | 205 | servers, |
200 | liveVideoId: videoUUIDPermanent, | 206 | liveVideoId: videoUUIDPermanent, |
201 | resolutions, | 207 | resolutions, |
@@ -266,8 +272,9 @@ describe('Object storage for lives', function () { | |||
266 | const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUIDPermanent }) | 272 | const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUIDPermanent }) |
267 | await waitUntilLivePublishedOnAllServers(servers, videoUUIDPermanent) | 273 | await waitUntilLivePublishedOnAllServers(servers, videoUUIDPermanent) |
268 | 274 | ||
269 | await testVideoResolutions({ | 275 | await testLiveVideoResolutions({ |
270 | originServer: servers[0], | 276 | originServer: servers[0], |
277 | sqlCommand: sqlCommandServer1, | ||
271 | servers, | 278 | servers, |
272 | liveVideoId: videoUUIDPermanent, | 279 | liveVideoId: videoUUIDPermanent, |
273 | resolutions: [ 720 ], | 280 | resolutions: [ 720 ], |
@@ -281,6 +288,8 @@ describe('Object storage for lives', function () { | |||
281 | }) | 288 | }) |
282 | 289 | ||
283 | after(async function () { | 290 | after(async function () { |
291 | await sqlCommandServer1.cleanup() | ||
292 | |||
284 | await killallServers(servers) | 293 | await killallServers(servers) |
285 | }) | 294 | }) |
286 | }) | 295 | }) |
diff --git a/server/tests/api/object-storage/video-static-file-privacy.ts b/server/tests/api/object-storage/video-static-file-privacy.ts index 930c88543..af9d681b2 100644 --- a/server/tests/api/object-storage/video-static-file-privacy.ts +++ b/server/tests/api/object-storage/video-static-file-privacy.ts | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | import { expect } from 'chai' | 3 | import { expect } from 'chai' |
4 | import { basename } from 'path' | 4 | import { basename } from 'path' |
5 | import { checkVideoFileTokenReinjection, expectStartWith } from '@server/tests/shared' | 5 | import { checkVideoFileTokenReinjection, expectStartWith, SQLCommand } from '@server/tests/shared' |
6 | import { areScalewayObjectStorageTestsDisabled, getAllFiles, getHLS } from '@shared/core-utils' | 6 | import { areScalewayObjectStorageTestsDisabled, getAllFiles, getHLS } from '@shared/core-utils' |
7 | import { HttpStatusCode, LiveVideo, VideoDetails, VideoPrivacy } from '@shared/models' | 7 | import { HttpStatusCode, LiveVideo, VideoDetails, VideoPrivacy } from '@shared/models' |
8 | import { | 8 | import { |
@@ -30,6 +30,7 @@ describe('Object storage for video static file privacy', function () { | |||
30 | if (areScalewayObjectStorageTestsDisabled()) return | 30 | if (areScalewayObjectStorageTestsDisabled()) return |
31 | 31 | ||
32 | let server: PeerTubeServer | 32 | let server: PeerTubeServer |
33 | let sqlCommand: SQLCommand | ||
33 | let userToken: string | 34 | let userToken: string |
34 | 35 | ||
35 | // --------------------------------------------------------------------------- | 36 | // --------------------------------------------------------------------------- |
@@ -44,7 +45,7 @@ describe('Object storage for video static file privacy', function () { | |||
44 | } | 45 | } |
45 | 46 | ||
46 | for (const file of getAllFiles(video)) { | 47 | for (const file of getAllFiles(video)) { |
47 | const internalFileUrl = await server.sql.getInternalFileUrl(file.id) | 48 | const internalFileUrl = await sqlCommand.getInternalFileUrl(file.id) |
48 | expectStartWith(internalFileUrl, ObjectStorageCommand.getScalewayBaseUrl()) | 49 | expectStartWith(internalFileUrl, ObjectStorageCommand.getScalewayBaseUrl()) |
49 | await makeRawRequest({ url: internalFileUrl, token: server.accessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) | 50 | await makeRawRequest({ url: internalFileUrl, token: server.accessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
50 | } | 51 | } |
@@ -99,6 +100,8 @@ describe('Object storage for video static file privacy', function () { | |||
99 | await server.config.enableMinimumTranscoding() | 100 | await server.config.enableMinimumTranscoding() |
100 | 101 | ||
101 | userToken = await server.users.generateUserAndToken('user1') | 102 | userToken = await server.users.generateUserAndToken('user1') |
103 | |||
104 | sqlCommand = new SQLCommand(server) | ||
102 | }) | 105 | }) |
103 | 106 | ||
104 | describe('VOD', function () { | 107 | describe('VOD', function () { |
@@ -439,6 +442,7 @@ describe('Object storage for video static file privacy', function () { | |||
439 | await server.servers.waitUntilLog('Removed files of video ' + v.url) | 442 | await server.servers.waitUntilLog('Removed files of video ' + v.url) |
440 | } | 443 | } |
441 | 444 | ||
445 | await sqlCommand.cleanup() | ||
442 | await cleanupTests([ server ]) | 446 | await cleanupTests([ server ]) |
443 | }) | 447 | }) |
444 | }) | 448 | }) |
diff --git a/server/tests/api/object-storage/videos.ts b/server/tests/api/object-storage/videos.ts index 6aaf32c34..e90753d09 100644 --- a/server/tests/api/object-storage/videos.ts +++ b/server/tests/api/object-storage/videos.ts | |||
@@ -6,12 +6,15 @@ import { stat } from 'fs-extra' | |||
6 | import { merge } from 'lodash' | 6 | import { merge } from 'lodash' |
7 | import { | 7 | import { |
8 | checkTmpIsEmpty, | 8 | checkTmpIsEmpty, |
9 | checkWebTorrentWorks, | ||
9 | expectLogDoesNotContain, | 10 | expectLogDoesNotContain, |
10 | expectStartWith, | 11 | expectStartWith, |
11 | generateHighBitrateVideo, | 12 | generateHighBitrateVideo, |
12 | MockObjectStorageProxy | 13 | MockObjectStorageProxy, |
14 | SQLCommand | ||
13 | } from '@server/tests/shared' | 15 | } from '@server/tests/shared' |
14 | import { areMockObjectStorageTestsDisabled } from '@shared/core-utils' | 16 | import { areMockObjectStorageTestsDisabled } from '@shared/core-utils' |
17 | import { sha1 } from '@shared/extra-utils' | ||
15 | import { HttpStatusCode, VideoDetails } from '@shared/models' | 18 | import { HttpStatusCode, VideoDetails } from '@shared/models' |
16 | import { | 19 | import { |
17 | cleanupTests, | 20 | cleanupTests, |
@@ -23,14 +26,13 @@ import { | |||
23 | ObjectStorageCommand, | 26 | ObjectStorageCommand, |
24 | PeerTubeServer, | 27 | PeerTubeServer, |
25 | setAccessTokensToServers, | 28 | setAccessTokensToServers, |
26 | waitJobs, | 29 | waitJobs |
27 | webtorrentAdd | ||
28 | } from '@shared/server-commands' | 30 | } from '@shared/server-commands' |
29 | import { sha1 } from '@shared/extra-utils' | ||
30 | 31 | ||
31 | async function checkFiles (options: { | 32 | async function checkFiles (options: { |
32 | server: PeerTubeServer | 33 | server: PeerTubeServer |
33 | originServer: PeerTubeServer | 34 | originServer: PeerTubeServer |
35 | originSQLCommand: SQLCommand | ||
34 | 36 | ||
35 | video: VideoDetails | 37 | video: VideoDetails |
36 | 38 | ||
@@ -45,6 +47,7 @@ async function checkFiles (options: { | |||
45 | const { | 47 | const { |
46 | server, | 48 | server, |
47 | originServer, | 49 | originServer, |
50 | originSQLCommand, | ||
48 | video, | 51 | video, |
49 | playlistBucket, | 52 | playlistBucket, |
50 | webtorrentBucket, | 53 | webtorrentBucket, |
@@ -104,7 +107,7 @@ async function checkFiles (options: { | |||
104 | 107 | ||
105 | if (originServer.internalServerNumber === server.internalServerNumber) { | 108 | if (originServer.internalServerNumber === server.internalServerNumber) { |
106 | const infohash = sha1(`${2 + hls.playlistUrl}+V${i}`) | 109 | const infohash = sha1(`${2 + hls.playlistUrl}+V${i}`) |
107 | const dbInfohashes = await originServer.sql.getPlaylistInfohash(hls.id) | 110 | const dbInfohashes = await originSQLCommand.getPlaylistInfohash(hls.id) |
108 | 111 | ||
109 | expect(dbInfohashes).to.include(infohash) | 112 | expect(dbInfohashes).to.include(infohash) |
110 | } | 113 | } |
@@ -114,11 +117,7 @@ async function checkFiles (options: { | |||
114 | } | 117 | } |
115 | 118 | ||
116 | for (const file of allFiles) { | 119 | for (const file of allFiles) { |
117 | const torrent = await webtorrentAdd(file.magnetUri, true) | 120 | await checkWebTorrentWorks(file.magnetUri) |
118 | |||
119 | expect(torrent.files).to.be.an('array') | ||
120 | expect(torrent.files.length).to.equal(1) | ||
121 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | ||
122 | 121 | ||
123 | const res = await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 }) | 122 | const res = await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 }) |
124 | expect(res.body).to.have.length.above(100) | 123 | expect(res.body).to.have.length.above(100) |
@@ -145,6 +144,7 @@ function runTestSuite (options: { | |||
145 | let baseMockUrl: string | 144 | let baseMockUrl: string |
146 | 145 | ||
147 | let servers: PeerTubeServer[] | 146 | let servers: PeerTubeServer[] |
147 | let sqlCommands: SQLCommand[] | ||
148 | 148 | ||
149 | let keptUrls: string[] = [] | 149 | let keptUrls: string[] = [] |
150 | 150 | ||
@@ -202,6 +202,8 @@ function runTestSuite (options: { | |||
202 | const files = await server.videos.listFiles({ id: uuid }) | 202 | const files = await server.videos.listFiles({ id: uuid }) |
203 | keptUrls = keptUrls.concat(files.map(f => f.fileUrl)) | 203 | keptUrls = keptUrls.concat(files.map(f => f.fileUrl)) |
204 | } | 204 | } |
205 | |||
206 | sqlCommands = servers.map(s => new SQLCommand(s)) | ||
205 | }) | 207 | }) |
206 | 208 | ||
207 | it('Should upload a video and move it to the object storage without transcoding', async function () { | 209 | it('Should upload a video and move it to the object storage without transcoding', async function () { |
@@ -214,7 +216,7 @@ function runTestSuite (options: { | |||
214 | 216 | ||
215 | for (const server of servers) { | 217 | for (const server of servers) { |
216 | const video = await server.videos.get({ id: uuid }) | 218 | const video = await server.videos.get({ id: uuid }) |
217 | const files = await checkFiles({ ...options, server, originServer: servers[0], video, baseMockUrl }) | 219 | const files = await checkFiles({ ...options, server, originServer: servers[0], originSQLCommand: sqlCommands[0], video, baseMockUrl }) |
218 | 220 | ||
219 | deletedUrls = deletedUrls.concat(files) | 221 | deletedUrls = deletedUrls.concat(files) |
220 | } | 222 | } |
@@ -230,7 +232,7 @@ function runTestSuite (options: { | |||
230 | 232 | ||
231 | for (const server of servers) { | 233 | for (const server of servers) { |
232 | const video = await server.videos.get({ id: uuid }) | 234 | const video = await server.videos.get({ id: uuid }) |
233 | const files = await checkFiles({ ...options, server, originServer: servers[0], video, baseMockUrl }) | 235 | const files = await checkFiles({ ...options, server, originServer: servers[0], originSQLCommand: sqlCommands[0], video, baseMockUrl }) |
234 | 236 | ||
235 | deletedUrls = deletedUrls.concat(files) | 237 | deletedUrls = deletedUrls.concat(files) |
236 | } | 238 | } |
@@ -274,6 +276,10 @@ function runTestSuite (options: { | |||
274 | after(async function () { | 276 | after(async function () { |
275 | await mockObjectStorageProxy.terminate() | 277 | await mockObjectStorageProxy.terminate() |
276 | 278 | ||
279 | for (const sqlCommand of sqlCommands) { | ||
280 | await sqlCommand.cleanup() | ||
281 | } | ||
282 | |||
277 | await cleanupTests(servers) | 283 | await cleanupTests(servers) |
278 | }) | 284 | }) |
279 | } | 285 | } |