aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/transcoding/create-transcoding.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/transcoding/create-transcoding.ts')
-rw-r--r--server/tests/api/transcoding/create-transcoding.ts252
1 files changed, 252 insertions, 0 deletions
diff --git a/server/tests/api/transcoding/create-transcoding.ts b/server/tests/api/transcoding/create-transcoding.ts
new file mode 100644
index 000000000..a4defdf51
--- /dev/null
+++ b/server/tests/api/transcoding/create-transcoding.ts
@@ -0,0 +1,252 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
5import { checkResolutionsInMasterPlaylist, expectStartWith } from '@server/tests/shared'
6import { areObjectStorageTestsDisabled } from '@shared/core-utils'
7import { HttpStatusCode, VideoDetails } from '@shared/models'
8import {
9 cleanupTests,
10 ConfigCommand,
11 createMultipleServers,
12 doubleFollow,
13 expectNoFailedTranscodingJob,
14 makeRawRequest,
15 ObjectStorageCommand,
16 PeerTubeServer,
17 setAccessTokensToServers,
18 waitJobs
19} from '@shared/server-commands'
20
21const expect = chai.expect
22
23async function checkFilesInObjectStorage (video: VideoDetails) {
24 for (const file of video.files) {
25 expectStartWith(file.fileUrl, ObjectStorageCommand.getWebTorrentBaseUrl())
26 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
27 }
28
29 if (video.streamingPlaylists.length === 0) return
30
31 const hlsPlaylist = video.streamingPlaylists[0]
32 for (const file of hlsPlaylist.files) {
33 expectStartWith(file.fileUrl, ObjectStorageCommand.getPlaylistBaseUrl())
34 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
35 }
36
37 expectStartWith(hlsPlaylist.playlistUrl, ObjectStorageCommand.getPlaylistBaseUrl())
38 await makeRawRequest(hlsPlaylist.playlistUrl, HttpStatusCode.OK_200)
39
40 expectStartWith(hlsPlaylist.segmentsSha256Url, ObjectStorageCommand.getPlaylistBaseUrl())
41 await makeRawRequest(hlsPlaylist.segmentsSha256Url, HttpStatusCode.OK_200)
42}
43
44function runTests (objectStorage: boolean) {
45 let servers: PeerTubeServer[] = []
46 let videoUUID: string
47 let publishedAt: string
48
49 before(async function () {
50 this.timeout(120000)
51
52 const config = objectStorage
53 ? ObjectStorageCommand.getDefaultConfig()
54 : {}
55
56 // Run server 2 to have transcoding enabled
57 servers = await createMultipleServers(2, config)
58 await setAccessTokensToServers(servers)
59
60 await servers[0].config.disableTranscoding()
61
62 await doubleFollow(servers[0], servers[1])
63
64 if (objectStorage) await ObjectStorageCommand.prepareDefaultBuckets()
65
66 const { shortUUID } = await servers[0].videos.quickUpload({ name: 'video' })
67 videoUUID = shortUUID
68
69 await waitJobs(servers)
70
71 const video = await servers[0].videos.get({ id: videoUUID })
72 publishedAt = video.publishedAt as string
73
74 await servers[0].config.enableTranscoding()
75 })
76
77 it('Should generate HLS', async function () {
78 this.timeout(60000)
79
80 await servers[0].videos.runTranscoding({
81 videoId: videoUUID,
82 transcodingType: 'hls'
83 })
84
85 await waitJobs(servers)
86 await expectNoFailedTranscodingJob(servers[0])
87
88 for (const server of servers) {
89 const videoDetails = await server.videos.get({ id: videoUUID })
90
91 expect(videoDetails.files).to.have.lengthOf(1)
92 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
93 expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5)
94
95 if (objectStorage) await checkFilesInObjectStorage(videoDetails)
96 }
97 })
98
99 it('Should generate WebTorrent', async function () {
100 this.timeout(60000)
101
102 await servers[0].videos.runTranscoding({
103 videoId: videoUUID,
104 transcodingType: 'webtorrent'
105 })
106
107 await waitJobs(servers)
108
109 for (const server of servers) {
110 const videoDetails = await server.videos.get({ id: videoUUID })
111
112 expect(videoDetails.files).to.have.lengthOf(5)
113 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
114 expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5)
115
116 if (objectStorage) await checkFilesInObjectStorage(videoDetails)
117 }
118 })
119
120 it('Should generate WebTorrent from HLS only video', async function () {
121 this.timeout(60000)
122
123 await servers[0].videos.removeWebTorrentFiles({ videoId: videoUUID })
124 await waitJobs(servers)
125
126 await servers[0].videos.runTranscoding({ videoId: videoUUID, transcodingType: 'webtorrent' })
127 await waitJobs(servers)
128
129 for (const server of servers) {
130 const videoDetails = await server.videos.get({ id: videoUUID })
131
132 expect(videoDetails.files).to.have.lengthOf(5)
133 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
134 expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5)
135
136 if (objectStorage) await checkFilesInObjectStorage(videoDetails)
137 }
138 })
139
140 it('Should only generate WebTorrent', async function () {
141 this.timeout(60000)
142
143 await servers[0].videos.removeHLSFiles({ videoId: videoUUID })
144 await waitJobs(servers)
145
146 await servers[0].videos.runTranscoding({ videoId: videoUUID, transcodingType: 'webtorrent' })
147 await waitJobs(servers)
148
149 for (const server of servers) {
150 const videoDetails = await server.videos.get({ id: videoUUID })
151
152 expect(videoDetails.files).to.have.lengthOf(5)
153 expect(videoDetails.streamingPlaylists).to.have.lengthOf(0)
154
155 if (objectStorage) await checkFilesInObjectStorage(videoDetails)
156 }
157 })
158
159 it('Should correctly update HLS playlist on resolution change', async function () {
160 this.timeout(120000)
161
162 await servers[0].config.updateExistingSubConfig({
163 newConfig: {
164 transcoding: {
165 enabled: true,
166 resolutions: ConfigCommand.getCustomConfigResolutions(false),
167
168 webtorrent: {
169 enabled: true
170 },
171 hls: {
172 enabled: true
173 }
174 }
175 }
176 })
177
178 const { uuid } = await servers[0].videos.quickUpload({ name: 'quick' })
179
180 await waitJobs(servers)
181
182 for (const server of servers) {
183 const videoDetails = await server.videos.get({ id: uuid })
184
185 expect(videoDetails.files).to.have.lengthOf(1)
186 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
187 expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(1)
188
189 if (objectStorage) await checkFilesInObjectStorage(videoDetails)
190 }
191
192 await servers[0].config.updateExistingSubConfig({
193 newConfig: {
194 transcoding: {
195 enabled: true,
196 resolutions: ConfigCommand.getCustomConfigResolutions(true),
197
198 webtorrent: {
199 enabled: true
200 },
201 hls: {
202 enabled: true
203 }
204 }
205 }
206 })
207
208 await servers[0].videos.runTranscoding({ videoId: uuid, transcodingType: 'hls' })
209 await waitJobs(servers)
210
211 for (const server of servers) {
212 const videoDetails = await server.videos.get({ id: uuid })
213
214 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
215 expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5)
216
217 if (objectStorage) {
218 await checkFilesInObjectStorage(videoDetails)
219
220 const hlsPlaylist = videoDetails.streamingPlaylists[0]
221 const resolutions = hlsPlaylist.files.map(f => f.resolution.id)
222 await checkResolutionsInMasterPlaylist({ server: servers[0], playlistUrl: hlsPlaylist.playlistUrl, resolutions })
223
224 const shaBody = await servers[0].streamingPlaylists.getSegmentSha256({ url: hlsPlaylist.segmentsSha256Url })
225 expect(Object.keys(shaBody)).to.have.lengthOf(5)
226 }
227 }
228 })
229
230 it('Should not have updated published at attributes', async function () {
231 const video = await servers[0].videos.get({ id: videoUUID })
232
233 expect(video.publishedAt).to.equal(publishedAt)
234 })
235
236 after(async function () {
237 await cleanupTests(servers)
238 })
239}
240
241describe('Test create transcoding jobs from API', function () {
242
243 describe('On filesystem', function () {
244 runTests(false)
245 })
246
247 describe('On object storage', function () {
248 if (areObjectStorageTestsDisabled()) return
249
250 runTests(true)
251 })
252})