]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/transcoding/hls.ts
Stop testing broken youtube-dl
[github/Chocobozzz/PeerTube.git] / server / tests / api / transcoding / hls.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
09209296 2
3545e72c
C
3import { join } from 'path'
4import { checkDirectoryIsEmpty, checkTmpIsEmpty, completeCheckHlsPlaylist } from '@server/tests/shared'
9ab330b9 5import { areMockObjectStorageTestsDisabled } from '@shared/core-utils'
3545e72c 6import { HttpStatusCode } from '@shared/models'
c55e3d72 7import {
7243f84d 8 cleanupTests,
254d3579 9 createMultipleServers,
4c7e60bc 10 doubleFollow,
0305db28 11 ObjectStorageCommand,
254d3579 12 PeerTubeServer,
a1587156 13 setAccessTokensToServers,
3545e72c 14 waitJobs
bf54587a 15} from '@shared/server-commands'
b345a804 16import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants'
09209296 17
09209296 18describe('Test HLS videos', function () {
254d3579 19 let servers: PeerTubeServer[] = []
09209296 20
0305db28 21 function runTestSuite (hlsOnly: boolean, objectStorageBaseUrl?: string) {
3545e72c 22 const videoUUIDs: string[] = []
dd0ebb71 23
d7a25329
C
24 it('Should upload a video and transcode it to HLS', async function () {
25 this.timeout(120000)
09209296 26
89d241a7 27 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video 1', fixture: 'video_short.webm' } })
3545e72c 28 videoUUIDs.push(uuid)
09209296 29
d7a25329 30 await waitJobs(servers)
09209296 31
3545e72c 32 await completeCheckHlsPlaylist({ servers, videoUUID: uuid, hlsOnly, objectStorageBaseUrl })
d7a25329 33 })
09209296 34
d7a25329
C
35 it('Should upload an audio file and transcode it to HLS', async function () {
36 this.timeout(120000)
09209296 37
89d241a7 38 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video audio', fixture: 'sample.ogg' } })
3545e72c 39 videoUUIDs.push(uuid)
09209296 40
d7a25329 41 await waitJobs(servers)
09209296 42
3545e72c 43 await completeCheckHlsPlaylist({
0305db28 44 servers,
3545e72c 45 videoUUID: uuid,
0305db28
JB
46 hlsOnly,
47 resolutions: [ DEFAULT_AUDIO_RESOLUTION, 360, 240 ],
48 objectStorageBaseUrl
49 })
d7a25329 50 })
09209296 51
d7a25329 52 it('Should update the video', async function () {
cbb1d46b 53 this.timeout(30000)
b345a804 54
3545e72c 55 await servers[0].videos.update({ id: videoUUIDs[0], attributes: { name: 'video 1 updated' } })
b345a804 56
d7a25329 57 await waitJobs(servers)
b345a804 58
3545e72c 59 await completeCheckHlsPlaylist({ servers, videoUUID: videoUUIDs[0], hlsOnly, objectStorageBaseUrl })
d7a25329 60 })
b345a804 61
d7a25329
C
62 it('Should delete videos', async function () {
63 this.timeout(10000)
80b8ad2a 64
3545e72c
C
65 for (const uuid of videoUUIDs) {
66 await servers[0].videos.remove({ id: uuid })
67 }
09209296 68
d7a25329 69 await waitJobs(servers)
09209296 70
d7a25329 71 for (const server of servers) {
3545e72c
C
72 for (const uuid of videoUUIDs) {
73 await server.videos.get({ id: uuid, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
74 }
d7a25329
C
75 }
76 })
09209296 77
d7a25329
C
78 it('Should have the playlists/segment deleted from the disk', async function () {
79 for (const server of servers) {
3545e72c
C
80 await checkDirectoryIsEmpty(server, 'videos', [ 'private' ])
81 await checkDirectoryIsEmpty(server, join('videos', 'private'))
82
83 await checkDirectoryIsEmpty(server, join('streaming-playlists', 'hls'), [ 'private' ])
84 await checkDirectoryIsEmpty(server, join('streaming-playlists', 'hls', 'private'))
d7a25329
C
85 }
86 })
80b8ad2a 87
d7a25329
C
88 it('Should have an empty tmp directory', async function () {
89 for (const server of servers) {
90 await checkTmpIsEmpty(server)
91 }
92 })
93 }
09209296 94
d7a25329
C
95 before(async function () {
96 this.timeout(120000)
09209296 97
d7a25329
C
98 const configOverride = {
99 transcoding: {
100 enabled: true,
101 allow_audio_files: true,
102 hls: {
103 enabled: true
104 }
105 }
09209296 106 }
254d3579 107 servers = await createMultipleServers(2, configOverride)
d7a25329
C
108
109 // Get the access tokens
110 await setAccessTokensToServers(servers)
111
112 // Server 1 and server 2 follow each other
113 await doubleFollow(servers[0], servers[1])
09209296
C
114 })
115
d7a25329
C
116 describe('With WebTorrent & HLS enabled', function () {
117 runTestSuite(false)
09209296
C
118 })
119
d7a25329
C
120 describe('With only HLS enabled', function () {
121
122 before(async function () {
89d241a7 123 await servers[0].config.updateCustomSubConfig({
65e6e260
C
124 newConfig: {
125 transcoding: {
126 enabled: true,
127 allowAudioFiles: true,
128 resolutions: {
8dd754c7 129 '144p': false,
65e6e260
C
130 '240p': true,
131 '360p': true,
132 '480p': true,
133 '720p': true,
134 '1080p': true,
135 '1440p': true,
136 '2160p': true
137 },
138 hls: {
139 enabled: true
140 },
141 webtorrent: {
142 enabled: false
143 }
d7a25329
C
144 }
145 }
146 })
147 })
148
149 runTestSuite(true)
09209296
C
150 })
151
0305db28 152 describe('With object storage enabled', function () {
9ab330b9 153 if (areMockObjectStorageTestsDisabled()) return
0305db28
JB
154
155 before(async function () {
156 this.timeout(120000)
157
9ab330b9
C
158 const configOverride = ObjectStorageCommand.getDefaultMockConfig()
159 await ObjectStorageCommand.prepareDefaultMockBuckets()
0305db28
JB
160
161 await servers[0].kill()
162 await servers[0].run(configOverride)
163 })
164
9ab330b9 165 runTestSuite(true, ObjectStorageCommand.getMockPlaylistBaseUrl())
0305db28
JB
166 })
167
7c3b7976
C
168 after(async function () {
169 await cleanupTests(servers)
09209296
C
170 })
171})