diff options
Diffstat (limited to 'packages/tests/src/peertube-runner/live-transcoding.ts')
-rw-r--r-- | packages/tests/src/peertube-runner/live-transcoding.ts | 200 |
1 files changed, 200 insertions, 0 deletions
diff --git a/packages/tests/src/peertube-runner/live-transcoding.ts b/packages/tests/src/peertube-runner/live-transcoding.ts new file mode 100644 index 000000000..9351bc5e2 --- /dev/null +++ b/packages/tests/src/peertube-runner/live-transcoding.ts | |||
@@ -0,0 +1,200 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | import { expect } from 'chai' | ||
3 | import { wait } from '@peertube/peertube-core-utils' | ||
4 | import { HttpStatusCode, VideoPrivacy } from '@peertube/peertube-models' | ||
5 | import { areMockObjectStorageTestsDisabled } from '@peertube/peertube-node-utils' | ||
6 | import { | ||
7 | cleanupTests, | ||
8 | createMultipleServers, | ||
9 | doubleFollow, | ||
10 | findExternalSavedVideo, | ||
11 | makeRawRequest, | ||
12 | ObjectStorageCommand, | ||
13 | PeerTubeServer, | ||
14 | setAccessTokensToServers, | ||
15 | setDefaultVideoChannel, | ||
16 | stopFfmpeg, | ||
17 | waitJobs, | ||
18 | waitUntilLivePublishedOnAllServers, | ||
19 | waitUntilLiveWaitingOnAllServers | ||
20 | } from '@peertube/peertube-server-commands' | ||
21 | import { expectStartWith } from '@tests/shared/checks.js' | ||
22 | import { checkPeerTubeRunnerCacheIsEmpty } from '@tests/shared/directories.js' | ||
23 | import { testLiveVideoResolutions } from '@tests/shared/live.js' | ||
24 | import { PeerTubeRunnerProcess } from '@tests/shared/peertube-runner-process.js' | ||
25 | import { SQLCommand } from '@tests/shared/sql-command.js' | ||
26 | |||
27 | describe('Test Live transcoding in peertube-runner program', function () { | ||
28 | let servers: PeerTubeServer[] = [] | ||
29 | let peertubeRunner: PeerTubeRunnerProcess | ||
30 | let sqlCommandServer1: SQLCommand | ||
31 | |||
32 | function runSuite (options: { | ||
33 | objectStorage?: ObjectStorageCommand | ||
34 | } = {}) { | ||
35 | const { objectStorage } = options | ||
36 | |||
37 | it('Should enable transcoding without additional resolutions', async function () { | ||
38 | this.timeout(120000) | ||
39 | |||
40 | const { video } = await servers[0].live.quickCreate({ permanentLive: true, saveReplay: false, privacy: VideoPrivacy.PUBLIC }) | ||
41 | |||
42 | const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: video.uuid }) | ||
43 | await waitUntilLivePublishedOnAllServers(servers, video.uuid) | ||
44 | await waitJobs(servers) | ||
45 | |||
46 | await testLiveVideoResolutions({ | ||
47 | originServer: servers[0], | ||
48 | sqlCommand: sqlCommandServer1, | ||
49 | servers, | ||
50 | liveVideoId: video.uuid, | ||
51 | resolutions: [ 720, 480, 360, 240, 144 ], | ||
52 | objectStorage, | ||
53 | transcoded: true | ||
54 | }) | ||
55 | |||
56 | await stopFfmpeg(ffmpegCommand) | ||
57 | |||
58 | await waitUntilLiveWaitingOnAllServers(servers, video.uuid) | ||
59 | await servers[0].videos.remove({ id: video.id }) | ||
60 | }) | ||
61 | |||
62 | it('Should transcode audio only RTMP stream', async function () { | ||
63 | this.timeout(120000) | ||
64 | |||
65 | const { video } = await servers[0].live.quickCreate({ permanentLive: true, saveReplay: false, privacy: VideoPrivacy.UNLISTED }) | ||
66 | |||
67 | const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: video.uuid, fixtureName: 'video_short_no_audio.mp4' }) | ||
68 | await waitUntilLivePublishedOnAllServers(servers, video.uuid) | ||
69 | await waitJobs(servers) | ||
70 | |||
71 | await stopFfmpeg(ffmpegCommand) | ||
72 | |||
73 | await waitUntilLiveWaitingOnAllServers(servers, video.uuid) | ||
74 | await servers[0].videos.remove({ id: video.id }) | ||
75 | }) | ||
76 | |||
77 | it('Should save a replay', async function () { | ||
78 | this.timeout(240000) | ||
79 | |||
80 | const { video } = await servers[0].live.quickCreate({ permanentLive: true, saveReplay: true }) | ||
81 | |||
82 | const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: video.uuid }) | ||
83 | await waitUntilLivePublishedOnAllServers(servers, video.uuid) | ||
84 | |||
85 | await testLiveVideoResolutions({ | ||
86 | originServer: servers[0], | ||
87 | sqlCommand: sqlCommandServer1, | ||
88 | servers, | ||
89 | liveVideoId: video.uuid, | ||
90 | resolutions: [ 720, 480, 360, 240, 144 ], | ||
91 | objectStorage, | ||
92 | transcoded: true | ||
93 | }) | ||
94 | |||
95 | await stopFfmpeg(ffmpegCommand) | ||
96 | |||
97 | await waitUntilLiveWaitingOnAllServers(servers, video.uuid) | ||
98 | await waitJobs(servers) | ||
99 | |||
100 | const session = await servers[0].live.findLatestSession({ videoId: video.uuid }) | ||
101 | expect(session.endingProcessed).to.be.true | ||
102 | expect(session.endDate).to.exist | ||
103 | expect(session.saveReplay).to.be.true | ||
104 | |||
105 | const videoLiveDetails = await servers[0].videos.get({ id: video.uuid }) | ||
106 | const replay = await findExternalSavedVideo(servers[0], videoLiveDetails) | ||
107 | |||
108 | for (const server of servers) { | ||
109 | const video = await server.videos.get({ id: replay.uuid }) | ||
110 | |||
111 | expect(video.files).to.have.lengthOf(0) | ||
112 | expect(video.streamingPlaylists).to.have.lengthOf(1) | ||
113 | |||
114 | const files = video.streamingPlaylists[0].files | ||
115 | expect(files).to.have.lengthOf(5) | ||
116 | |||
117 | for (const file of files) { | ||
118 | if (objectStorage) { | ||
119 | expectStartWith(file.fileUrl, objectStorage.getMockPlaylistBaseUrl()) | ||
120 | } | ||
121 | |||
122 | await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 }) | ||
123 | } | ||
124 | } | ||
125 | }) | ||
126 | } | ||
127 | |||
128 | before(async function () { | ||
129 | this.timeout(120_000) | ||
130 | |||
131 | servers = await createMultipleServers(2) | ||
132 | |||
133 | await setAccessTokensToServers(servers) | ||
134 | await setDefaultVideoChannel(servers) | ||
135 | |||
136 | await doubleFollow(servers[0], servers[1]) | ||
137 | |||
138 | sqlCommandServer1 = new SQLCommand(servers[0]) | ||
139 | |||
140 | await servers[0].config.enableRemoteTranscoding() | ||
141 | await servers[0].config.enableTranscoding({ hls: true, webVideo: true, with0p: true }) | ||
142 | await servers[0].config.enableLive({ allowReplay: true, resolutions: 'max', transcoding: true }) | ||
143 | |||
144 | const registrationToken = await servers[0].runnerRegistrationTokens.getFirstRegistrationToken() | ||
145 | |||
146 | peertubeRunner = new PeerTubeRunnerProcess(servers[0]) | ||
147 | await peertubeRunner.runServer() | ||
148 | await peertubeRunner.registerPeerTubeInstance({ registrationToken, runnerName: 'runner' }) | ||
149 | }) | ||
150 | |||
151 | describe('With lives on local filesystem storage', function () { | ||
152 | |||
153 | before(async function () { | ||
154 | await servers[0].config.enableTranscoding({ webVideo: true, hls: false, with0p: true }) | ||
155 | }) | ||
156 | |||
157 | runSuite() | ||
158 | }) | ||
159 | |||
160 | describe('With lives on object storage', function () { | ||
161 | if (areMockObjectStorageTestsDisabled()) return | ||
162 | |||
163 | const objectStorage = new ObjectStorageCommand() | ||
164 | |||
165 | before(async function () { | ||
166 | await objectStorage.prepareDefaultMockBuckets() | ||
167 | |||
168 | await servers[0].kill() | ||
169 | |||
170 | await servers[0].run(objectStorage.getDefaultMockConfig()) | ||
171 | |||
172 | // Wait for peertube runner socket reconnection | ||
173 | await wait(1500) | ||
174 | }) | ||
175 | |||
176 | runSuite({ objectStorage }) | ||
177 | |||
178 | after(async function () { | ||
179 | await objectStorage.cleanupMock() | ||
180 | }) | ||
181 | }) | ||
182 | |||
183 | describe('Check cleanup', function () { | ||
184 | |||
185 | it('Should have an empty cache directory', async function () { | ||
186 | await checkPeerTubeRunnerCacheIsEmpty(peertubeRunner) | ||
187 | }) | ||
188 | }) | ||
189 | |||
190 | after(async function () { | ||
191 | if (peertubeRunner) { | ||
192 | await peertubeRunner.unregisterPeerTubeInstance({ runnerName: 'runner' }) | ||
193 | peertubeRunner.kill() | ||
194 | } | ||
195 | |||
196 | if (sqlCommandServer1) await sqlCommandServer1.cleanup() | ||
197 | |||
198 | await cleanupTests(servers) | ||
199 | }) | ||
200 | }) | ||