diff options
author | Chocobozzz <me@florianbigard.com> | 2023-04-21 15:00:01 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2023-05-09 08:57:34 +0200 |
commit | d102de1b38f2877463529c3b27bd35ffef4fd8bf (patch) | |
tree | 31fa0bdf26ad7a2ee46d600d804a6f03260266c8 /server/tests/cli | |
parent | 2fe978744e5b74eb824e4d79c1bb9b840169f125 (diff) | |
download | PeerTube-d102de1b38f2877463529c3b27bd35ffef4fd8bf.tar.gz PeerTube-d102de1b38f2877463529c3b27bd35ffef4fd8bf.tar.zst PeerTube-d102de1b38f2877463529c3b27bd35ffef4fd8bf.zip |
Add runner server tests
Diffstat (limited to 'server/tests/cli')
-rw-r--r-- | server/tests/cli/create-transcoding-job.ts | 262 | ||||
-rw-r--r-- | server/tests/cli/index.ts | 2 | ||||
-rw-r--r-- | server/tests/cli/print-transcode-command.ts | 31 | ||||
-rw-r--r-- | server/tests/cli/update-host.ts | 2 |
4 files changed, 1 insertions, 296 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 | |||
3 | import { expect } from 'chai' | ||
4 | import { areMockObjectStorageTestsDisabled } from '@shared/core-utils' | ||
5 | import { HttpStatusCode, VideoFile } from '@shared/models' | ||
6 | import { | ||
7 | cleanupTests, | ||
8 | createMultipleServers, | ||
9 | doubleFollow, | ||
10 | makeRawRequest, | ||
11 | ObjectStorageCommand, | ||
12 | PeerTubeServer, | ||
13 | setAccessTokensToServers, | ||
14 | waitJobs | ||
15 | } from '@shared/server-commands' | ||
16 | import { checkResolutionsInMasterPlaylist, expectStartWith } from '../shared' | ||
17 | |||
18 | async 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 | |||
30 | function 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 | |||
251 | describe('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 | }) | ||
diff --git a/server/tests/cli/index.ts b/server/tests/cli/index.ts index 6e0cbe58b..8579be39c 100644 --- a/server/tests/cli/index.ts +++ b/server/tests/cli/index.ts | |||
@@ -1,10 +1,8 @@ | |||
1 | // Order of the tests we want to execute | 1 | // Order of the tests we want to execute |
2 | import './create-import-video-file-job' | 2 | import './create-import-video-file-job' |
3 | import './create-transcoding-job' | ||
4 | import './create-move-video-storage-job' | 3 | import './create-move-video-storage-job' |
5 | import './peertube' | 4 | import './peertube' |
6 | import './plugins' | 5 | import './plugins' |
7 | import './print-transcode-command' | ||
8 | import './prune-storage' | 6 | import './prune-storage' |
9 | import './regenerate-thumbnails' | 7 | import './regenerate-thumbnails' |
10 | import './reset-password' | 8 | import './reset-password' |
diff --git a/server/tests/cli/print-transcode-command.ts b/server/tests/cli/print-transcode-command.ts deleted file mode 100644 index 33b6cd27c..000000000 --- a/server/tests/cli/print-transcode-command.ts +++ /dev/null | |||
@@ -1,31 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { buildAbsoluteFixturePath } from '@shared/core-utils' | ||
5 | import { CLICommand } from '@shared/server-commands' | ||
6 | import { VideoResolution } from '../../../shared/models/videos' | ||
7 | |||
8 | describe('Test print transcode jobs', function () { | ||
9 | |||
10 | it('Should print the correct command for each resolution', async function () { | ||
11 | const fixturePath = buildAbsoluteFixturePath('video_short.webm') | ||
12 | |||
13 | for (const resolution of [ | ||
14 | VideoResolution.H_720P, | ||
15 | VideoResolution.H_1080P | ||
16 | ]) { | ||
17 | const command = await CLICommand.exec(`npm run print-transcode-command -- ${fixturePath} -r ${resolution}`) | ||
18 | |||
19 | expect(command).to.includes(`-vf scale=w=-2:h=${resolution}`) | ||
20 | expect(command).to.includes(`-y -acodec aac -vcodec libx264`) | ||
21 | expect(command).to.includes('-f mp4') | ||
22 | expect(command).to.includes('-movflags faststart') | ||
23 | expect(command).to.includes('-b:a 256k') | ||
24 | expect(command).to.includes('-r 25') | ||
25 | expect(command).to.includes('-level:v 3.1') | ||
26 | expect(command).to.includes('-g:v 50') | ||
27 | expect(command).to.includes(`-maxrate:v `) | ||
28 | expect(command).to.includes(`-bufsize:v `) | ||
29 | } | ||
30 | }) | ||
31 | }) | ||
diff --git a/server/tests/cli/update-host.ts b/server/tests/cli/update-host.ts index 51257d3d3..386c384e6 100644 --- a/server/tests/cli/update-host.ts +++ b/server/tests/cli/update-host.ts | |||
@@ -7,11 +7,11 @@ import { | |||
7 | createSingleServer, | 7 | createSingleServer, |
8 | killallServers, | 8 | killallServers, |
9 | makeActivityPubGetRequest, | 9 | makeActivityPubGetRequest, |
10 | parseTorrentVideo, | ||
11 | PeerTubeServer, | 10 | PeerTubeServer, |
12 | setAccessTokensToServers, | 11 | setAccessTokensToServers, |
13 | waitJobs | 12 | waitJobs |
14 | } from '@shared/server-commands' | 13 | } from '@shared/server-commands' |
14 | import { parseTorrentVideo } from '../shared' | ||
15 | 15 | ||
16 | describe('Test update host scripts', function () { | 16 | describe('Test update host scripts', function () { |
17 | let server: PeerTubeServer | 17 | let server: PeerTubeServer |