aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/videos/video-create-transcoding.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-11-18 14:35:08 +0100
committerChocobozzz <me@florianbigard.com>2021-11-18 15:20:57 +0100
commitad5db1044c8599eaaaa2a578b350777ae996b068 (patch)
tree3e003cccf021152405d49b21c6c91b703c8ae96c /server/tests/api/videos/video-create-transcoding.ts
parentb46cf4b920984492df598c1b61179acfc7f6f22e (diff)
downloadPeerTube-ad5db1044c8599eaaaa2a578b350777ae996b068.tar.gz
PeerTube-ad5db1044c8599eaaaa2a578b350777ae996b068.tar.zst
PeerTube-ad5db1044c8599eaaaa2a578b350777ae996b068.zip
Add ability to run transcoding jobs
Diffstat (limited to 'server/tests/api/videos/video-create-transcoding.ts')
-rw-r--r--server/tests/api/videos/video-create-transcoding.ts156
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
3import 'mocha'
4import * as chai from 'chai'
5import {
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'
17import { HttpStatusCode, VideoDetails } from '@shared/models'
18
19const expect = chai.expect
20
21async 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
33async function expectNoFailedTranscodingJob (server: PeerTubeServer) {
34 const { data } = await server.jobs.listFailed({ jobType: 'video-transcoding' })
35 expect(data).to.have.lengthOf(0)
36}
37
38function 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
145describe('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})