]>
Commit | Line | Data |
---|---|---|
ad5db104 C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
86347717 | 3 | import { expect } from 'chai' |
a2caee9f | 4 | import { checkResolutionsInMasterPlaylist, expectStartWith } from '@server/tests/shared' |
9ab330b9 | 5 | import { areMockObjectStorageTestsDisabled } from '@shared/core-utils' |
c55e3d72 | 6 | import { HttpStatusCode, VideoDetails } from '@shared/models' |
ad5db104 | 7 | import { |
ad5db104 | 8 | cleanupTests, |
a2caee9f | 9 | ConfigCommand, |
ad5db104 C |
10 | createMultipleServers, |
11 | doubleFollow, | |
842a1573 | 12 | expectNoFailedTranscodingJob, |
ad5db104 C |
13 | makeRawRequest, |
14 | ObjectStorageCommand, | |
15 | PeerTubeServer, | |
16 | setAccessTokensToServers, | |
17 | waitJobs | |
bf54587a | 18 | } from '@shared/server-commands' |
ad5db104 | 19 | |
ad5db104 C |
20 | async function checkFilesInObjectStorage (video: VideoDetails) { |
21 | for (const file of video.files) { | |
9ab330b9 | 22 | expectStartWith(file.fileUrl, ObjectStorageCommand.getMockWebTorrentBaseUrl()) |
3545e72c | 23 | await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 }) |
ad5db104 C |
24 | } |
25 | ||
a2caee9f | 26 | if (video.streamingPlaylists.length === 0) return |
0f11ec8d | 27 | |
a2caee9f C |
28 | const hlsPlaylist = video.streamingPlaylists[0] |
29 | for (const file of hlsPlaylist.files) { | |
9ab330b9 | 30 | expectStartWith(file.fileUrl, ObjectStorageCommand.getMockPlaylistBaseUrl()) |
3545e72c | 31 | await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 }) |
ad5db104 | 32 | } |
a2caee9f | 33 | |
9ab330b9 | 34 | expectStartWith(hlsPlaylist.playlistUrl, ObjectStorageCommand.getMockPlaylistBaseUrl()) |
3545e72c | 35 | await makeRawRequest({ url: hlsPlaylist.playlistUrl, expectedStatus: HttpStatusCode.OK_200 }) |
a2caee9f | 36 | |
9ab330b9 | 37 | expectStartWith(hlsPlaylist.segmentsSha256Url, ObjectStorageCommand.getMockPlaylistBaseUrl()) |
3545e72c | 38 | await makeRawRequest({ url: hlsPlaylist.segmentsSha256Url, expectedStatus: HttpStatusCode.OK_200 }) |
ad5db104 C |
39 | } |
40 | ||
ad5db104 C |
41 | function runTests (objectStorage: boolean) { |
42 | let servers: PeerTubeServer[] = [] | |
43 | let videoUUID: string | |
44 | let publishedAt: string | |
45 | ||
7b6b445d C |
46 | let shouldBeDeleted: string[] |
47 | ||
ad5db104 C |
48 | before(async function () { |
49 | this.timeout(120000) | |
50 | ||
51 | const config = objectStorage | |
9ab330b9 | 52 | ? ObjectStorageCommand.getDefaultMockConfig() |
ad5db104 C |
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 | ||
9ab330b9 | 63 | if (objectStorage) await ObjectStorageCommand.prepareDefaultMockBuckets() |
ad5db104 C |
64 | |
65 | const { shortUUID } = await servers[0].videos.quickUpload({ name: 'video' }) | |
66 | videoUUID = shortUUID | |
67 | ||
4842e518 C |
68 | await waitJobs(servers) |
69 | ||
ad5db104 C |
70 | const video = await servers[0].videos.get({ id: videoUUID }) |
71 | publishedAt = video.publishedAt as string | |
72 | ||
73 | await servers[0].config.enableTranscoding() | |
ad5db104 C |
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 | ||
1bb4c9ab | 122 | await servers[0].videos.removeAllWebTorrentFiles({ videoId: videoUUID }) |
ad5db104 C |
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 | ||
0f11ec8d C |
139 | it('Should only generate WebTorrent', async function () { |
140 | this.timeout(60000) | |
141 | ||
1bb4c9ab | 142 | await servers[0].videos.removeHLSPlaylist({ videoId: videoUUID }) |
0f11ec8d C |
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 | ||
a2caee9f | 158 | it('Should correctly update HLS playlist on resolution change', async function () { |
6e0ee5a5 C |
159 | this.timeout(120000) |
160 | ||
a2caee9f C |
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) | |
7b6b445d C |
189 | |
190 | shouldBeDeleted = [ | |
191 | videoDetails.streamingPlaylists[0].files[0].fileUrl, | |
192 | videoDetails.streamingPlaylists[0].playlistUrl, | |
193 | videoDetails.streamingPlaylists[0].segmentsSha256Url | |
194 | ] | |
a2caee9f C |
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 | ||
7b6b445d C |
235 | it('Should have correctly deleted previous files', async function () { |
236 | for (const fileUrl of shouldBeDeleted) { | |
3545e72c | 237 | await makeRawRequest({ url: fileUrl, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) |
7b6b445d C |
238 | } |
239 | }) | |
240 | ||
ad5db104 C |
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 () { | |
9ab330b9 | 259 | if (areMockObjectStorageTestsDisabled()) return |
ad5db104 C |
260 | |
261 | runTests(true) | |
262 | }) | |
263 | }) |