2021-11-18 07:35:08 -06:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
|
|
|
|
2022-08-17 08:44:32 -05:00
|
|
|
import { expect } from 'chai'
|
2022-02-01 07:19:44 -06:00
|
|
|
import { checkResolutionsInMasterPlaylist, expectStartWith } from '@server/tests/shared'
|
2022-10-19 03:43:53 -05:00
|
|
|
import { areMockObjectStorageTestsDisabled } from '@shared/core-utils'
|
2021-12-17 04:58:15 -06:00
|
|
|
import { HttpStatusCode, VideoDetails } from '@shared/models'
|
2021-11-18 07:35:08 -06:00
|
|
|
import {
|
|
|
|
cleanupTests,
|
2022-02-01 07:19:44 -06:00
|
|
|
ConfigCommand,
|
2021-11-18 07:35:08 -06:00
|
|
|
createMultipleServers,
|
|
|
|
doubleFollow,
|
2021-11-23 08:22:07 -06:00
|
|
|
expectNoFailedTranscodingJob,
|
2021-11-18 07:35:08 -06:00
|
|
|
makeRawRequest,
|
|
|
|
ObjectStorageCommand,
|
|
|
|
PeerTubeServer,
|
|
|
|
setAccessTokensToServers,
|
|
|
|
waitJobs
|
2021-12-17 02:29:23 -06:00
|
|
|
} from '@shared/server-commands'
|
2021-11-18 07:35:08 -06:00
|
|
|
|
2023-05-23 03:49:45 -05:00
|
|
|
async function checkFilesInObjectStorage (objectStorage: ObjectStorageCommand, video: VideoDetails) {
|
2021-11-18 07:35:08 -06:00
|
|
|
for (const file of video.files) {
|
2023-05-23 03:49:45 -05:00
|
|
|
expectStartWith(file.fileUrl, objectStorage.getMockWebVideosBaseUrl())
|
2022-10-12 09:09:02 -05:00
|
|
|
await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
|
2021-11-18 07:35:08 -06:00
|
|
|
}
|
|
|
|
|
2022-02-01 07:19:44 -06:00
|
|
|
if (video.streamingPlaylists.length === 0) return
|
2022-02-01 04:16:45 -06:00
|
|
|
|
2022-02-01 07:19:44 -06:00
|
|
|
const hlsPlaylist = video.streamingPlaylists[0]
|
|
|
|
for (const file of hlsPlaylist.files) {
|
2023-05-23 03:49:45 -05:00
|
|
|
expectStartWith(file.fileUrl, objectStorage.getMockPlaylistBaseUrl())
|
2022-10-12 09:09:02 -05:00
|
|
|
await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
|
2021-11-18 07:35:08 -06:00
|
|
|
}
|
2022-02-01 07:19:44 -06:00
|
|
|
|
2023-05-23 03:49:45 -05:00
|
|
|
expectStartWith(hlsPlaylist.playlistUrl, objectStorage.getMockPlaylistBaseUrl())
|
2022-10-12 09:09:02 -05:00
|
|
|
await makeRawRequest({ url: hlsPlaylist.playlistUrl, expectedStatus: HttpStatusCode.OK_200 })
|
2022-02-01 07:19:44 -06:00
|
|
|
|
2023-05-23 03:49:45 -05:00
|
|
|
expectStartWith(hlsPlaylist.segmentsSha256Url, objectStorage.getMockPlaylistBaseUrl())
|
2022-10-12 09:09:02 -05:00
|
|
|
await makeRawRequest({ url: hlsPlaylist.segmentsSha256Url, expectedStatus: HttpStatusCode.OK_200 })
|
2021-11-18 07:35:08 -06:00
|
|
|
}
|
|
|
|
|
2023-05-23 03:49:45 -05:00
|
|
|
function runTests (enableObjectStorage: boolean) {
|
2021-11-18 07:35:08 -06:00
|
|
|
let servers: PeerTubeServer[] = []
|
|
|
|
let videoUUID: string
|
|
|
|
let publishedAt: string
|
|
|
|
|
2022-07-25 03:57:16 -05:00
|
|
|
let shouldBeDeleted: string[]
|
2023-05-23 03:49:45 -05:00
|
|
|
const objectStorage = new ObjectStorageCommand()
|
2022-07-25 03:57:16 -05:00
|
|
|
|
2021-11-18 07:35:08 -06:00
|
|
|
before(async function () {
|
|
|
|
this.timeout(120000)
|
|
|
|
|
2023-05-23 03:49:45 -05:00
|
|
|
const config = enableObjectStorage
|
|
|
|
? objectStorage.getDefaultMockConfig()
|
2021-11-18 07:35:08 -06:00
|
|
|
: {}
|
|
|
|
|
|
|
|
// Run server 2 to have transcoding enabled
|
|
|
|
servers = await createMultipleServers(2, config)
|
|
|
|
await setAccessTokensToServers(servers)
|
|
|
|
|
|
|
|
await servers[0].config.disableTranscoding()
|
|
|
|
|
|
|
|
await doubleFollow(servers[0], servers[1])
|
|
|
|
|
2023-05-23 03:49:45 -05:00
|
|
|
if (enableObjectStorage) await objectStorage.prepareDefaultMockBuckets()
|
2021-11-18 07:35:08 -06:00
|
|
|
|
|
|
|
const { shortUUID } = await servers[0].videos.quickUpload({ name: 'video' })
|
|
|
|
videoUUID = shortUUID
|
|
|
|
|
2021-11-18 09:29:42 -06:00
|
|
|
await waitJobs(servers)
|
|
|
|
|
2021-11-18 07:35:08 -06:00
|
|
|
const video = await servers[0].videos.get({ id: videoUUID })
|
|
|
|
publishedAt = video.publishedAt as string
|
|
|
|
|
|
|
|
await servers[0].config.enableTranscoding()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should generate HLS', async function () {
|
|
|
|
this.timeout(60000)
|
|
|
|
|
|
|
|
await servers[0].videos.runTranscoding({
|
|
|
|
videoId: videoUUID,
|
|
|
|
transcodingType: 'hls'
|
|
|
|
})
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
await expectNoFailedTranscodingJob(servers[0])
|
|
|
|
|
|
|
|
for (const server of servers) {
|
|
|
|
const videoDetails = await server.videos.get({ id: videoUUID })
|
|
|
|
|
|
|
|
expect(videoDetails.files).to.have.lengthOf(1)
|
|
|
|
expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
|
|
|
|
expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5)
|
|
|
|
|
2023-05-23 03:49:45 -05:00
|
|
|
if (enableObjectStorage) await checkFilesInObjectStorage(objectStorage, videoDetails)
|
2021-11-18 07:35:08 -06:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should generate WebTorrent', async function () {
|
|
|
|
this.timeout(60000)
|
|
|
|
|
|
|
|
await servers[0].videos.runTranscoding({
|
|
|
|
videoId: videoUUID,
|
|
|
|
transcodingType: 'webtorrent'
|
|
|
|
})
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
for (const server of servers) {
|
|
|
|
const videoDetails = await server.videos.get({ id: videoUUID })
|
|
|
|
|
|
|
|
expect(videoDetails.files).to.have.lengthOf(5)
|
|
|
|
expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
|
|
|
|
expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5)
|
|
|
|
|
2023-05-23 03:49:45 -05:00
|
|
|
if (enableObjectStorage) await checkFilesInObjectStorage(objectStorage, videoDetails)
|
2021-11-18 07:35:08 -06:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should generate WebTorrent from HLS only video', async function () {
|
|
|
|
this.timeout(60000)
|
|
|
|
|
2022-07-29 07:50:41 -05:00
|
|
|
await servers[0].videos.removeAllWebTorrentFiles({ videoId: videoUUID })
|
2021-11-18 07:35:08 -06:00
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
await servers[0].videos.runTranscoding({ videoId: videoUUID, transcodingType: 'webtorrent' })
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
for (const server of servers) {
|
|
|
|
const videoDetails = await server.videos.get({ id: videoUUID })
|
|
|
|
|
|
|
|
expect(videoDetails.files).to.have.lengthOf(5)
|
|
|
|
expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
|
|
|
|
expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5)
|
|
|
|
|
2023-05-23 03:49:45 -05:00
|
|
|
if (enableObjectStorage) await checkFilesInObjectStorage(objectStorage, videoDetails)
|
2021-11-18 07:35:08 -06:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-02-01 04:16:45 -06:00
|
|
|
it('Should only generate WebTorrent', async function () {
|
|
|
|
this.timeout(60000)
|
|
|
|
|
2022-07-29 07:50:41 -05:00
|
|
|
await servers[0].videos.removeHLSPlaylist({ videoId: videoUUID })
|
2022-02-01 04:16:45 -06:00
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
await servers[0].videos.runTranscoding({ videoId: videoUUID, transcodingType: 'webtorrent' })
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
for (const server of servers) {
|
|
|
|
const videoDetails = await server.videos.get({ id: videoUUID })
|
|
|
|
|
|
|
|
expect(videoDetails.files).to.have.lengthOf(5)
|
|
|
|
expect(videoDetails.streamingPlaylists).to.have.lengthOf(0)
|
|
|
|
|
2023-05-23 03:49:45 -05:00
|
|
|
if (enableObjectStorage) await checkFilesInObjectStorage(objectStorage, videoDetails)
|
2022-02-01 04:16:45 -06:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-02-01 07:19:44 -06:00
|
|
|
it('Should correctly update HLS playlist on resolution change', async function () {
|
2022-02-03 07:21:40 -06:00
|
|
|
this.timeout(120000)
|
|
|
|
|
2022-02-01 07:19:44 -06:00
|
|
|
await servers[0].config.updateExistingSubConfig({
|
|
|
|
newConfig: {
|
|
|
|
transcoding: {
|
|
|
|
enabled: true,
|
|
|
|
resolutions: ConfigCommand.getCustomConfigResolutions(false),
|
|
|
|
|
|
|
|
webtorrent: {
|
|
|
|
enabled: true
|
|
|
|
},
|
|
|
|
hls: {
|
|
|
|
enabled: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
const { uuid } = await servers[0].videos.quickUpload({ name: 'quick' })
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
for (const server of servers) {
|
|
|
|
const videoDetails = await server.videos.get({ id: uuid })
|
|
|
|
|
|
|
|
expect(videoDetails.files).to.have.lengthOf(1)
|
|
|
|
expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
|
|
|
|
expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(1)
|
|
|
|
|
2023-05-23 03:49:45 -05:00
|
|
|
if (enableObjectStorage) await checkFilesInObjectStorage(objectStorage, videoDetails)
|
2022-07-25 03:57:16 -05:00
|
|
|
|
|
|
|
shouldBeDeleted = [
|
|
|
|
videoDetails.streamingPlaylists[0].files[0].fileUrl,
|
|
|
|
videoDetails.streamingPlaylists[0].playlistUrl,
|
|
|
|
videoDetails.streamingPlaylists[0].segmentsSha256Url
|
|
|
|
]
|
2022-02-01 07:19:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
await servers[0].config.updateExistingSubConfig({
|
|
|
|
newConfig: {
|
|
|
|
transcoding: {
|
|
|
|
enabled: true,
|
|
|
|
resolutions: ConfigCommand.getCustomConfigResolutions(true),
|
|
|
|
|
|
|
|
webtorrent: {
|
|
|
|
enabled: true
|
|
|
|
},
|
|
|
|
hls: {
|
|
|
|
enabled: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
await servers[0].videos.runTranscoding({ videoId: uuid, transcodingType: 'hls' })
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
for (const server of servers) {
|
|
|
|
const videoDetails = await server.videos.get({ id: uuid })
|
|
|
|
|
|
|
|
expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
|
|
|
|
expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5)
|
|
|
|
|
2023-05-23 03:49:45 -05:00
|
|
|
if (enableObjectStorage) {
|
|
|
|
await checkFilesInObjectStorage(objectStorage, videoDetails)
|
2022-02-01 07:19:44 -06:00
|
|
|
|
|
|
|
const hlsPlaylist = videoDetails.streamingPlaylists[0]
|
|
|
|
const resolutions = hlsPlaylist.files.map(f => f.resolution.id)
|
|
|
|
await checkResolutionsInMasterPlaylist({ server: servers[0], playlistUrl: hlsPlaylist.playlistUrl, resolutions })
|
|
|
|
|
2023-05-10 02:28:42 -05:00
|
|
|
const shaBody = await servers[0].streamingPlaylists.getSegmentSha256({ url: hlsPlaylist.segmentsSha256Url, withRetry: true })
|
2022-02-01 07:19:44 -06:00
|
|
|
expect(Object.keys(shaBody)).to.have.lengthOf(5)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-07-25 03:57:16 -05:00
|
|
|
it('Should have correctly deleted previous files', async function () {
|
|
|
|
for (const fileUrl of shouldBeDeleted) {
|
2022-10-12 09:09:02 -05:00
|
|
|
await makeRawRequest({ url: fileUrl, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
|
2022-07-25 03:57:16 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-11-18 07:35:08 -06:00
|
|
|
it('Should not have updated published at attributes', async function () {
|
|
|
|
const video = await servers[0].videos.get({ id: videoUUID })
|
|
|
|
|
|
|
|
expect(video.publishedAt).to.equal(publishedAt)
|
|
|
|
})
|
|
|
|
|
|
|
|
after(async function () {
|
2023-05-23 03:49:45 -05:00
|
|
|
if (objectStorage) await objectStorage.cleanupMock()
|
|
|
|
|
2021-11-18 07:35:08 -06:00
|
|
|
await cleanupTests(servers)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('Test create transcoding jobs from API', function () {
|
|
|
|
|
|
|
|
describe('On filesystem', function () {
|
|
|
|
runTests(false)
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('On object storage', function () {
|
2022-10-19 03:43:53 -05:00
|
|
|
if (areMockObjectStorageTestsDisabled()) return
|
2021-11-18 07:35:08 -06:00
|
|
|
|
|
|
|
runTests(true)
|
|
|
|
})
|
|
|
|
})
|