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