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