PeerTube/server/tests/cli/optimize-old-videos.ts

97 lines
2.7 KiB
TypeScript
Raw Normal View History

2020-01-31 16:56:52 +01:00
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2018-10-18 16:53:52 +02:00
import 'mocha'
import * as chai from 'chai'
2021-08-06 13:35:25 +02:00
import { getMaxBitrate } from '@shared/core-utils'
2018-10-18 16:53:52 +02:00
import {
2019-04-24 15:10:37 +02:00
cleanupTests,
2021-07-16 09:47:51 +02:00
createMultipleServers,
2021-07-16 14:27:30 +02:00
doubleFollow,
generateHighBitrateVideo,
2021-07-16 09:47:51 +02:00
PeerTubeServer,
2018-10-18 16:53:52 +02:00
setAccessTokensToServers,
2021-07-15 10:02:54 +02:00
wait,
waitJobs
} from '@shared/extra-utils'
2020-11-20 17:16:55 +01:00
import { getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../../helpers/ffprobe-utils'
2018-10-18 16:53:52 +02:00
const expect = chai.expect
describe('Test optimize old videos', function () {
2021-07-16 09:47:51 +02:00
let servers: PeerTubeServer[] = []
2018-10-18 16:53:52 +02:00
before(async function () {
this.timeout(200000)
// Run server 2 to have transcoding enabled
2021-07-16 09:47:51 +02:00
servers = await createMultipleServers(2)
2018-10-18 16:53:52 +02:00
await setAccessTokensToServers(servers)
await doubleFollow(servers[0], servers[1])
2021-08-06 13:35:25 +02:00
const tempFixturePath = await generateHighBitrateVideo()
2018-10-18 16:53:52 +02:00
// Upload two videos for our needs
2021-07-16 09:04:35 +02:00
await servers[0].videos.upload({ attributes: { name: 'video1', fixture: tempFixturePath } })
await servers[0].videos.upload({ attributes: { name: 'video2', fixture: tempFixturePath } })
2018-10-18 16:53:52 +02:00
await waitJobs(servers)
})
it('Should have two video files on each server', async function () {
this.timeout(30000)
for (const server of servers) {
2021-07-16 09:04:35 +02:00
const { data } = await server.videos.list()
2021-07-15 10:02:54 +02:00
expect(data).to.have.lengthOf(2)
for (const video of data) {
2021-07-16 09:04:35 +02:00
const videoDetails = await server.videos.get({ id: video.uuid })
2021-07-15 10:02:54 +02:00
expect(videoDetails.files).to.have.lengthOf(1)
2018-10-18 16:53:52 +02:00
}
}
})
it('Should run optimize script', async function () {
2019-07-23 12:04:15 +02:00
this.timeout(200000)
2018-10-18 16:53:52 +02:00
2021-07-16 09:04:35 +02:00
await servers[0].cli.execWithEnv('npm run optimize-old-videos')
2018-10-18 16:53:52 +02:00
await waitJobs(servers)
for (const server of servers) {
2021-07-16 09:04:35 +02:00
const { data } = await server.videos.list()
2021-07-15 10:02:54 +02:00
expect(data).to.have.lengthOf(2)
2018-10-18 16:53:52 +02:00
2021-07-15 10:02:54 +02:00
for (const video of data) {
2021-07-16 09:04:35 +02:00
await server.videos.view({ id: video.uuid })
2018-10-18 16:53:52 +02:00
// Refresh video
await waitJobs(servers)
await wait(5000)
await waitJobs(servers)
2021-07-16 09:04:35 +02:00
const videoDetails = await server.videos.get({ id: video.uuid })
2018-10-18 16:53:52 +02:00
2021-07-15 10:02:54 +02:00
expect(videoDetails.files).to.have.lengthOf(1)
const file = videoDetails.files[0]
2018-10-18 16:53:52 +02:00
2019-12-06 09:55:36 +01:00
expect(file.size).to.be.below(8000000)
2018-10-18 16:53:52 +02:00
2021-07-23 11:20:00 +02:00
const path = servers[0].servers.buildWebTorrentFilePath(file.fileUrl)
2018-10-18 16:53:52 +02:00
const bitrate = await getVideoFileBitrate(path)
const fps = await getVideoFileFPS(path)
2021-08-06 13:35:25 +02:00
const data = await getVideoFileResolution(path)
expect(data.resolution).to.equal(file.resolution.id)
2018-10-18 16:53:52 +02:00
2021-08-06 13:35:25 +02:00
const maxBitrate = getMaxBitrate({ ...data, fps })
expect(bitrate).to.be.below(maxBitrate)
2018-10-18 16:53:52 +02:00
}
}
})
2019-04-24 15:10:37 +02:00
after(async function () {
await cleanupTests(servers)
2018-10-18 16:53:52 +02:00
})
})