2021-08-17 08:26:20 +02:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
|
|
|
|
2022-08-17 15:44:32 +02:00
|
|
|
import { expect } from 'chai'
|
2022-10-04 10:03:17 +02:00
|
|
|
import { expectStartWith, testVideoResolutions } from '@server/tests/shared'
|
2021-12-17 11:58:15 +01:00
|
|
|
import { areObjectStorageTestsDisabled } from '@shared/core-utils'
|
2022-10-04 10:03:17 +02:00
|
|
|
import { HttpStatusCode, LiveVideoCreate, VideoPrivacy } from '@shared/models'
|
2021-08-17 08:26:20 +02:00
|
|
|
import {
|
|
|
|
createMultipleServers,
|
|
|
|
doubleFollow,
|
2022-04-21 09:06:52 +02:00
|
|
|
findExternalSavedVideo,
|
2021-08-17 08:26:20 +02:00
|
|
|
killallServers,
|
|
|
|
makeRawRequest,
|
|
|
|
ObjectStorageCommand,
|
|
|
|
PeerTubeServer,
|
|
|
|
setAccessTokensToServers,
|
|
|
|
setDefaultVideoChannel,
|
|
|
|
stopFfmpeg,
|
|
|
|
waitJobs,
|
|
|
|
waitUntilLivePublishedOnAllServers,
|
2022-04-21 09:06:52 +02:00
|
|
|
waitUntilLiveReplacedByReplayOnAllServers,
|
|
|
|
waitUntilLiveWaitingOnAllServers
|
2021-12-17 09:29:23 +01:00
|
|
|
} from '@shared/server-commands'
|
2021-08-17 08:26:20 +02:00
|
|
|
|
2022-04-21 09:06:52 +02:00
|
|
|
async function createLive (server: PeerTubeServer, permanent: boolean) {
|
2021-08-17 08:26:20 +02:00
|
|
|
const attributes: LiveVideoCreate = {
|
|
|
|
channelId: server.store.channel.id,
|
|
|
|
privacy: VideoPrivacy.PUBLIC,
|
|
|
|
name: 'my super live',
|
2022-04-21 09:06:52 +02:00
|
|
|
saveReplay: true,
|
|
|
|
permanentLive: permanent
|
2021-08-17 08:26:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const { uuid } = await server.live.create({ fields: attributes })
|
|
|
|
|
|
|
|
return uuid
|
|
|
|
}
|
|
|
|
|
2022-10-04 10:03:17 +02:00
|
|
|
async function checkFilesExist (servers: PeerTubeServer[], videoUUID: string, numberOfFiles: number) {
|
|
|
|
for (const server of servers) {
|
|
|
|
const video = await server.videos.get({ id: videoUUID })
|
2021-08-17 08:26:20 +02:00
|
|
|
|
2022-10-04 10:03:17 +02:00
|
|
|
expect(video.files).to.have.lengthOf(0)
|
|
|
|
expect(video.streamingPlaylists).to.have.lengthOf(1)
|
2021-08-17 08:26:20 +02:00
|
|
|
|
2022-10-04 10:03:17 +02:00
|
|
|
const files = video.streamingPlaylists[0].files
|
|
|
|
expect(files).to.have.lengthOf(numberOfFiles)
|
2022-04-21 09:06:52 +02:00
|
|
|
|
2022-10-04 10:03:17 +02:00
|
|
|
for (const file of files) {
|
|
|
|
expectStartWith(file.fileUrl, ObjectStorageCommand.getPlaylistBaseUrl())
|
2022-04-21 09:06:52 +02:00
|
|
|
|
2022-10-04 10:03:17 +02:00
|
|
|
await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
|
|
|
|
}
|
|
|
|
}
|
2022-04-21 09:06:52 +02:00
|
|
|
}
|
|
|
|
|
2022-10-04 10:03:17 +02:00
|
|
|
async function checkFilesCleanup (server: PeerTubeServer, videoUUID: string, resolutions: number[]) {
|
|
|
|
const resolutionFiles = resolutions.map((_value, i) => `${i}.m3u8`)
|
2022-04-21 09:06:52 +02:00
|
|
|
|
2022-10-04 10:03:17 +02:00
|
|
|
for (const playlistName of [ 'master.m3u8' ].concat(resolutionFiles)) {
|
|
|
|
await server.live.getPlaylistFile({
|
|
|
|
videoUUID,
|
|
|
|
playlistName,
|
|
|
|
expectedStatus: HttpStatusCode.NOT_FOUND_404,
|
|
|
|
objectStorage: true
|
|
|
|
})
|
2022-04-21 09:06:52 +02:00
|
|
|
}
|
|
|
|
|
2022-10-04 10:03:17 +02:00
|
|
|
await server.live.getSegmentFile({
|
|
|
|
videoUUID,
|
|
|
|
playlistNumber: 0,
|
|
|
|
segment: 0,
|
|
|
|
objectStorage: true,
|
|
|
|
expectedStatus: HttpStatusCode.NOT_FOUND_404
|
|
|
|
})
|
2022-04-21 09:06:52 +02:00
|
|
|
}
|
|
|
|
|
2021-08-17 08:26:20 +02:00
|
|
|
describe('Object storage for lives', function () {
|
|
|
|
if (areObjectStorageTestsDisabled()) return
|
|
|
|
|
|
|
|
let servers: PeerTubeServer[]
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(120000)
|
|
|
|
|
|
|
|
await ObjectStorageCommand.prepareDefaultBuckets()
|
|
|
|
|
|
|
|
servers = await createMultipleServers(2, ObjectStorageCommand.getDefaultConfig())
|
|
|
|
|
|
|
|
await setAccessTokensToServers(servers)
|
|
|
|
await setDefaultVideoChannel(servers)
|
|
|
|
await doubleFollow(servers[0], servers[1])
|
|
|
|
|
|
|
|
await servers[0].config.enableTranscoding()
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('Without live transcoding', async function () {
|
2022-04-21 09:06:52 +02:00
|
|
|
let videoUUID: string
|
2021-08-17 08:26:20 +02:00
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
await servers[0].config.enableLive({ transcoding: false })
|
|
|
|
|
2022-04-21 09:06:52 +02:00
|
|
|
videoUUID = await createLive(servers[0], false)
|
2021-08-17 08:26:20 +02:00
|
|
|
})
|
|
|
|
|
2022-10-04 10:03:17 +02:00
|
|
|
it('Should create a live and publish it on object storage', async function () {
|
|
|
|
this.timeout(220000)
|
|
|
|
|
|
|
|
const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUID })
|
|
|
|
await waitUntilLivePublishedOnAllServers(servers, videoUUID)
|
|
|
|
|
|
|
|
await testVideoResolutions({
|
|
|
|
originServer: servers[0],
|
|
|
|
servers,
|
|
|
|
liveVideoId: videoUUID,
|
|
|
|
resolutions: [ 720 ],
|
|
|
|
transcoded: false,
|
|
|
|
objectStorage: true
|
|
|
|
})
|
|
|
|
|
|
|
|
await stopFfmpeg(ffmpegCommand)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should have saved the replay on object storage', async function () {
|
2021-08-17 08:26:20 +02:00
|
|
|
this.timeout(220000)
|
|
|
|
|
2022-10-04 10:03:17 +02:00
|
|
|
await waitUntilLiveReplacedByReplayOnAllServers(servers, videoUUID)
|
|
|
|
await waitJobs(servers)
|
2021-08-17 08:26:20 +02:00
|
|
|
|
2022-10-04 10:03:17 +02:00
|
|
|
await checkFilesExist(servers, videoUUID, 1)
|
|
|
|
})
|
2021-08-17 08:26:20 +02:00
|
|
|
|
2022-10-04 10:03:17 +02:00
|
|
|
it('Should have cleaned up live files from object storage', async function () {
|
|
|
|
await checkFilesCleanup(servers[0], videoUUID, [ 720 ])
|
2021-08-17 08:26:20 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('With live transcoding', async function () {
|
2022-10-04 10:03:17 +02:00
|
|
|
const resolutions = [ 720, 480, 360, 240, 144 ]
|
2021-08-17 08:26:20 +02:00
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
await servers[0].config.enableLive({ transcoding: true })
|
|
|
|
})
|
|
|
|
|
2022-10-04 10:03:17 +02:00
|
|
|
describe('Normal replay', function () {
|
|
|
|
let videoUUIDNonPermanent: string
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
videoUUIDNonPermanent = await createLive(servers[0], false)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should create a live and publish it on object storage', async function () {
|
|
|
|
this.timeout(240000)
|
|
|
|
|
|
|
|
const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUIDNonPermanent })
|
|
|
|
await waitUntilLivePublishedOnAllServers(servers, videoUUIDNonPermanent)
|
|
|
|
|
|
|
|
await testVideoResolutions({
|
|
|
|
originServer: servers[0],
|
|
|
|
servers,
|
|
|
|
liveVideoId: videoUUIDNonPermanent,
|
|
|
|
resolutions,
|
|
|
|
transcoded: true,
|
|
|
|
objectStorage: true
|
|
|
|
})
|
|
|
|
|
|
|
|
await stopFfmpeg(ffmpegCommand)
|
|
|
|
})
|
2021-08-17 08:26:20 +02:00
|
|
|
|
2022-10-04 10:03:17 +02:00
|
|
|
it('Should have saved the replay on object storage', async function () {
|
|
|
|
this.timeout(220000)
|
2021-08-17 08:26:20 +02:00
|
|
|
|
2022-10-04 10:03:17 +02:00
|
|
|
await waitUntilLiveReplacedByReplayOnAllServers(servers, videoUUIDNonPermanent)
|
|
|
|
await waitJobs(servers)
|
2021-08-17 08:26:20 +02:00
|
|
|
|
2022-10-04 10:03:17 +02:00
|
|
|
await checkFilesExist(servers, videoUUIDNonPermanent, 5)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should have cleaned up live files from object storage', async function () {
|
|
|
|
await checkFilesCleanup(servers[0], videoUUIDNonPermanent, resolutions)
|
|
|
|
})
|
2022-04-21 09:06:52 +02:00
|
|
|
})
|
2021-08-17 08:26:20 +02:00
|
|
|
|
2022-10-04 10:03:17 +02:00
|
|
|
describe('Permanent replay', function () {
|
|
|
|
let videoUUIDPermanent: string
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
videoUUIDPermanent = await createLive(servers[0], true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should create a live and publish it on object storage', async function () {
|
|
|
|
this.timeout(240000)
|
|
|
|
|
|
|
|
const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUIDPermanent })
|
|
|
|
await waitUntilLivePublishedOnAllServers(servers, videoUUIDPermanent)
|
|
|
|
|
|
|
|
await testVideoResolutions({
|
|
|
|
originServer: servers[0],
|
|
|
|
servers,
|
|
|
|
liveVideoId: videoUUIDPermanent,
|
|
|
|
resolutions,
|
|
|
|
transcoded: true,
|
|
|
|
objectStorage: true
|
|
|
|
})
|
|
|
|
|
|
|
|
await stopFfmpeg(ffmpegCommand)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should have saved the replay on object storage', async function () {
|
|
|
|
this.timeout(220000)
|
2022-04-21 09:06:52 +02:00
|
|
|
|
2022-10-04 10:03:17 +02:00
|
|
|
await waitUntilLiveWaitingOnAllServers(servers, videoUUIDPermanent)
|
|
|
|
await waitJobs(servers)
|
2021-08-17 08:26:20 +02:00
|
|
|
|
2022-10-04 10:03:17 +02:00
|
|
|
const videoLiveDetails = await servers[0].videos.get({ id: videoUUIDPermanent })
|
|
|
|
const replay = await findExternalSavedVideo(servers[0], videoLiveDetails)
|
2021-08-17 08:26:20 +02:00
|
|
|
|
2022-10-04 10:03:17 +02:00
|
|
|
await checkFilesExist(servers, replay.uuid, 5)
|
|
|
|
})
|
2021-08-17 08:26:20 +02:00
|
|
|
|
2022-10-04 10:03:17 +02:00
|
|
|
it('Should have cleaned up live files from object storage', async function () {
|
|
|
|
await checkFilesCleanup(servers[0], videoUUIDPermanent, resolutions)
|
|
|
|
})
|
2021-08-17 08:26:20 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
after(async function () {
|
|
|
|
await killallServers(servers)
|
|
|
|
})
|
|
|
|
})
|