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