]>
Commit | Line | Data |
---|---|---|
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 (objectStorage: ObjectStorageCommand, video: VideoDetails) { | |
21 | for (const file of video.files) { | |
22 | expectStartWith(file.fileUrl, objectStorage.getMockWebVideosBaseUrl()) | |
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, objectStorage.getMockPlaylistBaseUrl()) | |
31 | await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 }) | |
32 | } | |
33 | ||
34 | expectStartWith(hlsPlaylist.playlistUrl, objectStorage.getMockPlaylistBaseUrl()) | |
35 | await makeRawRequest({ url: hlsPlaylist.playlistUrl, expectedStatus: HttpStatusCode.OK_200 }) | |
36 | ||
37 | expectStartWith(hlsPlaylist.segmentsSha256Url, objectStorage.getMockPlaylistBaseUrl()) | |
38 | await makeRawRequest({ url: hlsPlaylist.segmentsSha256Url, expectedStatus: HttpStatusCode.OK_200 }) | |
39 | } | |
40 | ||
41 | function runTests (enableObjectStorage: boolean) { | |
42 | let servers: PeerTubeServer[] = [] | |
43 | let videoUUID: string | |
44 | let publishedAt: string | |
45 | ||
46 | let shouldBeDeleted: string[] | |
47 | const objectStorage = new ObjectStorageCommand() | |
48 | ||
49 | before(async function () { | |
50 | this.timeout(120000) | |
51 | ||
52 | const config = enableObjectStorage | |
53 | ? objectStorage.getDefaultMockConfig() | |
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 (enableObjectStorage) await objectStorage.prepareDefaultMockBuckets() | |
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 (enableObjectStorage) await checkFilesInObjectStorage(objectStorage, 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 (enableObjectStorage) await checkFilesInObjectStorage(objectStorage, 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.removeAllWebTorrentFiles({ 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 (enableObjectStorage) await checkFilesInObjectStorage(objectStorage, videoDetails) | |
137 | } | |
138 | }) | |
139 | ||
140 | it('Should only generate WebTorrent', async function () { | |
141 | this.timeout(60000) | |
142 | ||
143 | await servers[0].videos.removeHLSPlaylist({ 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 (enableObjectStorage) await checkFilesInObjectStorage(objectStorage, 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 (enableObjectStorage) await checkFilesInObjectStorage(objectStorage, videoDetails) | |
190 | ||
191 | shouldBeDeleted = [ | |
192 | videoDetails.streamingPlaylists[0].files[0].fileUrl, | |
193 | videoDetails.streamingPlaylists[0].playlistUrl, | |
194 | videoDetails.streamingPlaylists[0].segmentsSha256Url | |
195 | ] | |
196 | } | |
197 | ||
198 | await servers[0].config.updateExistingSubConfig({ | |
199 | newConfig: { | |
200 | transcoding: { | |
201 | enabled: true, | |
202 | resolutions: ConfigCommand.getCustomConfigResolutions(true), | |
203 | ||
204 | webtorrent: { | |
205 | enabled: true | |
206 | }, | |
207 | hls: { | |
208 | enabled: true | |
209 | } | |
210 | } | |
211 | } | |
212 | }) | |
213 | ||
214 | await servers[0].videos.runTranscoding({ videoId: uuid, transcodingType: 'hls' }) | |
215 | await waitJobs(servers) | |
216 | ||
217 | for (const server of servers) { | |
218 | const videoDetails = await server.videos.get({ id: uuid }) | |
219 | ||
220 | expect(videoDetails.streamingPlaylists).to.have.lengthOf(1) | |
221 | expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5) | |
222 | ||
223 | if (enableObjectStorage) { | |
224 | await checkFilesInObjectStorage(objectStorage, videoDetails) | |
225 | ||
226 | const hlsPlaylist = videoDetails.streamingPlaylists[0] | |
227 | const resolutions = hlsPlaylist.files.map(f => f.resolution.id) | |
228 | await checkResolutionsInMasterPlaylist({ server: servers[0], playlistUrl: hlsPlaylist.playlistUrl, resolutions }) | |
229 | ||
230 | const shaBody = await servers[0].streamingPlaylists.getSegmentSha256({ url: hlsPlaylist.segmentsSha256Url, withRetry: true }) | |
231 | expect(Object.keys(shaBody)).to.have.lengthOf(5) | |
232 | } | |
233 | } | |
234 | }) | |
235 | ||
236 | it('Should have correctly deleted previous files', async function () { | |
237 | for (const fileUrl of shouldBeDeleted) { | |
238 | await makeRawRequest({ url: fileUrl, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) | |
239 | } | |
240 | }) | |
241 | ||
242 | it('Should not have updated published at attributes', async function () { | |
243 | const video = await servers[0].videos.get({ id: videoUUID }) | |
244 | ||
245 | expect(video.publishedAt).to.equal(publishedAt) | |
246 | }) | |
247 | ||
248 | after(async function () { | |
249 | if (objectStorage) await objectStorage.cleanupMock() | |
250 | ||
251 | await cleanupTests(servers) | |
252 | }) | |
253 | } | |
254 | ||
255 | describe('Test create transcoding jobs from API', function () { | |
256 | ||
257 | describe('On filesystem', function () { | |
258 | runTests(false) | |
259 | }) | |
260 | ||
261 | describe('On object storage', function () { | |
262 | if (areMockObjectStorageTestsDisabled()) return | |
263 | ||
264 | runTests(true) | |
265 | }) | |
266 | }) |