aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/cli/create-transcoding-job.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-04-21 15:00:01 +0200
committerChocobozzz <chocobozzz@cpy.re>2023-05-09 08:57:34 +0200
commitd102de1b38f2877463529c3b27bd35ffef4fd8bf (patch)
tree31fa0bdf26ad7a2ee46d600d804a6f03260266c8 /server/tests/cli/create-transcoding-job.ts
parent2fe978744e5b74eb824e4d79c1bb9b840169f125 (diff)
downloadPeerTube-d102de1b38f2877463529c3b27bd35ffef4fd8bf.tar.gz
PeerTube-d102de1b38f2877463529c3b27bd35ffef4fd8bf.tar.zst
PeerTube-d102de1b38f2877463529c3b27bd35ffef4fd8bf.zip
Add runner server tests
Diffstat (limited to 'server/tests/cli/create-transcoding-job.ts')
-rw-r--r--server/tests/cli/create-transcoding-job.ts262
1 files changed, 0 insertions, 262 deletions
diff --git a/server/tests/cli/create-transcoding-job.ts b/server/tests/cli/create-transcoding-job.ts
deleted file mode 100644
index 38b737829..000000000
--- a/server/tests/cli/create-transcoding-job.ts
+++ /dev/null
@@ -1,262 +0,0 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { expect } from 'chai'
4import { areMockObjectStorageTestsDisabled } from '@shared/core-utils'
5import { HttpStatusCode, VideoFile } from '@shared/models'
6import {
7 cleanupTests,
8 createMultipleServers,
9 doubleFollow,
10 makeRawRequest,
11 ObjectStorageCommand,
12 PeerTubeServer,
13 setAccessTokensToServers,
14 waitJobs
15} from '@shared/server-commands'
16import { checkResolutionsInMasterPlaylist, expectStartWith } from '../shared'
17
18async function checkFilesInObjectStorage (files: VideoFile[], type: 'webtorrent' | 'playlist') {
19 for (const file of files) {
20 const shouldStartWith = type === 'webtorrent'
21 ? ObjectStorageCommand.getMockWebTorrentBaseUrl()
22 : ObjectStorageCommand.getMockPlaylistBaseUrl()
23
24 expectStartWith(file.fileUrl, shouldStartWith)
25
26 await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
27 }
28}
29
30function runTests (objectStorage: boolean) {
31 let servers: PeerTubeServer[] = []
32 const videosUUID: string[] = []
33 const publishedAt: string[] = []
34
35 before(async function () {
36 this.timeout(120000)
37
38 const config = objectStorage
39 ? ObjectStorageCommand.getDefaultMockConfig()
40 : {}
41
42 // Run server 2 to have transcoding enabled
43 servers = await createMultipleServers(2, config)
44 await setAccessTokensToServers(servers)
45
46 await servers[0].config.disableTranscoding()
47
48 await doubleFollow(servers[0], servers[1])
49
50 if (objectStorage) await ObjectStorageCommand.prepareDefaultMockBuckets()
51
52 for (let i = 1; i <= 5; i++) {
53 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'video' + i } })
54
55 await waitJobs(servers)
56
57 const video = await servers[0].videos.get({ id: uuid })
58 publishedAt.push(video.publishedAt as string)
59
60 if (i > 2) {
61 videosUUID.push(uuid)
62 } else {
63 videosUUID.push(shortUUID)
64 }
65 }
66
67 await waitJobs(servers)
68 })
69
70 it('Should have two video files on each server', async function () {
71 this.timeout(30000)
72
73 for (const server of servers) {
74 const { data } = await server.videos.list()
75 expect(data).to.have.lengthOf(videosUUID.length)
76
77 for (const video of data) {
78 const videoDetail = await server.videos.get({ id: video.uuid })
79 expect(videoDetail.files).to.have.lengthOf(1)
80 expect(videoDetail.streamingPlaylists).to.have.lengthOf(0)
81 }
82 }
83 })
84
85 it('Should run a transcoding job on video 2', async function () {
86 this.timeout(60000)
87
88 await servers[0].cli.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[1]}`)
89 await waitJobs(servers)
90
91 for (const server of servers) {
92 const { data } = await server.videos.list()
93
94 let infoHashes: { [id: number]: string }
95
96 for (const video of data) {
97 const videoDetails = await server.videos.get({ id: video.uuid })
98
99 if (video.shortUUID === videosUUID[1] || video.uuid === videosUUID[1]) {
100 expect(videoDetails.files).to.have.lengthOf(4)
101 expect(videoDetails.streamingPlaylists).to.have.lengthOf(0)
102
103 if (objectStorage) await checkFilesInObjectStorage(videoDetails.files, 'webtorrent')
104
105 if (!infoHashes) {
106 infoHashes = {}
107
108 for (const file of videoDetails.files) {
109 infoHashes[file.resolution.id.toString()] = file.magnetUri
110 }
111 } else {
112 for (const resolution of Object.keys(infoHashes)) {
113 const file = videoDetails.files.find(f => f.resolution.id.toString() === resolution)
114 expect(file.magnetUri).to.equal(infoHashes[resolution])
115 }
116 }
117 } else {
118 expect(videoDetails.files).to.have.lengthOf(1)
119 expect(videoDetails.streamingPlaylists).to.have.lengthOf(0)
120 }
121 }
122 }
123 })
124
125 it('Should run a transcoding job on video 1 with resolution', async function () {
126 this.timeout(60000)
127
128 await servers[0].cli.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[0]} -r 480`)
129
130 await waitJobs(servers)
131
132 for (const server of servers) {
133 const { data } = await server.videos.list()
134 expect(data).to.have.lengthOf(videosUUID.length)
135
136 const videoDetails = await server.videos.get({ id: videosUUID[0] })
137
138 expect(videoDetails.files).to.have.lengthOf(2)
139 expect(videoDetails.files[0].resolution.id).to.equal(720)
140 expect(videoDetails.files[1].resolution.id).to.equal(480)
141
142 expect(videoDetails.streamingPlaylists).to.have.lengthOf(0)
143
144 if (objectStorage) await checkFilesInObjectStorage(videoDetails.files, 'webtorrent')
145 }
146 })
147
148 it('Should generate an HLS resolution', async function () {
149 this.timeout(120000)
150
151 await servers[0].cli.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[2]} --generate-hls -r 480`)
152
153 await waitJobs(servers)
154
155 for (const server of servers) {
156 const videoDetails = await server.videos.get({ id: videosUUID[2] })
157
158 expect(videoDetails.files).to.have.lengthOf(1)
159 if (objectStorage) await checkFilesInObjectStorage(videoDetails.files, 'webtorrent')
160
161 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
162
163 const hlsPlaylist = videoDetails.streamingPlaylists[0]
164
165 const files = hlsPlaylist.files
166 expect(files).to.have.lengthOf(1)
167 expect(files[0].resolution.id).to.equal(480)
168
169 if (objectStorage) {
170 await checkFilesInObjectStorage(files, 'playlist')
171
172 const resolutions = files.map(f => f.resolution.id)
173 await checkResolutionsInMasterPlaylist({ server, playlistUrl: hlsPlaylist.playlistUrl, resolutions })
174 }
175 }
176 })
177
178 it('Should not duplicate an HLS resolution', async function () {
179 this.timeout(120000)
180
181 await servers[0].cli.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[2]} --generate-hls -r 480`)
182
183 await waitJobs(servers)
184
185 for (const server of servers) {
186 const videoDetails = await server.videos.get({ id: videosUUID[2] })
187
188 const files = videoDetails.streamingPlaylists[0].files
189 expect(files).to.have.lengthOf(1)
190 expect(files[0].resolution.id).to.equal(480)
191
192 if (objectStorage) await checkFilesInObjectStorage(files, 'playlist')
193 }
194 })
195
196 it('Should generate all HLS resolutions', async function () {
197 this.timeout(120000)
198
199 await servers[0].cli.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[3]} --generate-hls`)
200
201 await waitJobs(servers)
202
203 for (const server of servers) {
204 const videoDetails = await server.videos.get({ id: videosUUID[3] })
205
206 expect(videoDetails.files).to.have.lengthOf(1)
207 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
208
209 const files = videoDetails.streamingPlaylists[0].files
210 expect(files).to.have.lengthOf(4)
211
212 if (objectStorage) await checkFilesInObjectStorage(files, 'playlist')
213 }
214 })
215
216 it('Should optimize the video file and generate HLS videos if enabled in config', async function () {
217 this.timeout(120000)
218
219 await servers[0].config.enableTranscoding()
220 await servers[0].cli.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[4]}`)
221
222 await waitJobs(servers)
223
224 for (const server of servers) {
225 const videoDetails = await server.videos.get({ id: videosUUID[4] })
226
227 expect(videoDetails.files).to.have.lengthOf(5)
228 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
229 expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5)
230
231 if (objectStorage) {
232 await checkFilesInObjectStorage(videoDetails.files, 'webtorrent')
233 await checkFilesInObjectStorage(videoDetails.streamingPlaylists[0].files, 'playlist')
234 }
235 }
236 })
237
238 it('Should not have updated published at attributes', async function () {
239 for (const id of videosUUID) {
240 const video = await servers[0].videos.get({ id })
241
242 expect(publishedAt.some(p => video.publishedAt === p)).to.be.true
243 }
244 })
245
246 after(async function () {
247 await cleanupTests(servers)
248 })
249}
250
251describe('Test create transcoding jobs', function () {
252
253 describe('On filesystem', function () {
254 runTests(false)
255 })
256
257 describe('On object storage', function () {
258 if (areMockObjectStorageTestsDisabled()) return
259
260 runTests(true)
261 })
262})