PeerTube/server/tests/cli/create-transcoding-job.ts

207 lines
6.2 KiB
TypeScript
Raw Normal View History

2020-01-31 09:56:52 -06:00
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha'
import * as chai from 'chai'
import {
2019-04-24 08:10:37 -05:00
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
ServerInfo,
2020-01-31 09:56:52 -06:00
setAccessTokensToServers,
2021-07-15 03:02:54 -05:00
waitJobs
} from '../../../shared/extra-utils'
const expect = chai.expect
describe('Test create transcoding jobs', function () {
let servers: ServerInfo[] = []
2020-01-31 09:56:52 -06:00
const videosUUID: string[] = []
2019-11-22 03:45:03 -06:00
const config = {
transcoding: {
enabled: false,
resolutions: {
'240p': true,
'360p': true,
'480p': true,
'720p': true,
'1080p': true,
'1440p': true,
2019-11-22 03:45:03 -06:00
'2160p': true
},
hls: {
enabled: false
}
}
}
before(async function () {
this.timeout(60000)
// Run server 2 to have transcoding enabled
servers = await flushAndRunMultipleServers(2)
await setAccessTokensToServers(servers)
2021-07-07 04:51:09 -05:00
await servers[0].configCommand.updateCustomSubConfig({ newConfig: config })
2019-11-22 03:45:03 -06:00
await doubleFollow(servers[0], servers[1])
2019-11-22 03:45:03 -06:00
for (let i = 1; i <= 5; i++) {
2021-07-15 03:02:54 -05:00
const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video' + i } })
videosUUID.push(uuid)
2019-11-22 03:45:03 -06: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-15 03:02:54 -05:00
const { data } = await server.videosCommand.list()
expect(data).to.have.lengthOf(videosUUID.length)
2021-07-15 03:02:54 -05:00
for (const video of data) {
const videoDetail = await server.videosCommand.get({ id: video.uuid })
expect(videoDetail.files).to.have.lengthOf(1)
2019-11-22 03:45:03 -06:00
expect(videoDetail.streamingPlaylists).to.have.lengthOf(0)
}
}
})
it('Should run a transcoding job on video 2', async function () {
this.timeout(60000)
2021-07-05 09:37:50 -05:00
await servers[0].cliCommand.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[1]}`)
await waitJobs(servers)
for (const server of servers) {
2021-07-15 03:02:54 -05:00
const { data } = await server.videosCommand.list()
2020-01-31 09:56:52 -06:00
let infoHashes: { [id: number]: string }
2018-05-30 04:11:51 -05:00
2021-07-15 03:02:54 -05:00
for (const video of data) {
const videoDetail = await server.videosCommand.get({ id: video.uuid })
2019-11-22 03:45:03 -06:00
if (video.uuid === videosUUID[1]) {
expect(videoDetail.files).to.have.lengthOf(4)
2019-11-22 03:45:03 -06:00
expect(videoDetail.streamingPlaylists).to.have.lengthOf(0)
2018-05-30 04:11:51 -05:00
if (!infoHashes) {
infoHashes = {}
for (const file of videoDetail.files) {
infoHashes[file.resolution.id.toString()] = file.magnetUri
}
} else {
for (const resolution of Object.keys(infoHashes)) {
const file = videoDetail.files.find(f => f.resolution.id.toString() === resolution)
expect(file.magnetUri).to.equal(infoHashes[resolution])
}
}
} else {
expect(videoDetail.files).to.have.lengthOf(1)
2019-11-22 03:45:03 -06:00
expect(videoDetail.streamingPlaylists).to.have.lengthOf(0)
}
}
}
})
it('Should run a transcoding job on video 1 with resolution', async function () {
this.timeout(60000)
2021-07-05 09:37:50 -05:00
await servers[0].cliCommand.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[0]} -r 480`)
await waitJobs(servers)
for (const server of servers) {
2021-07-15 03:02:54 -05:00
const { data } = await server.videosCommand.list()
expect(data).to.have.lengthOf(videosUUID.length)
2021-07-15 03:02:54 -05:00
const videoDetails = await server.videosCommand.get({ id: videosUUID[0] })
2021-07-15 03:02:54 -05:00
expect(videoDetails.files).to.have.lengthOf(2)
expect(videoDetails.files[0].resolution.id).to.equal(720)
expect(videoDetails.files[1].resolution.id).to.equal(480)
2019-11-22 03:45:03 -06:00
2021-07-15 03:02:54 -05:00
expect(videoDetails.streamingPlaylists).to.have.lengthOf(0)
2019-11-22 03:45:03 -06:00
}
})
it('Should generate an HLS resolution', async function () {
this.timeout(120000)
2021-07-05 09:37:50 -05:00
await servers[0].cliCommand.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[2]} --generate-hls -r 480`)
2019-11-22 03:45:03 -06:00
await waitJobs(servers)
for (const server of servers) {
2021-07-15 03:02:54 -05:00
const videoDetails = await server.videosCommand.get({ id: videosUUID[2] })
2019-11-22 03:45:03 -06:00
2021-07-15 03:02:54 -05:00
expect(videoDetails.files).to.have.lengthOf(1)
expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
2019-11-22 03:45:03 -06:00
2021-07-15 03:02:54 -05:00
const files = videoDetails.streamingPlaylists[0].files
2019-11-22 03:45:03 -06:00
expect(files).to.have.lengthOf(1)
expect(files[0].resolution.id).to.equal(480)
}
})
it('Should not duplicate an HLS resolution', async function () {
this.timeout(120000)
2021-07-05 09:37:50 -05:00
await servers[0].cliCommand.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[2]} --generate-hls -r 480`)
2019-11-22 03:45:03 -06:00
await waitJobs(servers)
for (const server of servers) {
2021-07-15 03:02:54 -05:00
const videoDetails = await server.videosCommand.get({ id: videosUUID[2] })
2019-11-22 03:45:03 -06:00
2021-07-15 03:02:54 -05:00
const files = videoDetails.streamingPlaylists[0].files
2019-11-22 03:45:03 -06:00
expect(files).to.have.lengthOf(1)
expect(files[0].resolution.id).to.equal(480)
}
})
it('Should generate all HLS resolutions', async function () {
this.timeout(120000)
2021-07-05 09:37:50 -05:00
await servers[0].cliCommand.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[3]} --generate-hls`)
2019-11-22 03:45:03 -06:00
await waitJobs(servers)
for (const server of servers) {
2021-07-15 03:02:54 -05:00
const videoDetails = await server.videosCommand.get({ id: videosUUID[3] })
2019-11-22 03:45:03 -06:00
2021-07-15 03:02:54 -05:00
expect(videoDetails.files).to.have.lengthOf(1)
expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
2019-11-22 03:45:03 -06:00
2021-07-15 03:02:54 -05:00
const files = videoDetails.streamingPlaylists[0].files
2019-11-22 03:45:03 -06:00
expect(files).to.have.lengthOf(4)
}
})
it('Should optimize the video file and generate HLS videos if enabled in config', async function () {
this.timeout(120000)
config.transcoding.hls.enabled = true
2021-07-07 04:51:09 -05:00
await servers[0].configCommand.updateCustomSubConfig({ newConfig: config })
2019-11-22 03:45:03 -06:00
2021-07-05 09:37:50 -05:00
await servers[0].cliCommand.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[4]}`)
2019-11-22 03:45:03 -06:00
await waitJobs(servers)
for (const server of servers) {
2021-07-15 03:02:54 -05:00
const videoDetails = await server.videosCommand.get({ id: videosUUID[4] })
2019-11-22 03:45:03 -06:00
2021-07-15 03:02:54 -05:00
expect(videoDetails.files).to.have.lengthOf(4)
expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(4)
}
})
2019-04-24 08:10:37 -05:00
after(async function () {
await cleanupTests(servers)
})
})