]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/videos/video-transcoder.ts
Introduce blacklist command
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-transcoder.ts
index 1058baaa313d50f5672debdca057784b9817e885..e74fb5bef4b5c27c4f978c5bd9a62c44a9e700a9 100644 (file)
@@ -5,7 +5,6 @@ import * as chai from 'chai'
 import { FfprobeData } from 'fluent-ffmpeg'
 import { omit } from 'lodash'
 import { join } from 'path'
-import { Job } from '@shared/models'
 import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants'
 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
 import {
@@ -16,7 +15,6 @@ import {
   flushAndRunMultipleServers,
   generateHighBitrateVideo,
   generateVideoWithFramerate,
-  getJobsListPaginationAndSort,
   getMyVideos,
   getServerFileSize,
   getVideo,
@@ -25,7 +23,6 @@ import {
   makeGetRequest,
   ServerInfo,
   setAccessTokensToServers,
-  updateCustomSubConfig,
   uploadVideo,
   uploadVideoAndGetId,
   waitJobs,
@@ -44,22 +41,24 @@ import {
 const expect = chai.expect
 
 function updateConfigForTranscoding (server: ServerInfo) {
-  return updateCustomSubConfig(server.url, server.accessToken, {
-    transcoding: {
-      enabled: true,
-      allowAdditionalExtensions: true,
-      allowAudioFiles: true,
-      hls: { enabled: true },
-      webtorrent: { enabled: true },
-      resolutions: {
-        '0p': false,
-        '240p': true,
-        '360p': true,
-        '480p': true,
-        '720p': true,
-        '1080p': true,
-        '1440p': true,
-        '2160p': true
+  return server.configCommand.updateCustomSubConfig({
+    newConfig: {
+      transcoding: {
+        enabled: true,
+        allowAdditionalExtensions: true,
+        allowAudioFiles: true,
+        hls: { enabled: true },
+        webtorrent: { enabled: true },
+        resolutions: {
+          '0p': false,
+          '240p': true,
+          '360p': true,
+          '480p': true,
+          '720p': true,
+          '1080p': true,
+          '1440p': true,
+          '2160p': true
+        }
       }
     }
   })
@@ -361,106 +360,121 @@ describe('Test video transcoding', function () {
 
   describe('Audio upload', function () {
 
-    before(async function () {
-      await updateCustomSubConfig(servers[1].url, servers[1].accessToken, {
-        transcoding: {
-          hls: { enabled: true },
-          webtorrent: { enabled: true },
-          resolutions: {
-            '0p': false,
-            '240p': false,
-            '360p': false,
-            '480p': false,
-            '720p': false,
-            '1080p': false,
-            '1440p': false,
-            '2160p': false
+    function runSuite (mode: 'legacy' | 'resumable') {
+
+      before(async function () {
+        await servers[1].configCommand.updateCustomSubConfig({
+          newConfig: {
+            transcoding: {
+              hls: { enabled: true },
+              webtorrent: { enabled: true },
+              resolutions: {
+                '0p': false,
+                '240p': false,
+                '360p': false,
+                '480p': false,
+                '720p': false,
+                '1080p': false,
+                '1440p': false,
+                '2160p': false
+              }
+            }
           }
-        }
+        })
       })
-    })
-
-    it('Should merge an audio file with the preview file', async function () {
-      this.timeout(60_000)
 
-      const videoAttributesArg = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' }
-      await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg)
+      it('Should merge an audio file with the preview file', async function () {
+        this.timeout(60_000)
 
-      await waitJobs(servers)
+        const videoAttributesArg = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' }
+        await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg, HttpStatusCode.OK_200, mode)
 
-      for (const server of servers) {
-        const res = await getVideosList(server.url)
-
-        const video = res.body.data.find(v => v.name === 'audio_with_preview')
-        const res2 = await getVideo(server.url, video.id)
-        const videoDetails: VideoDetails = res2.body
+        await waitJobs(servers)
 
-        expect(videoDetails.files).to.have.lengthOf(1)
+        for (const server of servers) {
+          const res = await getVideosList(server.url)
 
-        await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: HttpStatusCode.OK_200 })
-        await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: HttpStatusCode.OK_200 })
+          const video = res.body.data.find(v => v.name === 'audio_with_preview')
+          const res2 = await getVideo(server.url, video.id)
+          const videoDetails: VideoDetails = res2.body
 
-        const magnetUri = videoDetails.files[0].magnetUri
-        expect(magnetUri).to.contain('.mp4')
-      }
-    })
+          expect(videoDetails.files).to.have.lengthOf(1)
 
-    it('Should upload an audio file and choose a default background image', async function () {
-      this.timeout(60_000)
+          await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: HttpStatusCode.OK_200 })
+          await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: HttpStatusCode.OK_200 })
 
-      const videoAttributesArg = { name: 'audio_without_preview', fixture: 'sample.ogg' }
-      await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg)
+          const magnetUri = videoDetails.files[0].magnetUri
+          expect(magnetUri).to.contain('.mp4')
+        }
+      })
 
-      await waitJobs(servers)
+      it('Should upload an audio file and choose a default background image', async function () {
+        this.timeout(60_000)
 
-      for (const server of servers) {
-        const res = await getVideosList(server.url)
+        const videoAttributesArg = { name: 'audio_without_preview', fixture: 'sample.ogg' }
+        await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg, HttpStatusCode.OK_200, mode)
 
-        const video = res.body.data.find(v => v.name === 'audio_without_preview')
-        const res2 = await getVideo(server.url, video.id)
-        const videoDetails = res2.body
+        await waitJobs(servers)
 
-        expect(videoDetails.files).to.have.lengthOf(1)
+        for (const server of servers) {
+          const res = await getVideosList(server.url)
 
-        await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: HttpStatusCode.OK_200 })
-        await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: HttpStatusCode.OK_200 })
+          const video = res.body.data.find(v => v.name === 'audio_without_preview')
+          const res2 = await getVideo(server.url, video.id)
+          const videoDetails = res2.body
 
-        const magnetUri = videoDetails.files[0].magnetUri
-        expect(magnetUri).to.contain('.mp4')
-      }
-    })
+          expect(videoDetails.files).to.have.lengthOf(1)
 
-    it('Should upload an audio file and create an audio version only', async function () {
-      this.timeout(60_000)
+          await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: HttpStatusCode.OK_200 })
+          await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: HttpStatusCode.OK_200 })
 
-      await updateCustomSubConfig(servers[1].url, servers[1].accessToken, {
-        transcoding: {
-          hls: { enabled: true },
-          webtorrent: { enabled: true },
-          resolutions: {
-            '0p': true,
-            '240p': false,
-            '360p': false
-          }
+          const magnetUri = videoDetails.files[0].magnetUri
+          expect(magnetUri).to.contain('.mp4')
         }
       })
 
-      const videoAttributesArg = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' }
-      const resVideo = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg)
+      it('Should upload an audio file and create an audio version only', async function () {
+        this.timeout(60_000)
+
+        await servers[1].configCommand.updateCustomSubConfig({
+          newConfig: {
+            transcoding: {
+              hls: { enabled: true },
+              webtorrent: { enabled: true },
+              resolutions: {
+                '0p': true,
+                '240p': false,
+                '360p': false
+              }
+            }
+          }
+        })
+
+        const videoAttributesArg = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' }
+        const resVideo = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg, HttpStatusCode.OK_200, mode)
 
-      await waitJobs(servers)
+        await waitJobs(servers)
 
-      for (const server of servers) {
-        const res2 = await getVideo(server.url, resVideo.body.video.id)
-        const videoDetails: VideoDetails = res2.body
+        for (const server of servers) {
+          const res2 = await getVideo(server.url, resVideo.body.video.id)
+          const videoDetails: VideoDetails = res2.body
 
-        for (const files of [ videoDetails.files, videoDetails.streamingPlaylists[0].files ]) {
-          expect(files).to.have.lengthOf(2)
-          expect(files.find(f => f.resolution.id === 0)).to.not.be.undefined
+          for (const files of [ videoDetails.files, videoDetails.streamingPlaylists[0].files ]) {
+            expect(files).to.have.lengthOf(2)
+            expect(files.find(f => f.resolution.id === 0)).to.not.be.undefined
+          }
         }
-      }
 
-      await updateConfigForTranscoding(servers[1])
+        await updateConfigForTranscoding(servers[1])
+      })
+    }
+
+    describe('Legacy upload', function () {
+      runSuite('legacy')
+    })
+
+    describe('Resumable upload', function () {
+      runSuite('resumable')
     })
   })
 
@@ -591,7 +605,7 @@ describe('Test video transcoding', function () {
     it('Should not transcode to an higher bitrate than the original file', async function () {
       this.timeout(160_000)
 
-      const config = {
+      const newConfig = {
         transcoding: {
           enabled: true,
           resolutions: {
@@ -607,7 +621,7 @@ describe('Test video transcoding', function () {
           hls: { enabled: true }
         }
       }
-      await updateCustomSubConfig(servers[1].url, servers[1].accessToken, config)
+      await servers[1].configCommand.updateCustomSubConfig({ newConfig })
 
       const videoAttributes = {
         name: 'low bitrate',
@@ -698,17 +712,14 @@ describe('Test video transcoding', function () {
   describe('Transcoding job queue', function () {
 
     it('Should have the appropriate priorities for transcoding jobs', async function () {
-      const res = await getJobsListPaginationAndSort({
-        url: servers[1].url,
-        accessToken: servers[1].accessToken,
+      const body = await servers[1].jobsCommand.getJobsList({
         start: 0,
         count: 100,
         sort: '-createdAt',
         jobType: 'video-transcoding'
       })
 
-      const jobs = res.body.data as Job[]
-
+      const jobs = body.data
       const transcodingJobs = jobs.filter(j => j.data.videoUUID === video4k)
 
       expect(transcodingJobs).to.have.lengthOf(14)
@@ -721,12 +732,7 @@ describe('Test video transcoding', function () {
       expect(webtorrentJobs).to.have.lengthOf(6)
       expect(optimizeJobs).to.have.lengthOf(1)
 
-      for (const j of optimizeJobs) {
-        expect(j.priority).to.be.greaterThan(11)
-        expect(j.priority).to.be.lessThan(50)
-      }
-
-      for (const j of hlsJobs.concat(webtorrentJobs)) {
+      for (const j of optimizeJobs.concat(hlsJobs.concat(webtorrentJobs))) {
         expect(j.priority).to.be.greaterThan(100)
         expect(j.priority).to.be.lessThan(150)
       }