diff options
Diffstat (limited to 'server/tests/api/videos/video-create-transcoding.ts')
-rw-r--r-- | server/tests/api/videos/video-create-transcoding.ts | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/server/tests/api/videos/video-create-transcoding.ts b/server/tests/api/videos/video-create-transcoding.ts new file mode 100644 index 000000000..bae06ac6c --- /dev/null +++ b/server/tests/api/videos/video-create-transcoding.ts | |||
@@ -0,0 +1,156 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import * as chai from 'chai' | ||
5 | import { | ||
6 | areObjectStorageTestsDisabled, | ||
7 | cleanupTests, | ||
8 | createMultipleServers, | ||
9 | doubleFollow, | ||
10 | expectStartWith, | ||
11 | makeRawRequest, | ||
12 | ObjectStorageCommand, | ||
13 | PeerTubeServer, | ||
14 | setAccessTokensToServers, | ||
15 | waitJobs | ||
16 | } from '@shared/extra-utils' | ||
17 | import { HttpStatusCode, VideoDetails } from '@shared/models' | ||
18 | |||
19 | const expect = chai.expect | ||
20 | |||
21 | async function checkFilesInObjectStorage (video: VideoDetails) { | ||
22 | for (const file of video.files) { | ||
23 | expectStartWith(file.fileUrl, ObjectStorageCommand.getWebTorrentBaseUrl()) | ||
24 | await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200) | ||
25 | } | ||
26 | |||
27 | for (const file of video.streamingPlaylists[0].files) { | ||
28 | expectStartWith(file.fileUrl, ObjectStorageCommand.getPlaylistBaseUrl()) | ||
29 | await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200) | ||
30 | } | ||
31 | } | ||
32 | |||
33 | async function expectNoFailedTranscodingJob (server: PeerTubeServer) { | ||
34 | const { data } = await server.jobs.listFailed({ jobType: 'video-transcoding' }) | ||
35 | expect(data).to.have.lengthOf(0) | ||
36 | } | ||
37 | |||
38 | function runTests (objectStorage: boolean) { | ||
39 | let servers: PeerTubeServer[] = [] | ||
40 | let videoUUID: string | ||
41 | let publishedAt: string | ||
42 | |||
43 | before(async function () { | ||
44 | this.timeout(120000) | ||
45 | |||
46 | const config = objectStorage | ||
47 | ? ObjectStorageCommand.getDefaultConfig() | ||
48 | : {} | ||
49 | |||
50 | // Run server 2 to have transcoding enabled | ||
51 | servers = await createMultipleServers(2, config) | ||
52 | await setAccessTokensToServers(servers) | ||
53 | |||
54 | await servers[0].config.disableTranscoding() | ||
55 | |||
56 | await doubleFollow(servers[0], servers[1]) | ||
57 | |||
58 | if (objectStorage) await ObjectStorageCommand.prepareDefaultBuckets() | ||
59 | |||
60 | const { shortUUID } = await servers[0].videos.quickUpload({ name: 'video' }) | ||
61 | videoUUID = shortUUID | ||
62 | |||
63 | const video = await servers[0].videos.get({ id: videoUUID }) | ||
64 | publishedAt = video.publishedAt as string | ||
65 | |||
66 | await servers[0].config.enableTranscoding() | ||
67 | |||
68 | await waitJobs(servers) | ||
69 | }) | ||
70 | |||
71 | it('Should generate HLS', async function () { | ||
72 | this.timeout(60000) | ||
73 | |||
74 | await servers[0].videos.runTranscoding({ | ||
75 | videoId: videoUUID, | ||
76 | transcodingType: 'hls' | ||
77 | }) | ||
78 | |||
79 | await waitJobs(servers) | ||
80 | await expectNoFailedTranscodingJob(servers[0]) | ||
81 | |||
82 | for (const server of servers) { | ||
83 | const videoDetails = await server.videos.get({ id: videoUUID }) | ||
84 | |||
85 | expect(videoDetails.files).to.have.lengthOf(1) | ||
86 | expect(videoDetails.streamingPlaylists).to.have.lengthOf(1) | ||
87 | expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5) | ||
88 | |||
89 | if (objectStorage) await checkFilesInObjectStorage(videoDetails) | ||
90 | } | ||
91 | }) | ||
92 | |||
93 | it('Should generate WebTorrent', async function () { | ||
94 | this.timeout(60000) | ||
95 | |||
96 | await servers[0].videos.runTranscoding({ | ||
97 | videoId: videoUUID, | ||
98 | transcodingType: 'webtorrent' | ||
99 | }) | ||
100 | |||
101 | await waitJobs(servers) | ||
102 | |||
103 | for (const server of servers) { | ||
104 | const videoDetails = await server.videos.get({ id: videoUUID }) | ||
105 | |||
106 | expect(videoDetails.files).to.have.lengthOf(5) | ||
107 | expect(videoDetails.streamingPlaylists).to.have.lengthOf(1) | ||
108 | expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5) | ||
109 | |||
110 | if (objectStorage) await checkFilesInObjectStorage(videoDetails) | ||
111 | } | ||
112 | }) | ||
113 | |||
114 | it('Should generate WebTorrent from HLS only video', async function () { | ||
115 | this.timeout(60000) | ||
116 | |||
117 | await servers[0].videos.removeWebTorrentFiles({ videoId: videoUUID }) | ||
118 | await waitJobs(servers) | ||
119 | |||
120 | await servers[0].videos.runTranscoding({ videoId: videoUUID, transcodingType: 'webtorrent' }) | ||
121 | await waitJobs(servers) | ||
122 | |||
123 | for (const server of servers) { | ||
124 | const videoDetails = await server.videos.get({ id: videoUUID }) | ||
125 | |||
126 | expect(videoDetails.files).to.have.lengthOf(5) | ||
127 | expect(videoDetails.streamingPlaylists).to.have.lengthOf(1) | ||
128 | expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5) | ||
129 | |||
130 | if (objectStorage) await checkFilesInObjectStorage(videoDetails) | ||
131 | } | ||
132 | }) | ||
133 | |||
134 | it('Should not have updated published at attributes', async function () { | ||
135 | const video = await servers[0].videos.get({ id: videoUUID }) | ||
136 | |||
137 | expect(video.publishedAt).to.equal(publishedAt) | ||
138 | }) | ||
139 | |||
140 | after(async function () { | ||
141 | await cleanupTests(servers) | ||
142 | }) | ||
143 | } | ||
144 | |||
145 | describe('Test create transcoding jobs from API', function () { | ||
146 | |||
147 | describe('On filesystem', function () { | ||
148 | runTests(false) | ||
149 | }) | ||
150 | |||
151 | describe('On object storage', function () { | ||
152 | if (areObjectStorageTestsDisabled()) return | ||
153 | |||
154 | runTests(true) | ||
155 | }) | ||
156 | }) | ||