diff options
Diffstat (limited to 'server/tests/peertube-runner/vod-transcoding.ts')
-rw-r--r-- | server/tests/peertube-runner/vod-transcoding.ts | 330 |
1 files changed, 330 insertions, 0 deletions
diff --git a/server/tests/peertube-runner/vod-transcoding.ts b/server/tests/peertube-runner/vod-transcoding.ts new file mode 100644 index 000000000..bdf798379 --- /dev/null +++ b/server/tests/peertube-runner/vod-transcoding.ts | |||
@@ -0,0 +1,330 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | import { expect } from 'chai' | ||
3 | import { completeCheckHlsPlaylist, completeWebVideoFilesCheck, PeerTubeRunnerProcess } from '@server/tests/shared' | ||
4 | import { areMockObjectStorageTestsDisabled, getAllFiles, wait } from '@shared/core-utils' | ||
5 | import { VideoPrivacy } from '@shared/models' | ||
6 | import { | ||
7 | cleanupTests, | ||
8 | createMultipleServers, | ||
9 | doubleFollow, | ||
10 | ObjectStorageCommand, | ||
11 | PeerTubeServer, | ||
12 | setAccessTokensToServers, | ||
13 | setDefaultVideoChannel, | ||
14 | waitJobs | ||
15 | } from '@shared/server-commands' | ||
16 | |||
17 | describe('Test VOD transcoding in peertube-runner program', function () { | ||
18 | let servers: PeerTubeServer[] = [] | ||
19 | let peertubeRunner: PeerTubeRunnerProcess | ||
20 | |||
21 | function runSuite (options: { | ||
22 | webtorrentEnabled: boolean | ||
23 | hlsEnabled: boolean | ||
24 | objectStorage: boolean | ||
25 | }) { | ||
26 | const { webtorrentEnabled, hlsEnabled, objectStorage } = options | ||
27 | |||
28 | const objectStorageBaseUrlWebTorrent = objectStorage | ||
29 | ? ObjectStorageCommand.getMockWebTorrentBaseUrl() | ||
30 | : undefined | ||
31 | |||
32 | const objectStorageBaseUrlHLS = objectStorage | ||
33 | ? ObjectStorageCommand.getMockPlaylistBaseUrl() | ||
34 | : undefined | ||
35 | |||
36 | it('Should upload a classic video mp4 and transcode it', async function () { | ||
37 | this.timeout(120000) | ||
38 | |||
39 | const { uuid } = await servers[0].videos.quickUpload({ name: 'mp4', fixture: 'video_short.mp4' }) | ||
40 | |||
41 | await waitJobs(servers, { runnerJobs: true }) | ||
42 | |||
43 | for (const server of servers) { | ||
44 | if (webtorrentEnabled) { | ||
45 | await completeWebVideoFilesCheck({ | ||
46 | server, | ||
47 | originServer: servers[0], | ||
48 | fixture: 'video_short.mp4', | ||
49 | videoUUID: uuid, | ||
50 | objectStorageBaseUrl: objectStorageBaseUrlWebTorrent, | ||
51 | files: [ | ||
52 | { resolution: 0 }, | ||
53 | { resolution: 144 }, | ||
54 | { resolution: 240 }, | ||
55 | { resolution: 360 }, | ||
56 | { resolution: 480 }, | ||
57 | { resolution: 720 } | ||
58 | ] | ||
59 | }) | ||
60 | } | ||
61 | |||
62 | if (hlsEnabled) { | ||
63 | await completeCheckHlsPlaylist({ | ||
64 | hlsOnly: !webtorrentEnabled, | ||
65 | servers, | ||
66 | videoUUID: uuid, | ||
67 | objectStorageBaseUrl: objectStorageBaseUrlHLS, | ||
68 | resolutions: [ 720, 480, 360, 240, 144, 0 ] | ||
69 | }) | ||
70 | } | ||
71 | } | ||
72 | }) | ||
73 | |||
74 | it('Should upload a webm video and transcode it', async function () { | ||
75 | this.timeout(120000) | ||
76 | |||
77 | const { uuid } = await servers[0].videos.quickUpload({ name: 'mp4', fixture: 'video_short.webm' }) | ||
78 | |||
79 | await waitJobs(servers, { runnerJobs: true }) | ||
80 | |||
81 | for (const server of servers) { | ||
82 | if (webtorrentEnabled) { | ||
83 | await completeWebVideoFilesCheck({ | ||
84 | server, | ||
85 | originServer: servers[0], | ||
86 | fixture: 'video_short.webm', | ||
87 | videoUUID: uuid, | ||
88 | objectStorageBaseUrl: objectStorageBaseUrlWebTorrent, | ||
89 | files: [ | ||
90 | { resolution: 0 }, | ||
91 | { resolution: 144 }, | ||
92 | { resolution: 240 }, | ||
93 | { resolution: 360 }, | ||
94 | { resolution: 480 }, | ||
95 | { resolution: 720 } | ||
96 | ] | ||
97 | }) | ||
98 | } | ||
99 | |||
100 | if (hlsEnabled) { | ||
101 | await completeCheckHlsPlaylist({ | ||
102 | hlsOnly: !webtorrentEnabled, | ||
103 | servers, | ||
104 | videoUUID: uuid, | ||
105 | objectStorageBaseUrl: objectStorageBaseUrlHLS, | ||
106 | resolutions: [ 720, 480, 360, 240, 144, 0 ] | ||
107 | }) | ||
108 | } | ||
109 | } | ||
110 | }) | ||
111 | |||
112 | it('Should upload an audio only video and transcode it', async function () { | ||
113 | this.timeout(120000) | ||
114 | |||
115 | const attributes = { name: 'audio_without_preview', fixture: 'sample.ogg' } | ||
116 | const { uuid } = await servers[0].videos.upload({ attributes, mode: 'resumable' }) | ||
117 | |||
118 | await waitJobs(servers, { runnerJobs: true }) | ||
119 | |||
120 | for (const server of servers) { | ||
121 | if (webtorrentEnabled) { | ||
122 | await completeWebVideoFilesCheck({ | ||
123 | server, | ||
124 | originServer: servers[0], | ||
125 | fixture: 'sample.ogg', | ||
126 | videoUUID: uuid, | ||
127 | objectStorageBaseUrl: objectStorageBaseUrlWebTorrent, | ||
128 | files: [ | ||
129 | { resolution: 0 }, | ||
130 | { resolution: 144 }, | ||
131 | { resolution: 240 }, | ||
132 | { resolution: 360 }, | ||
133 | { resolution: 480 } | ||
134 | ] | ||
135 | }) | ||
136 | } | ||
137 | |||
138 | if (hlsEnabled) { | ||
139 | await completeCheckHlsPlaylist({ | ||
140 | hlsOnly: !webtorrentEnabled, | ||
141 | servers, | ||
142 | videoUUID: uuid, | ||
143 | objectStorageBaseUrl: objectStorageBaseUrlHLS, | ||
144 | resolutions: [ 480, 360, 240, 144, 0 ] | ||
145 | }) | ||
146 | } | ||
147 | } | ||
148 | }) | ||
149 | |||
150 | it('Should upload a private video and transcode it', async function () { | ||
151 | this.timeout(120000) | ||
152 | |||
153 | const { uuid } = await servers[0].videos.quickUpload({ name: 'mp4', fixture: 'video_short.mp4', privacy: VideoPrivacy.PRIVATE }) | ||
154 | |||
155 | await waitJobs(servers, { runnerJobs: true }) | ||
156 | |||
157 | if (webtorrentEnabled) { | ||
158 | await completeWebVideoFilesCheck({ | ||
159 | server: servers[0], | ||
160 | originServer: servers[0], | ||
161 | fixture: 'video_short.mp4', | ||
162 | videoUUID: uuid, | ||
163 | objectStorageBaseUrl: objectStorageBaseUrlWebTorrent, | ||
164 | files: [ | ||
165 | { resolution: 0 }, | ||
166 | { resolution: 144 }, | ||
167 | { resolution: 240 }, | ||
168 | { resolution: 360 }, | ||
169 | { resolution: 480 }, | ||
170 | { resolution: 720 } | ||
171 | ] | ||
172 | }) | ||
173 | } | ||
174 | |||
175 | if (hlsEnabled) { | ||
176 | await completeCheckHlsPlaylist({ | ||
177 | hlsOnly: !webtorrentEnabled, | ||
178 | servers: [ servers[0] ], | ||
179 | videoUUID: uuid, | ||
180 | objectStorageBaseUrl: objectStorageBaseUrlHLS, | ||
181 | resolutions: [ 720, 480, 360, 240, 144, 0 ] | ||
182 | }) | ||
183 | } | ||
184 | }) | ||
185 | |||
186 | it('Should transcode videos on manual run', async function () { | ||
187 | this.timeout(120000) | ||
188 | |||
189 | await servers[0].config.disableTranscoding() | ||
190 | |||
191 | const { uuid } = await servers[0].videos.quickUpload({ name: 'manual transcoding', fixture: 'video_short.mp4' }) | ||
192 | await waitJobs(servers, { runnerJobs: true }) | ||
193 | |||
194 | { | ||
195 | const video = await servers[0].videos.get({ id: uuid }) | ||
196 | expect(getAllFiles(video)).to.have.lengthOf(1) | ||
197 | } | ||
198 | |||
199 | await servers[0].config.enableTranscoding(true, true, true) | ||
200 | |||
201 | await servers[0].videos.runTranscoding({ transcodingType: 'webtorrent', videoId: uuid }) | ||
202 | await waitJobs(servers, { runnerJobs: true }) | ||
203 | |||
204 | await completeWebVideoFilesCheck({ | ||
205 | server: servers[0], | ||
206 | originServer: servers[0], | ||
207 | fixture: 'video_short.mp4', | ||
208 | videoUUID: uuid, | ||
209 | objectStorageBaseUrl: objectStorageBaseUrlWebTorrent, | ||
210 | files: [ | ||
211 | { resolution: 0 }, | ||
212 | { resolution: 144 }, | ||
213 | { resolution: 240 }, | ||
214 | { resolution: 360 }, | ||
215 | { resolution: 480 }, | ||
216 | { resolution: 720 } | ||
217 | ] | ||
218 | }) | ||
219 | |||
220 | await servers[0].videos.runTranscoding({ transcodingType: 'hls', videoId: uuid }) | ||
221 | await waitJobs(servers, { runnerJobs: true }) | ||
222 | |||
223 | await completeCheckHlsPlaylist({ | ||
224 | hlsOnly: false, | ||
225 | servers: [ servers[0] ], | ||
226 | videoUUID: uuid, | ||
227 | objectStorageBaseUrl: objectStorageBaseUrlHLS, | ||
228 | resolutions: [ 720, 480, 360, 240, 144, 0 ] | ||
229 | }) | ||
230 | }) | ||
231 | } | ||
232 | |||
233 | before(async function () { | ||
234 | this.timeout(120_000) | ||
235 | |||
236 | servers = await createMultipleServers(2) | ||
237 | |||
238 | await setAccessTokensToServers(servers) | ||
239 | await setDefaultVideoChannel(servers) | ||
240 | |||
241 | await doubleFollow(servers[0], servers[1]) | ||
242 | |||
243 | await servers[0].config.enableRemoteTranscoding() | ||
244 | |||
245 | const registrationToken = await servers[0].runnerRegistrationTokens.getFirstRegistrationToken() | ||
246 | |||
247 | peertubeRunner = new PeerTubeRunnerProcess() | ||
248 | await peertubeRunner.runServer() | ||
249 | await peertubeRunner.registerPeerTubeInstance({ server: servers[0], registrationToken, runnerName: 'runner' }) | ||
250 | }) | ||
251 | |||
252 | describe('With videos on local filesystem storage', function () { | ||
253 | |||
254 | describe('Web video only enabled', function () { | ||
255 | |||
256 | before(async function () { | ||
257 | await servers[0].config.enableTranscoding(true, false, true) | ||
258 | }) | ||
259 | |||
260 | runSuite({ webtorrentEnabled: true, hlsEnabled: false, objectStorage: false }) | ||
261 | }) | ||
262 | |||
263 | describe('HLS videos only enabled', function () { | ||
264 | |||
265 | before(async function () { | ||
266 | await servers[0].config.enableTranscoding(false, true, true) | ||
267 | }) | ||
268 | |||
269 | runSuite({ webtorrentEnabled: false, hlsEnabled: true, objectStorage: false }) | ||
270 | }) | ||
271 | |||
272 | describe('Web video & HLS enabled', function () { | ||
273 | |||
274 | before(async function () { | ||
275 | await servers[0].config.enableTranscoding(true, true, true) | ||
276 | }) | ||
277 | |||
278 | runSuite({ webtorrentEnabled: true, hlsEnabled: true, objectStorage: false }) | ||
279 | }) | ||
280 | }) | ||
281 | |||
282 | describe('With videos on object storage', function () { | ||
283 | if (areMockObjectStorageTestsDisabled()) return | ||
284 | |||
285 | before(async function () { | ||
286 | await ObjectStorageCommand.prepareDefaultMockBuckets() | ||
287 | |||
288 | await servers[0].kill() | ||
289 | |||
290 | await servers[0].run(ObjectStorageCommand.getDefaultMockConfig()) | ||
291 | |||
292 | // Wait for peertube runner socket reconnection | ||
293 | await wait(1500) | ||
294 | }) | ||
295 | |||
296 | describe('Web video only enabled', function () { | ||
297 | |||
298 | before(async function () { | ||
299 | await servers[0].config.enableTranscoding(true, false, true) | ||
300 | }) | ||
301 | |||
302 | runSuite({ webtorrentEnabled: true, hlsEnabled: false, objectStorage: true }) | ||
303 | }) | ||
304 | |||
305 | describe('HLS videos only enabled', function () { | ||
306 | |||
307 | before(async function () { | ||
308 | await servers[0].config.enableTranscoding(false, true, true) | ||
309 | }) | ||
310 | |||
311 | runSuite({ webtorrentEnabled: false, hlsEnabled: true, objectStorage: true }) | ||
312 | }) | ||
313 | |||
314 | describe('Web video & HLS enabled', function () { | ||
315 | |||
316 | before(async function () { | ||
317 | await servers[0].config.enableTranscoding(true, true, true) | ||
318 | }) | ||
319 | |||
320 | runSuite({ webtorrentEnabled: true, hlsEnabled: true, objectStorage: true }) | ||
321 | }) | ||
322 | }) | ||
323 | |||
324 | after(async function () { | ||
325 | await peertubeRunner.unregisterPeerTubeInstance({ server: servers[0] }) | ||
326 | peertubeRunner.kill() | ||
327 | |||
328 | await cleanupTests(servers) | ||
329 | }) | ||
330 | }) | ||