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