2020-01-31 16:56:52 +01:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
2018-05-30 10:49:40 +02:00
|
|
|
|
2022-08-17 15:44:32 +02:00
|
|
|
import { expect } from 'chai'
|
2022-10-19 10:43:53 +02:00
|
|
|
import { areMockObjectStorageTestsDisabled } from '@shared/core-utils'
|
2021-08-17 08:26:20 +02:00
|
|
|
import { HttpStatusCode, VideoFile } from '@shared/models'
|
2018-05-30 10:49:40 +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,
|
2021-08-17 08:26:20 +02:00
|
|
|
makeRawRequest,
|
|
|
|
ObjectStorageCommand,
|
2021-07-16 09:47:51 +02:00
|
|
|
PeerTubeServer,
|
2020-01-31 16:56:52 +01:00
|
|
|
setAccessTokensToServers,
|
2021-07-15 10:02:54 +02:00
|
|
|
waitJobs
|
2021-12-17 11:58:15 +01:00
|
|
|
} from '@shared/server-commands'
|
2022-02-01 14:19:44 +01:00
|
|
|
import { checkResolutionsInMasterPlaylist, expectStartWith } from '../shared'
|
2018-06-13 10:06:50 +02:00
|
|
|
|
2021-08-17 08:26:20 +02:00
|
|
|
async function checkFilesInObjectStorage (files: VideoFile[], type: 'webtorrent' | 'playlist') {
|
|
|
|
for (const file of files) {
|
|
|
|
const shouldStartWith = type === 'webtorrent'
|
2022-10-19 10:43:53 +02:00
|
|
|
? ObjectStorageCommand.getMockWebTorrentBaseUrl()
|
|
|
|
: ObjectStorageCommand.getMockPlaylistBaseUrl()
|
2019-11-22 10:45:03 +01:00
|
|
|
|
2021-08-17 08:26:20 +02:00
|
|
|
expectStartWith(file.fileUrl, shouldStartWith)
|
|
|
|
|
2022-10-12 16:09:02 +02:00
|
|
|
await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
|
2019-11-22 10:45:03 +01:00
|
|
|
}
|
2021-08-17 08:26:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function runTests (objectStorage: boolean) {
|
|
|
|
let servers: PeerTubeServer[] = []
|
|
|
|
const videosUUID: string[] = []
|
2021-10-08 15:34:07 +02:00
|
|
|
const publishedAt: string[] = []
|
2018-05-30 10:49:40 +02:00
|
|
|
|
|
|
|
before(async function () {
|
2021-10-08 15:34:07 +02:00
|
|
|
this.timeout(120000)
|
2018-05-30 10:49:40 +02:00
|
|
|
|
2021-08-17 08:26:20 +02:00
|
|
|
const config = objectStorage
|
2022-10-19 10:43:53 +02:00
|
|
|
? ObjectStorageCommand.getDefaultMockConfig()
|
2021-08-17 08:26:20 +02:00
|
|
|
: {}
|
|
|
|
|
2018-05-30 10:49:40 +02:00
|
|
|
// Run server 2 to have transcoding enabled
|
2021-08-17 08:26:20 +02:00
|
|
|
servers = await createMultipleServers(2, config)
|
2018-05-30 10:49:40 +02:00
|
|
|
await setAccessTokensToServers(servers)
|
|
|
|
|
2021-08-17 08:26:20 +02:00
|
|
|
await servers[0].config.disableTranscoding()
|
2019-11-22 10:45:03 +01:00
|
|
|
|
2018-05-30 10:49:40 +02:00
|
|
|
await doubleFollow(servers[0], servers[1])
|
|
|
|
|
2022-10-19 10:43:53 +02:00
|
|
|
if (objectStorage) await ObjectStorageCommand.prepareDefaultMockBuckets()
|
2021-08-17 08:26:20 +02:00
|
|
|
|
2019-11-22 10:45:03 +01:00
|
|
|
for (let i = 1; i <= 5; i++) {
|
2021-08-17 11:06:10 +02:00
|
|
|
const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'video' + i } })
|
|
|
|
|
2021-10-08 15:34:07 +02:00
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
const video = await servers[0].videos.get({ id: uuid })
|
|
|
|
publishedAt.push(video.publishedAt as string)
|
|
|
|
|
2021-08-17 11:06:10 +02:00
|
|
|
if (i > 2) {
|
|
|
|
videosUUID.push(uuid)
|
|
|
|
} else {
|
|
|
|
videosUUID.push(shortUUID)
|
|
|
|
}
|
2019-11-22 10:45:03 +01:00
|
|
|
}
|
2018-05-30 10:49:40 +02:00
|
|
|
|
2018-06-13 10:06:50 +02:00
|
|
|
await waitJobs(servers)
|
2018-05-30 10:49:40 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
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(videosUUID.length)
|
2018-05-30 10:49:40 +02:00
|
|
|
|
2021-07-15 10:02:54 +02:00
|
|
|
for (const video of data) {
|
2021-07-16 09:04:35 +02:00
|
|
|
const videoDetail = await server.videos.get({ id: video.uuid })
|
2018-05-30 10:49:40 +02:00
|
|
|
expect(videoDetail.files).to.have.lengthOf(1)
|
2019-11-22 10:45:03 +01:00
|
|
|
expect(videoDetail.streamingPlaylists).to.have.lengthOf(0)
|
2018-05-30 10:49:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should run a transcoding job on video 2', async function () {
|
|
|
|
this.timeout(60000)
|
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[0].cli.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[1]}`)
|
2018-06-13 10:06:50 +02:00
|
|
|
await waitJobs(servers)
|
2018-05-30 10:49:40 +02:00
|
|
|
|
|
|
|
for (const server of servers) {
|
2021-07-16 09:04:35 +02:00
|
|
|
const { data } = await server.videos.list()
|
2018-05-30 10:49:40 +02:00
|
|
|
|
2020-01-31 16:56:52 +01:00
|
|
|
let infoHashes: { [id: number]: string }
|
2018-05-30 11:11:51 +02:00
|
|
|
|
2021-07-15 10:02:54 +02:00
|
|
|
for (const video of data) {
|
2021-08-17 08:26:20 +02:00
|
|
|
const videoDetails = await server.videos.get({ id: video.uuid })
|
2018-05-30 10:49:40 +02:00
|
|
|
|
2021-08-17 11:06:10 +02:00
|
|
|
if (video.shortUUID === videosUUID[1] || video.uuid === videosUUID[1]) {
|
2021-08-17 08:26:20 +02:00
|
|
|
expect(videoDetails.files).to.have.lengthOf(4)
|
|
|
|
expect(videoDetails.streamingPlaylists).to.have.lengthOf(0)
|
|
|
|
|
|
|
|
if (objectStorage) await checkFilesInObjectStorage(videoDetails.files, 'webtorrent')
|
2018-05-30 11:11:51 +02:00
|
|
|
|
|
|
|
if (!infoHashes) {
|
|
|
|
infoHashes = {}
|
|
|
|
|
2021-08-17 08:26:20 +02:00
|
|
|
for (const file of videoDetails.files) {
|
2018-05-30 11:11:51 +02:00
|
|
|
infoHashes[file.resolution.id.toString()] = file.magnetUri
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (const resolution of Object.keys(infoHashes)) {
|
2021-08-17 08:26:20 +02:00
|
|
|
const file = videoDetails.files.find(f => f.resolution.id.toString() === resolution)
|
2018-05-30 11:11:51 +02:00
|
|
|
expect(file.magnetUri).to.equal(infoHashes[resolution])
|
|
|
|
}
|
|
|
|
}
|
2018-05-30 10:49:40 +02:00
|
|
|
} else {
|
2021-08-17 08:26:20 +02:00
|
|
|
expect(videoDetails.files).to.have.lengthOf(1)
|
|
|
|
expect(videoDetails.streamingPlaylists).to.have.lengthOf(0)
|
2018-05-30 10:49:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-06-15 18:27:35 +02:00
|
|
|
it('Should run a transcoding job on video 1 with resolution', async function () {
|
|
|
|
this.timeout(60000)
|
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[0].cli.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[0]} -r 480`)
|
2018-06-15 18:27:35 +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(videosUUID.length)
|
2018-06-15 18:27:35 +02:00
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
const videoDetails = await server.videos.get({ id: videosUUID[0] })
|
2018-06-15 18:27:35 +02:00
|
|
|
|
2021-07-15 10:02:54 +02: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 10:45:03 +01:00
|
|
|
|
2021-07-15 10:02:54 +02:00
|
|
|
expect(videoDetails.streamingPlaylists).to.have.lengthOf(0)
|
2021-08-17 08:26:20 +02:00
|
|
|
|
|
|
|
if (objectStorage) await checkFilesInObjectStorage(videoDetails.files, 'webtorrent')
|
2019-11-22 10:45:03 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should generate an HLS resolution', async function () {
|
|
|
|
this.timeout(120000)
|
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[0].cli.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[2]} --generate-hls -r 480`)
|
2019-11-22 10:45:03 +01:00
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
for (const server of servers) {
|
2021-07-16 09:04:35 +02:00
|
|
|
const videoDetails = await server.videos.get({ id: videosUUID[2] })
|
2019-11-22 10:45:03 +01:00
|
|
|
|
2021-07-15 10:02:54 +02:00
|
|
|
expect(videoDetails.files).to.have.lengthOf(1)
|
2021-08-17 08:26:20 +02:00
|
|
|
if (objectStorage) await checkFilesInObjectStorage(videoDetails.files, 'webtorrent')
|
|
|
|
|
2021-07-15 10:02:54 +02:00
|
|
|
expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
|
2019-11-22 10:45:03 +01:00
|
|
|
|
2022-02-01 14:19:44 +01:00
|
|
|
const hlsPlaylist = videoDetails.streamingPlaylists[0]
|
|
|
|
|
|
|
|
const files = hlsPlaylist.files
|
2019-11-22 10:45:03 +01:00
|
|
|
expect(files).to.have.lengthOf(1)
|
|
|
|
expect(files[0].resolution.id).to.equal(480)
|
2021-08-17 08:26:20 +02:00
|
|
|
|
2022-02-01 14:19:44 +01:00
|
|
|
if (objectStorage) {
|
|
|
|
await checkFilesInObjectStorage(files, 'playlist')
|
|
|
|
|
|
|
|
const resolutions = files.map(f => f.resolution.id)
|
|
|
|
await checkResolutionsInMasterPlaylist({ server, playlistUrl: hlsPlaylist.playlistUrl, resolutions })
|
|
|
|
}
|
2019-11-22 10:45:03 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not duplicate an HLS resolution', async function () {
|
|
|
|
this.timeout(120000)
|
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[0].cli.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[2]} --generate-hls -r 480`)
|
2019-11-22 10:45:03 +01:00
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
for (const server of servers) {
|
2021-07-16 09:04:35 +02:00
|
|
|
const videoDetails = await server.videos.get({ id: videosUUID[2] })
|
2019-11-22 10:45:03 +01:00
|
|
|
|
2021-07-15 10:02:54 +02:00
|
|
|
const files = videoDetails.streamingPlaylists[0].files
|
2019-11-22 10:45:03 +01:00
|
|
|
expect(files).to.have.lengthOf(1)
|
|
|
|
expect(files[0].resolution.id).to.equal(480)
|
2021-08-17 08:26:20 +02:00
|
|
|
|
|
|
|
if (objectStorage) await checkFilesInObjectStorage(files, 'playlist')
|
2019-11-22 10:45:03 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should generate all HLS resolutions', async function () {
|
|
|
|
this.timeout(120000)
|
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[0].cli.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[3]} --generate-hls`)
|
2019-11-22 10:45:03 +01:00
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
for (const server of servers) {
|
2021-07-16 09:04:35 +02:00
|
|
|
const videoDetails = await server.videos.get({ id: videosUUID[3] })
|
2019-11-22 10:45:03 +01:00
|
|
|
|
2021-07-15 10:02:54 +02:00
|
|
|
expect(videoDetails.files).to.have.lengthOf(1)
|
|
|
|
expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
|
2019-11-22 10:45:03 +01:00
|
|
|
|
2021-07-15 10:02:54 +02:00
|
|
|
const files = videoDetails.streamingPlaylists[0].files
|
2019-11-22 10:45:03 +01:00
|
|
|
expect(files).to.have.lengthOf(4)
|
2021-08-17 08:26:20 +02:00
|
|
|
|
|
|
|
if (objectStorage) await checkFilesInObjectStorage(files, 'playlist')
|
2019-11-22 10:45:03 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should optimize the video file and generate HLS videos if enabled in config', async function () {
|
|
|
|
this.timeout(120000)
|
|
|
|
|
2021-08-17 08:26:20 +02:00
|
|
|
await servers[0].config.enableTranscoding()
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[0].cli.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[4]}`)
|
2019-11-22 10:45:03 +01:00
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
for (const server of servers) {
|
2021-07-16 09:04:35 +02:00
|
|
|
const videoDetails = await server.videos.get({ id: videosUUID[4] })
|
2019-11-22 10:45:03 +01:00
|
|
|
|
2021-11-05 10:23:02 +01:00
|
|
|
expect(videoDetails.files).to.have.lengthOf(5)
|
2021-07-15 10:02:54 +02:00
|
|
|
expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
|
2021-11-05 10:23:02 +01:00
|
|
|
expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5)
|
2021-08-17 08:26:20 +02:00
|
|
|
|
|
|
|
if (objectStorage) {
|
|
|
|
await checkFilesInObjectStorage(videoDetails.files, 'webtorrent')
|
|
|
|
await checkFilesInObjectStorage(videoDetails.streamingPlaylists[0].files, 'playlist')
|
|
|
|
}
|
2018-06-15 18:27:35 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-10-08 15:34:07 +02:00
|
|
|
it('Should not have updated published at attributes', async function () {
|
|
|
|
for (const id of videosUUID) {
|
|
|
|
const video = await servers[0].videos.get({ id })
|
|
|
|
|
|
|
|
expect(publishedAt.some(p => video.publishedAt === p)).to.be.true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-04-24 15:10:37 +02:00
|
|
|
after(async function () {
|
|
|
|
await cleanupTests(servers)
|
2018-05-30 10:49:40 +02:00
|
|
|
})
|
2021-08-17 08:26:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
describe('Test create transcoding jobs', function () {
|
|
|
|
|
|
|
|
describe('On filesystem', function () {
|
|
|
|
runTests(false)
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('On object storage', function () {
|
2022-10-19 10:43:53 +02:00
|
|
|
if (areMockObjectStorageTestsDisabled()) return
|
2021-08-17 08:26:20 +02:00
|
|
|
|
|
|
|
runTests(true)
|
|
|
|
})
|
2018-05-30 10:49:40 +02:00
|
|
|
})
|