]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix tests
authorChocobozzz <me@florianbigard.com>
Wed, 10 Nov 2021 13:25:33 +0000 (14:25 +0100)
committerChocobozzz <me@florianbigard.com>
Wed, 10 Nov 2021 13:25:33 +0000 (14:25 +0100)
server/tests/api/videos/multiple-servers.ts
server/tests/api/videos/video-transcoder.ts
server/tests/cli/print-transcode-command.ts

index 9c255c1c55ef0a74ddb92801e0dbba4af758d96d..470bee45b60c8c98e5000f8a3071652d49d8d2d0 100644 (file)
@@ -591,7 +591,9 @@ describe('Test multiple servers', function () {
   })
 
   describe('Should manipulate these videos', function () {
-    it('Should update the video 3 by asking server 3', async function () {
+    let updatedAtMin: Date
+
+    it('Should update video 3', async function () {
       this.timeout(10000)
 
       const attributes = {
@@ -608,6 +610,7 @@ describe('Test multiple servers', function () {
         previewfile: 'preview.jpg'
       }
 
+      updatedAtMin = new Date()
       await servers[2].videos.update({ id: toRemove[0].id, attributes })
 
       await waitJobs(servers)
@@ -622,6 +625,8 @@ describe('Test multiple servers', function () {
         const videoUpdated = data.find(video => video.name === 'my super video updated')
         expect(!!videoUpdated).to.be.true
 
+        expect(new Date(videoUpdated.updatedAt)).to.be.greaterThan(updatedAtMin)
+
         const isLocal = server.url === 'http://localhost:' + servers[2].port
         const checkAttributes = {
           name: 'my super video updated',
@@ -1024,15 +1029,15 @@ describe('Test multiple servers', function () {
           files: [
             {
               resolution: 720,
-              size: 59000
+              size: 61000
             },
             {
               resolution: 480,
-              size: 34000
+              size: 40000
             },
             {
               resolution: 360,
-              size: 31000
+              size: 32000
             },
             {
               resolution: 240,
index b3226dbf7289f869c2fb22639b1d6cbfbb2f15cd..7ed55b8e8d3d18b0fb2c3e2fe98c0169f723d9f9 100644 (file)
@@ -3,7 +3,7 @@
 import 'mocha'
 import * as chai from 'chai'
 import { omit } from 'lodash'
-import { getMaxBitrate } from '@shared/core-utils'
+import { getMaxBitrate, getMinLimitBitrate } from '@shared/core-utils'
 import {
   buildAbsoluteFixturePath,
   cleanupTests,
@@ -583,7 +583,7 @@ describe('Test video transcoding', function () {
       }
     })
 
-    it('Should not transcode to an higher bitrate than the original file', async function () {
+    it('Should not transcode to an higher bitrate than the original file but above our low limit', async function () {
       this.timeout(160_000)
 
       const newConfig = {
@@ -622,7 +622,13 @@ describe('Test video transcoding', function () {
 
         const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
         const bitrate = await getVideoFileBitrate(path)
-        expect(bitrate, `${path} not below ${60_000}`).to.be.below(60_000)
+
+        const inputBitrate = 60_000
+        const limit = getMinLimitBitrate({ fps: 10, ratio: 1, resolution: r })
+        let belowValue = Math.max(inputBitrate, limit)
+        belowValue += belowValue * 0.20 // Apply 20% margin because bitrate control is not very precise
+
+        expect(bitrate, `${path} not below ${limit}`).to.be.below(belowValue)
       }
     })
   })
index e2cca17f9365acaa35fe77f6c3a68a07ad380736..0b86292516771b2306c5ebb74ce7570ebb912925 100644 (file)
@@ -2,8 +2,6 @@
 
 import 'mocha'
 import * as chai from 'chai'
-import { getVideoFileBitrate, getVideoFileFPS } from '@server/helpers/ffprobe-utils'
-import { getMaxBitrate } from '@shared/core-utils'
 import { buildAbsoluteFixturePath, CLICommand } from '@shared/extra-utils'
 import { VideoResolution } from '../../../shared/models/videos'
 
@@ -13,15 +11,12 @@ describe('Test print transcode jobs', function () {
 
   it('Should print the correct command for each resolution', async function () {
     const fixturePath = buildAbsoluteFixturePath('video_short.webm')
-    const fps = await getVideoFileFPS(fixturePath)
-    const bitrate = await getVideoFileBitrate(fixturePath)
 
     for (const resolution of [
       VideoResolution.H_720P,
       VideoResolution.H_1080P
     ]) {
       const command = await CLICommand.exec(`npm run print-transcode-command -- ${fixturePath} -r ${resolution}`)
-      const targetBitrate = Math.min(getMaxBitrate({ resolution, fps, ratio: 16 / 9 }), bitrate + (bitrate * 0.3))
 
       expect(command).to.includes(`-vf scale=w=-2:h=${resolution}`)
       expect(command).to.includes(`-y -acodec aac -vcodec libx264`)
@@ -31,8 +26,8 @@ describe('Test print transcode jobs', function () {
       expect(command).to.includes('-r 25')
       expect(command).to.includes('-level:v 3.1')
       expect(command).to.includes('-g:v 50')
-      expect(command).to.includes(`-maxrate ${targetBitrate}`)
-      expect(command).to.includes(`-bufsize ${targetBitrate * 2}`)
+      expect(command).to.includes(`-maxrate `)
+      expect(command).to.includes(`-bufsize `)
     }
   })
 })