1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 import { expect } from 'chai'
4 checkPeerTubeRunnerCacheIsEmpty,
8 testLiveVideoResolutions
9 } from '@server/tests/shared'
10 import { areMockObjectStorageTestsDisabled, wait } from '@shared/core-utils'
11 import { HttpStatusCode, VideoPrivacy } from '@shared/models'
14 createMultipleServers,
16 findExternalSavedVideo,
20 setAccessTokensToServers,
21 setDefaultVideoChannel,
24 waitUntilLivePublishedOnAllServers,
25 waitUntilLiveWaitingOnAllServers
26 } from '@shared/server-commands'
28 describe('Test Live transcoding in peertube-runner program', function () {
29 let servers: PeerTubeServer[] = []
30 let peertubeRunner: PeerTubeRunnerProcess
31 let sqlCommandServer1: SQLCommand
33 function runSuite (options: {
34 objectStorage: boolean
36 const { objectStorage } = options
38 it('Should enable transcoding without additional resolutions', async function () {
41 const { video } = await servers[0].live.quickCreate({ permanentLive: true, saveReplay: false, privacy: VideoPrivacy.PUBLIC })
43 const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: video.uuid })
44 await waitUntilLivePublishedOnAllServers(servers, video.uuid)
45 await waitJobs(servers)
47 await testLiveVideoResolutions({
48 originServer: servers[0],
49 sqlCommand: sqlCommandServer1,
51 liveVideoId: video.uuid,
52 resolutions: [ 720, 480, 360, 240, 144 ],
57 await stopFfmpeg(ffmpegCommand)
59 await waitUntilLiveWaitingOnAllServers(servers, video.uuid)
60 await servers[0].videos.remove({ id: video.id })
63 it('Should transcode audio only RTMP stream', async function () {
66 const { video } = await servers[0].live.quickCreate({ permanentLive: true, saveReplay: false, privacy: VideoPrivacy.UNLISTED })
68 const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: video.uuid, fixtureName: 'video_short_no_audio.mp4' })
69 await waitUntilLivePublishedOnAllServers(servers, video.uuid)
70 await waitJobs(servers)
72 await stopFfmpeg(ffmpegCommand)
74 await waitUntilLiveWaitingOnAllServers(servers, video.uuid)
75 await servers[0].videos.remove({ id: video.id })
78 it('Should save a replay', async function () {
81 const { video } = await servers[0].live.quickCreate({ permanentLive: true, saveReplay: true })
83 const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: video.uuid })
84 await waitUntilLivePublishedOnAllServers(servers, video.uuid)
86 await testLiveVideoResolutions({
87 originServer: servers[0],
88 sqlCommand: sqlCommandServer1,
90 liveVideoId: video.uuid,
91 resolutions: [ 720, 480, 360, 240, 144 ],
96 await stopFfmpeg(ffmpegCommand)
98 await waitUntilLiveWaitingOnAllServers(servers, video.uuid)
99 await waitJobs(servers)
101 const session = await servers[0].live.findLatestSession({ videoId: video.uuid })
102 expect(session.endingProcessed).to.be.true
103 expect(session.endDate).to.exist
104 expect(session.saveReplay).to.be.true
106 const videoLiveDetails = await servers[0].videos.get({ id: video.uuid })
107 const replay = await findExternalSavedVideo(servers[0], videoLiveDetails)
109 for (const server of servers) {
110 const video = await server.videos.get({ id: replay.uuid })
112 expect(video.files).to.have.lengthOf(0)
113 expect(video.streamingPlaylists).to.have.lengthOf(1)
115 const files = video.streamingPlaylists[0].files
116 expect(files).to.have.lengthOf(5)
118 for (const file of files) {
120 expectStartWith(file.fileUrl, ObjectStorageCommand.getMockPlaylistBaseUrl())
123 await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
129 before(async function () {
130 this.timeout(120_000)
132 servers = await createMultipleServers(2)
134 await setAccessTokensToServers(servers)
135 await setDefaultVideoChannel(servers)
137 await doubleFollow(servers[0], servers[1])
139 sqlCommandServer1 = new SQLCommand(servers[0])
141 await servers[0].config.enableRemoteTranscoding()
142 await servers[0].config.enableTranscoding(true, true, true)
143 await servers[0].config.enableLive({ allowReplay: true, resolutions: 'max', transcoding: true })
145 const registrationToken = await servers[0].runnerRegistrationTokens.getFirstRegistrationToken()
147 peertubeRunner = new PeerTubeRunnerProcess(servers[0])
148 await peertubeRunner.runServer()
149 await peertubeRunner.registerPeerTubeInstance({ registrationToken, runnerName: 'runner' })
152 describe('With lives on local filesystem storage', function () {
154 before(async function () {
155 await servers[0].config.enableTranscoding(true, false, true)
158 runSuite({ objectStorage: false })
161 describe('With lives on object storage', function () {
162 if (areMockObjectStorageTestsDisabled()) return
164 before(async function () {
165 await ObjectStorageCommand.prepareDefaultMockBuckets()
167 await servers[0].kill()
169 await servers[0].run(ObjectStorageCommand.getDefaultMockConfig())
171 // Wait for peertube runner socket reconnection
175 runSuite({ objectStorage: true })
178 describe('Check cleanup', function () {
180 it('Should have an empty cache directory', async function () {
181 await checkPeerTubeRunnerCacheIsEmpty(peertubeRunner)
185 after(async function () {
186 if (peertubeRunner) {
187 await peertubeRunner.unregisterPeerTubeInstance()
188 peertubeRunner.kill()
191 if (sqlCommandServer1) await sqlCommandServer1.cleanup()
193 await cleanupTests(servers)