]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
0c948c16 C |
2 | |
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
0c948c16 | 5 | import { |
7c3b7976 | 6 | cleanupTests, |
3cd0734f | 7 | doubleFollow, |
3cd0734f | 8 | flushAndRunMultipleServers, |
3cd0734f | 9 | getVideo, |
0c948c16 | 10 | getVideosList, |
0c948c16 | 11 | ServerInfo, |
a1587156 C |
12 | setAccessTokensToServers, |
13 | updateCustomSubConfig, | |
14 | uploadVideo | |
94565d52 C |
15 | } from '../../../shared/extra-utils' |
16 | import { waitJobs } from '../../../shared/extra-utils/server/jobs' | |
329619b3 | 17 | import { VideoDetails } from '../../../shared/models/videos' |
3cd0734f C |
18 | |
19 | const expect = chai.expect | |
0c948c16 C |
20 | |
21 | describe('Test create transcoding jobs', function () { | |
22 | let servers: ServerInfo[] = [] | |
a1587156 | 23 | const videosUUID: string[] = [] |
dee6fe1e C |
24 | |
25 | const config = { | |
26 | transcoding: { | |
27 | enabled: false, | |
28 | resolutions: { | |
29 | '240p': true, | |
30 | '360p': true, | |
31 | '480p': true, | |
32 | '720p': true, | |
33 | '1080p': true, | |
b7085c71 | 34 | '1440p': true, |
dee6fe1e C |
35 | '2160p': true |
36 | }, | |
37 | hls: { | |
38 | enabled: false | |
39 | } | |
40 | } | |
41 | } | |
0c948c16 C |
42 | |
43 | before(async function () { | |
44 | this.timeout(60000) | |
45 | ||
0c948c16 C |
46 | // Run server 2 to have transcoding enabled |
47 | servers = await flushAndRunMultipleServers(2) | |
48 | await setAccessTokensToServers(servers) | |
49 | ||
dee6fe1e C |
50 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) |
51 | ||
0c948c16 C |
52 | await doubleFollow(servers[0], servers[1]) |
53 | ||
dee6fe1e | 54 | for (let i = 1; i <= 5; i++) { |
a1587156 | 55 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' + i }) |
dee6fe1e C |
56 | videosUUID.push(res.body.video.uuid) |
57 | } | |
0c948c16 | 58 | |
3cd0734f | 59 | await waitJobs(servers) |
0c948c16 C |
60 | }) |
61 | ||
62 | it('Should have two video files on each server', async function () { | |
63 | this.timeout(30000) | |
64 | ||
65 | for (const server of servers) { | |
66 | const res = await getVideosList(server.url) | |
67 | const videos = res.body.data | |
dee6fe1e | 68 | expect(videos).to.have.lengthOf(videosUUID.length) |
0c948c16 C |
69 | |
70 | for (const video of videos) { | |
71 | const res2 = await getVideo(server.url, video.uuid) | |
72 | const videoDetail: VideoDetails = res2.body | |
73 | expect(videoDetail.files).to.have.lengthOf(1) | |
dee6fe1e | 74 | expect(videoDetail.streamingPlaylists).to.have.lengthOf(0) |
0c948c16 C |
75 | } |
76 | } | |
77 | }) | |
78 | ||
79 | it('Should run a transcoding job on video 2', async function () { | |
80 | this.timeout(60000) | |
81 | ||
329619b3 | 82 | await servers[0].cliCommand.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[1]}`) |
3cd0734f | 83 | await waitJobs(servers) |
0c948c16 C |
84 | |
85 | for (const server of servers) { | |
86 | const res = await getVideosList(server.url) | |
87 | const videos = res.body.data | |
0c948c16 | 88 | |
a1587156 | 89 | let infoHashes: { [id: number]: string } |
04bf312c | 90 | |
0c948c16 C |
91 | for (const video of videos) { |
92 | const res2 = await getVideo(server.url, video.uuid) | |
93 | const videoDetail: VideoDetails = res2.body | |
94 | ||
dee6fe1e | 95 | if (video.uuid === videosUUID[1]) { |
0c948c16 | 96 | expect(videoDetail.files).to.have.lengthOf(4) |
dee6fe1e | 97 | expect(videoDetail.streamingPlaylists).to.have.lengthOf(0) |
04bf312c C |
98 | |
99 | if (!infoHashes) { | |
100 | infoHashes = {} | |
101 | ||
102 | for (const file of videoDetail.files) { | |
103 | infoHashes[file.resolution.id.toString()] = file.magnetUri | |
104 | } | |
105 | } else { | |
106 | for (const resolution of Object.keys(infoHashes)) { | |
107 | const file = videoDetail.files.find(f => f.resolution.id.toString() === resolution) | |
108 | expect(file.magnetUri).to.equal(infoHashes[resolution]) | |
109 | } | |
110 | } | |
0c948c16 C |
111 | } else { |
112 | expect(videoDetail.files).to.have.lengthOf(1) | |
dee6fe1e | 113 | expect(videoDetail.streamingPlaylists).to.have.lengthOf(0) |
0c948c16 C |
114 | } |
115 | } | |
116 | } | |
117 | }) | |
118 | ||
05623b90 F |
119 | it('Should run a transcoding job on video 1 with resolution', async function () { |
120 | this.timeout(60000) | |
121 | ||
329619b3 | 122 | await servers[0].cliCommand.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[0]} -r 480`) |
05623b90 F |
123 | |
124 | await waitJobs(servers) | |
125 | ||
126 | for (const server of servers) { | |
127 | const res = await getVideosList(server.url) | |
128 | const videos = res.body.data | |
dee6fe1e | 129 | expect(videos).to.have.lengthOf(videosUUID.length) |
05623b90 | 130 | |
dee6fe1e | 131 | const res2 = await getVideo(server.url, videosUUID[0]) |
05623b90 F |
132 | const videoDetail: VideoDetails = res2.body |
133 | ||
134 | expect(videoDetail.files).to.have.lengthOf(2) | |
05623b90 | 135 | expect(videoDetail.files[0].resolution.id).to.equal(720) |
05623b90 | 136 | expect(videoDetail.files[1].resolution.id).to.equal(480) |
dee6fe1e C |
137 | |
138 | expect(videoDetail.streamingPlaylists).to.have.lengthOf(0) | |
139 | } | |
140 | }) | |
141 | ||
142 | it('Should generate an HLS resolution', async function () { | |
143 | this.timeout(120000) | |
144 | ||
329619b3 | 145 | await servers[0].cliCommand.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[2]} --generate-hls -r 480`) |
dee6fe1e C |
146 | |
147 | await waitJobs(servers) | |
148 | ||
149 | for (const server of servers) { | |
150 | const res = await getVideo(server.url, videosUUID[2]) | |
151 | const videoDetail: VideoDetails = res.body | |
152 | ||
153 | expect(videoDetail.files).to.have.lengthOf(1) | |
154 | expect(videoDetail.streamingPlaylists).to.have.lengthOf(1) | |
155 | ||
156 | const files = videoDetail.streamingPlaylists[0].files | |
157 | expect(files).to.have.lengthOf(1) | |
158 | expect(files[0].resolution.id).to.equal(480) | |
159 | } | |
160 | }) | |
161 | ||
162 | it('Should not duplicate an HLS resolution', async function () { | |
163 | this.timeout(120000) | |
164 | ||
329619b3 | 165 | await servers[0].cliCommand.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[2]} --generate-hls -r 480`) |
dee6fe1e C |
166 | |
167 | await waitJobs(servers) | |
168 | ||
169 | for (const server of servers) { | |
170 | const res = await getVideo(server.url, videosUUID[2]) | |
171 | const videoDetail: VideoDetails = res.body | |
172 | ||
173 | const files = videoDetail.streamingPlaylists[0].files | |
174 | expect(files).to.have.lengthOf(1) | |
175 | expect(files[0].resolution.id).to.equal(480) | |
176 | } | |
177 | }) | |
178 | ||
179 | it('Should generate all HLS resolutions', async function () { | |
180 | this.timeout(120000) | |
181 | ||
329619b3 | 182 | await servers[0].cliCommand.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[3]} --generate-hls`) |
dee6fe1e C |
183 | |
184 | await waitJobs(servers) | |
185 | ||
186 | for (const server of servers) { | |
187 | const res = await getVideo(server.url, videosUUID[3]) | |
188 | const videoDetail: VideoDetails = res.body | |
189 | ||
190 | expect(videoDetail.files).to.have.lengthOf(1) | |
191 | expect(videoDetail.streamingPlaylists).to.have.lengthOf(1) | |
192 | ||
193 | const files = videoDetail.streamingPlaylists[0].files | |
194 | expect(files).to.have.lengthOf(4) | |
195 | } | |
196 | }) | |
197 | ||
198 | it('Should optimize the video file and generate HLS videos if enabled in config', async function () { | |
199 | this.timeout(120000) | |
200 | ||
201 | config.transcoding.hls.enabled = true | |
202 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) | |
203 | ||
329619b3 | 204 | await servers[0].cliCommand.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[4]}`) |
dee6fe1e C |
205 | |
206 | await waitJobs(servers) | |
207 | ||
208 | for (const server of servers) { | |
209 | const res = await getVideo(server.url, videosUUID[4]) | |
210 | const videoDetail: VideoDetails = res.body | |
211 | ||
212 | expect(videoDetail.files).to.have.lengthOf(4) | |
213 | expect(videoDetail.streamingPlaylists).to.have.lengthOf(1) | |
214 | expect(videoDetail.streamingPlaylists[0].files).to.have.lengthOf(4) | |
05623b90 F |
215 | } |
216 | }) | |
217 | ||
7c3b7976 C |
218 | after(async function () { |
219 | await cleanupTests(servers) | |
0c948c16 C |
220 | }) |
221 | }) |