X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fobject-storage%2Fvideos.ts;h=77ed78ae11a9cba845f49737a81d1bae2d36eeb4;hb=5a05c14573ca3c0d16b77bef78d845f96c8c6497;hp=af3db9334d44da616e558f2ef5e1f4da74f1764e;hpb=9ab330b90decf4edf152ff8e1d2948c065766b2c;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/object-storage/videos.ts b/server/tests/api/object-storage/videos.ts index af3db9334..77ed78ae1 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' import { merge } from 'lodash' import { checkTmpIsEmpty, + checkWebTorrentWorks, expectLogDoesNotContain, expectStartWith, generateHighBitrateVideo, - MockObjectStorage + MockObjectStorageProxy, + SQLCommand } from '@server/tests/shared' import { areMockObjectStorageTestsDisabled } from '@shared/core-utils' +import { sha1 } from '@shared/extra-utils' import { HttpStatusCode, VideoDetails } from '@shared/models' import { cleanupTests, @@ -23,11 +26,14 @@ import { ObjectStorageCommand, PeerTubeServer, setAccessTokensToServers, - waitJobs, - webtorrentAdd + waitJobs } from '@shared/server-commands' async function checkFiles (options: { + server: PeerTubeServer + originServer: PeerTubeServer + originSQLCommand: SQLCommand + video: VideoDetails baseMockUrl?: string @@ -39,6 +45,9 @@ async function checkFiles (options: { webtorrentPrefix?: string }) { const { + server, + originServer, + originSQLCommand, video, playlistBucket, webtorrentBucket, @@ -86,6 +95,7 @@ async function checkFiles (options: { const resSha = await makeRawRequest({ url: hls.segmentsSha256Url, expectedStatus: HttpStatusCode.OK_200 }) expect(JSON.stringify(resSha.body)).to.not.throw + let i = 0 for (const file of hls.files) { expectStartWith(file.fileUrl, start) @@ -94,15 +104,20 @@ async function checkFiles (options: { expectStartWith(location, start) await makeRawRequest({ url: location, expectedStatus: HttpStatusCode.OK_200 }) + + if (originServer.internalServerNumber === server.internalServerNumber) { + const infohash = sha1(`${2 + hls.playlistUrl}+V${i}`) + const dbInfohashes = await originSQLCommand.getPlaylistInfohash(hls.id) + + expect(dbInfohashes).to.include(infohash) + } + + i++ } } for (const file of allFiles) { - const torrent = await webtorrentAdd(file.magnetUri, true) - - expect(torrent.files).to.be.an('array') - expect(torrent.files.length).to.equal(1) - expect(torrent.files[0].path).to.exist.and.to.not.equal('') + await checkWebTorrentWorks(file.magnetUri) const res = await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 }) expect(res.body).to.have.length.above(100) @@ -124,11 +139,12 @@ function runTestSuite (options: { useMockBaseUrl?: boolean }) { - const mockObjectStorage = new MockObjectStorage() + const mockObjectStorageProxy = new MockObjectStorageProxy() const { fixture } = options let baseMockUrl: string let servers: PeerTubeServer[] + let sqlCommands: SQLCommand[] = [] let keptUrls: string[] = [] @@ -136,10 +152,12 @@ function runTestSuite (options: { let deletedUrls: string[] = [] before(async function () { - this.timeout(120000) + this.timeout(240000) - const port = await mockObjectStorage.initialize() - baseMockUrl = options.useMockBaseUrl ? `http://localhost:${port}` : undefined + const port = await mockObjectStorageProxy.initialize() + baseMockUrl = options.useMockBaseUrl + ? `http://127.0.0.1:${port}` + : undefined await ObjectStorageCommand.createMockBucket(options.playlistBucket) await ObjectStorageCommand.createMockBucket(options.webtorrentBucket) @@ -184,6 +202,8 @@ function runTestSuite (options: { const files = await server.videos.listFiles({ id: uuid }) keptUrls = keptUrls.concat(files.map(f => f.fileUrl)) } + + sqlCommands = servers.map(s => new SQLCommand(s)) }) it('Should upload a video and move it to the object storage without transcoding', async function () { @@ -196,7 +216,7 @@ function runTestSuite (options: { for (const server of servers) { const video = await server.videos.get({ id: uuid }) - const files = await checkFiles({ ...options, video, baseMockUrl }) + const files = await checkFiles({ ...options, server, originServer: servers[0], originSQLCommand: sqlCommands[0], video, baseMockUrl }) deletedUrls = deletedUrls.concat(files) } @@ -212,7 +232,7 @@ function runTestSuite (options: { for (const server of servers) { const video = await server.videos.get({ id: uuid }) - const files = await checkFiles({ ...options, video, baseMockUrl }) + const files = await checkFiles({ ...options, server, originServer: servers[0], originSQLCommand: sqlCommands[0], video, baseMockUrl }) deletedUrls = deletedUrls.concat(files) } @@ -254,7 +274,11 @@ function runTestSuite (options: { }) after(async function () { - await mockObjectStorage.terminate() + await mockObjectStorageProxy.terminate() + + for (const sqlCommand of sqlCommands) { + await sqlCommand.cleanup() + } await cleanupTests(servers) }) @@ -323,7 +347,7 @@ describe('Object storage for videos', function () { const { uuid } = await server.videos.quickUpload({ name: 'video' }) - await waitJobs([ server ], true) + await waitJobs([ server ], { skipDelayed: true }) const video = await server.videos.get({ id: uuid }) expectStartWith(video.files[0].fileUrl, server.url) @@ -358,14 +382,14 @@ describe('Object storage for videos', function () { const { uuid } = await server.videos.quickUpload({ name: 'video' }) - await waitJobs([ server ], true) + await waitJobs([ server ], { skipDelayed: true }) const video = await server.videos.get({ id: uuid }) expectStartWith(video.files[0].fileUrl, ObjectStorageCommand.getMockWebTorrentBaseUrl()) }) after(async function () { - await killallServers([ server ]) + await cleanupTests([ server ]) }) })