]>
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 | |
f8918990 | 20 | async function checkFilesInObjectStorage (objectStorage: ObjectStorageCommand, video: VideoDetails) { |
ad5db104 | 21 | for (const file of video.files) { |
f8918990 | 22 | expectStartWith(file.fileUrl, objectStorage.getMockWebVideosBaseUrl()) |
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) { | |
f8918990 | 30 | expectStartWith(file.fileUrl, objectStorage.getMockPlaylistBaseUrl()) |
3545e72c | 31 | await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 }) |
ad5db104 | 32 | } |
a2caee9f | 33 | |
f8918990 | 34 | expectStartWith(hlsPlaylist.playlistUrl, objectStorage.getMockPlaylistBaseUrl()) |
3545e72c | 35 | await makeRawRequest({ url: hlsPlaylist.playlistUrl, expectedStatus: HttpStatusCode.OK_200 }) |
a2caee9f | 36 | |
f8918990 | 37 | expectStartWith(hlsPlaylist.segmentsSha256Url, objectStorage.getMockPlaylistBaseUrl()) |
3545e72c | 38 | await makeRawRequest({ url: hlsPlaylist.segmentsSha256Url, expectedStatus: HttpStatusCode.OK_200 }) |
ad5db104 C |
39 | } |
40 | ||
f8918990 | 41 | function runTests (enableObjectStorage: boolean) { |
ad5db104 C |
42 | let servers: PeerTubeServer[] = [] |
43 | let videoUUID: string | |
44 | let publishedAt: string | |
45 | ||
7b6b445d | 46 | let shouldBeDeleted: string[] |
f8918990 | 47 | const objectStorage = new ObjectStorageCommand() |
7b6b445d | 48 | |
ad5db104 C |
49 | before(async function () { |
50 | this.timeout(120000) | |
51 | ||
f8918990 C |
52 | const config = enableObjectStorage |
53 | ? objectStorage.getDefaultMockConfig() | |
ad5db104 C |
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 | ||
f8918990 | 64 | if (enableObjectStorage) await objectStorage.prepareDefaultMockBuckets() |
ad5db104 C |
65 | |
66 | const { shortUUID } = await servers[0].videos.quickUpload({ name: 'video' }) | |
67 | videoUUID = shortUUID | |
68 | ||
4842e518 C |
69 | await waitJobs(servers) |
70 | ||
ad5db104 C |
71 | const video = await servers[0].videos.get({ id: videoUUID }) |
72 | publishedAt = video.publishedAt as string | |
73 | ||
74 | await servers[0].config.enableTranscoding() | |
ad5db104 C |
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 | ||
f8918990 | 95 | if (enableObjectStorage) await checkFilesInObjectStorage(objectStorage, videoDetails) |
ad5db104 C |
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 | ||
f8918990 | 116 | if (enableObjectStorage) await checkFilesInObjectStorage(objectStorage, videoDetails) |
ad5db104 C |
117 | } |
118 | }) | |
119 | ||
120 | it('Should generate WebTorrent from HLS only video', async function () { | |
121 | this.timeout(60000) | |
122 | ||
1bb4c9ab | 123 | await servers[0].videos.removeAllWebTorrentFiles({ videoId: videoUUID }) |
ad5db104 C |
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 | ||
f8918990 | 136 | if (enableObjectStorage) await checkFilesInObjectStorage(objectStorage, videoDetails) |
ad5db104 C |
137 | } |
138 | }) | |
139 | ||
0f11ec8d C |
140 | it('Should only generate WebTorrent', async function () { |
141 | this.timeout(60000) | |
142 | ||
1bb4c9ab | 143 | await servers[0].videos.removeHLSPlaylist({ videoId: videoUUID }) |
0f11ec8d C |
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 | ||
f8918990 | 155 | if (enableObjectStorage) await checkFilesInObjectStorage(objectStorage, videoDetails) |
0f11ec8d C |
156 | } |
157 | }) | |
158 | ||
a2caee9f | 159 | it('Should correctly update HLS playlist on resolution change', async function () { |
6e0ee5a5 C |
160 | this.timeout(120000) |
161 | ||
a2caee9f C |
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 | ||
f8918990 | 189 | if (enableObjectStorage) await checkFilesInObjectStorage(objectStorage, videoDetails) |
7b6b445d C |
190 | |
191 | shouldBeDeleted = [ | |
192 | videoDetails.streamingPlaylists[0].files[0].fileUrl, | |
193 | videoDetails.streamingPlaylists[0].playlistUrl, | |
194 | videoDetails.streamingPlaylists[0].segmentsSha256Url | |
195 | ] | |
a2caee9f C |
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 | ||
f8918990 C |
223 | if (enableObjectStorage) { |
224 | await checkFilesInObjectStorage(objectStorage, videoDetails) | |
a2caee9f C |
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 | ||
5170f492 | 230 | const shaBody = await servers[0].streamingPlaylists.getSegmentSha256({ url: hlsPlaylist.segmentsSha256Url, withRetry: true }) |
a2caee9f C |
231 | expect(Object.keys(shaBody)).to.have.lengthOf(5) |
232 | } | |
233 | } | |
234 | }) | |
235 | ||
7b6b445d C |
236 | it('Should have correctly deleted previous files', async function () { |
237 | for (const fileUrl of shouldBeDeleted) { | |
3545e72c | 238 | await makeRawRequest({ url: fileUrl, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) |
7b6b445d C |
239 | } |
240 | }) | |
241 | ||
ad5db104 C |
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 () { | |
f8918990 C |
249 | if (objectStorage) await objectStorage.cleanupMock() |
250 | ||
ad5db104 C |
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 () { | |
9ab330b9 | 262 | if (areMockObjectStorageTestsDisabled()) return |
ad5db104 C |
263 | |
264 | runTests(true) | |
265 | }) | |
266 | }) |