]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/object-storage/videos.ts
Fix removed sha segments on fast restream
[github/Chocobozzz/PeerTube.git] / server / tests / api / object-storage / videos.ts
index 3958bd3d7aae2e8a2f53946cb6c1ecee9f77149f..e288e542e55dc43d118a988d9f5cc6e72e22a219 100644 (file)
@@ -1,26 +1,32 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
 import 'mocha'
+import bytes from 'bytes'
 import * as chai from 'chai'
+import { stat } from 'fs-extra'
 import { merge } from 'lodash'
 import {
-  areObjectStorageTestsDisabled,
   checkTmpIsEmpty,
+  expectLogDoesNotContain,
+  expectStartWith,
+  generateHighBitrateVideo,
+  MockObjectStorage
+} from '@server/tests/shared'
+import { areObjectStorageTestsDisabled } from '@shared/core-utils'
+import { HttpStatusCode, VideoDetails } from '@shared/models'
+import {
   cleanupTests,
   createMultipleServers,
   createSingleServer,
   doubleFollow,
-  expectStartWith,
   killallServers,
   makeRawRequest,
-  MockObjectStorage,
   ObjectStorageCommand,
   PeerTubeServer,
   setAccessTokensToServers,
   waitJobs,
   webtorrentAdd
-} from '@shared/extra-utils'
-import { HttpStatusCode, VideoDetails } from '@shared/models'
+} from '@shared/server-commands'
 
 const expect = chai.expect
 
@@ -109,6 +115,10 @@ async function checkFiles (options: {
 }
 
 function runTestSuite (options: {
+  fixture?: string
+
+  maxUploadPart?: string
+
   playlistBucket: string
   playlistPrefix?: string
 
@@ -116,10 +126,9 @@ function runTestSuite (options: {
   webtorrentPrefix?: string
 
   useMockBaseUrl?: boolean
-
-  maxUploadPart?: string
 }) {
   const mockObjectStorage = new MockObjectStorage()
+  const { fixture } = options
   let baseMockUrl: string
 
   let servers: PeerTubeServer[]
@@ -146,7 +155,7 @@ function runTestSuite (options: {
 
         credentials: ObjectStorageCommand.getCredentialsConfig(),
 
-        max_upload_part: options.maxUploadPart || '2MB',
+        max_upload_part: options.maxUploadPart || '5MB',
 
         streaming_playlists: {
           bucket_name: options.playlistBucket,
@@ -181,9 +190,9 @@ function runTestSuite (options: {
   })
 
   it('Should upload a video and move it to the object storage without transcoding', async function () {
-    this.timeout(20000)
+    this.timeout(40000)
 
-    const { uuid } = await servers[0].videos.quickUpload({ name: 'video 1' })
+    const { uuid } = await servers[0].videos.quickUpload({ name: 'video 1', fixture })
     uuidsToDelete.push(uuid)
 
     await waitJobs(servers)
@@ -197,9 +206,9 @@ function runTestSuite (options: {
   })
 
   it('Should upload a video and move it to the object storage with transcoding', async function () {
-    this.timeout(40000)
+    this.timeout(120000)
 
-    const { uuid } = await servers[1].videos.quickUpload({ name: 'video 2' })
+    const { uuid } = await servers[1].videos.quickUpload({ name: 'video 2', fixture })
     uuidsToDelete.push(uuid)
 
     await waitJobs(servers)
@@ -212,6 +221,12 @@ function runTestSuite (options: {
     }
   })
 
+  it('Should fetch correctly all the files', async function () {
+    for (const url of deletedUrls.concat(keptUrls)) {
+      await makeRawRequest(url, HttpStatusCode.OK_200)
+    }
+  })
+
   it('Should correctly delete the files', async function () {
     await servers[0].videos.remove({ id: uuidsToDelete[0] })
     await servers[1].videos.remove({ id: uuidsToDelete[1] })
@@ -235,8 +250,14 @@ function runTestSuite (options: {
     }
   })
 
+  it('Should not have downloaded files from object storage', async function () {
+    for (const server of servers) {
+      await expectLogDoesNotContain(server, 'from object storage')
+    }
+  })
+
   after(async function () {
-    mockObjectStorage.terminate()
+    await mockObjectStorage.terminate()
 
     await cleanupTests(servers)
   })
@@ -373,19 +394,34 @@ describe('Object storage for videos', function () {
       playlistBucket: 'mybucket',
       webtorrentBucket: 'mybucket',
 
-      playlistPrefix: 'streaming-playlists_',
-      webtorrentPrefix: 'webtorrent_',
+      playlistPrefix: 'streaming-playlists/',
+      webtorrentPrefix: 'webtorrent/',
 
       useMockBaseUrl: true
     })
   })
 
-  describe('Test object storage with small upload part', function () {
+  describe('Test object storage with file bigger than upload part', function () {
+    let fixture: string
+    const maxUploadPart = '5MB'
+
+    before(async function () {
+      this.timeout(120000)
+
+      fixture = await generateHighBitrateVideo()
+
+      const { size } = await stat(fixture)
+
+      if (bytes.parse(maxUploadPart) > size) {
+        throw Error(`Fixture file is too small (${size}) to make sense for this test.`)
+      }
+    })
+
     runTestSuite({
+      maxUploadPart,
       playlistBucket: 'streaming-playlists',
       webtorrentBucket: 'videos',
-
-      maxUploadPart: '5KB'
+      fixture
     })
   })
 })