]>
Commit | Line | Data |
---|---|---|
09209296 C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
5 | import { | |
6 | checkDirectoryIsEmpty, | |
4c280004 | 7 | checkSegmentHash, |
7243f84d C |
8 | checkTmpIsEmpty, |
9 | cleanupTests, | |
09209296 C |
10 | doubleFollow, |
11 | flushAndRunMultipleServers, | |
09209296 | 12 | getPlaylist, |
d7a25329 | 13 | getVideo, makeGetRequest, makeRawRequest, |
09209296 C |
14 | removeVideo, |
15 | ServerInfo, | |
d7a25329 | 16 | setAccessTokensToServers, updateCustomSubConfig, |
09209296 C |
17 | updateVideo, |
18 | uploadVideo, | |
d7a25329 | 19 | waitJobs, webtorrentAdd |
94565d52 | 20 | } from '../../../../shared/extra-utils' |
09209296 C |
21 | import { VideoDetails } from '../../../../shared/models/videos' |
22 | import { VideoStreamingPlaylistType } from '../../../../shared/models/videos/video-streaming-playlist.type' | |
09209296 | 23 | import { join } from 'path' |
b345a804 | 24 | import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants' |
09209296 C |
25 | |
26 | const expect = chai.expect | |
27 | ||
d7a25329 | 28 | async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, hlsOnly: boolean, resolutions = [ 240, 360, 480, 720 ]) { |
09209296 | 29 | for (const server of servers) { |
d7a25329 C |
30 | const resVideoDetails = await getVideo(server.url, videoUUID) |
31 | const videoDetails: VideoDetails = resVideoDetails.body | |
32 | const baseUrl = `http://${videoDetails.account.host}` | |
09209296 C |
33 | |
34 | expect(videoDetails.streamingPlaylists).to.have.lengthOf(1) | |
35 | ||
36 | const hlsPlaylist = videoDetails.streamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS) | |
37 | expect(hlsPlaylist).to.not.be.undefined | |
38 | ||
d7a25329 C |
39 | const hlsFiles = hlsPlaylist.files |
40 | expect(hlsFiles).to.have.lengthOf(resolutions.length) | |
41 | ||
42 | if (hlsOnly) expect(videoDetails.files).to.have.lengthOf(0) | |
43 | else expect(videoDetails.files).to.have.lengthOf(resolutions.length) | |
44 | ||
45 | for (const resolution of resolutions) { | |
46 | const file = hlsFiles.find(f => f.resolution.id === resolution) | |
47 | expect(file).to.not.be.undefined | |
48 | ||
49 | expect(file.magnetUri).to.have.lengthOf.above(2) | |
50 | expect(file.torrentUrl).to.equal(`${baseUrl}/static/torrents/${videoDetails.uuid}-${file.resolution.id}-hls.torrent`) | |
51 | expect(file.fileUrl).to.equal(`${baseUrl}/static/streaming-playlists/hls/${videoDetails.uuid}/${videoDetails.uuid}-${file.resolution.id}-fragmented.mp4`) | |
52 | expect(file.resolution.label).to.equal(resolution + 'p') | |
53 | ||
54 | await makeRawRequest(file.torrentUrl, 200) | |
55 | await makeRawRequest(file.fileUrl, 200) | |
56 | ||
57 | const torrent = await webtorrentAdd(file.magnetUri, true) | |
58 | expect(torrent.files).to.be.an('array') | |
59 | expect(torrent.files.length).to.equal(1) | |
60 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
61 | } | |
62 | ||
09209296 | 63 | { |
d7a25329 | 64 | const res = await getPlaylist(hlsPlaylist.playlistUrl) |
09209296 | 65 | |
d7a25329 | 66 | const masterPlaylist = res.text |
09209296 | 67 | |
09209296 | 68 | for (const resolution of resolutions) { |
b345a804 | 69 | expect(masterPlaylist).to.match(new RegExp('#EXT-X-STREAM-INF:BANDWIDTH=\\d+,RESOLUTION=\\d+x' + resolution + ',FRAME-RATE=\\d+')) |
09209296 C |
70 | expect(masterPlaylist).to.contain(`${resolution}.m3u8`) |
71 | } | |
72 | } | |
73 | ||
74 | { | |
75 | for (const resolution of resolutions) { | |
d7a25329 | 76 | const res = await getPlaylist(`${baseUrl}/static/streaming-playlists/hls/${videoUUID}/${resolution}.m3u8`) |
09209296 | 77 | |
d7a25329 | 78 | const subPlaylist = res.text |
4c280004 | 79 | expect(subPlaylist).to.contain(`${videoUUID}-${resolution}-fragmented.mp4`) |
09209296 C |
80 | } |
81 | } | |
82 | ||
83 | { | |
d7a25329 | 84 | const baseUrlAndPath = baseUrl + '/static/streaming-playlists/hls' |
09209296 | 85 | |
4c280004 | 86 | for (const resolution of resolutions) { |
d7a25329 | 87 | await checkSegmentHash(baseUrlAndPath, baseUrlAndPath, videoUUID, resolution, hlsPlaylist) |
09209296 C |
88 | } |
89 | } | |
90 | } | |
91 | } | |
92 | ||
93 | describe('Test HLS videos', function () { | |
94 | let servers: ServerInfo[] = [] | |
95 | let videoUUID = '' | |
b345a804 | 96 | let videoAudioUUID = '' |
09209296 | 97 | |
d7a25329 C |
98 | function runTestSuite (hlsOnly: boolean) { |
99 | it('Should upload a video and transcode it to HLS', async function () { | |
100 | this.timeout(120000) | |
09209296 | 101 | |
d7a25329 C |
102 | const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'video 1', fixture: 'video_short.webm' }) |
103 | videoUUID = res.body.video.uuid | |
09209296 | 104 | |
d7a25329 | 105 | await waitJobs(servers) |
09209296 | 106 | |
d7a25329 C |
107 | await checkHlsPlaylist(servers, videoUUID, hlsOnly) |
108 | }) | |
09209296 | 109 | |
d7a25329 C |
110 | it('Should upload an audio file and transcode it to HLS', async function () { |
111 | this.timeout(120000) | |
09209296 | 112 | |
d7a25329 C |
113 | const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'video audio', fixture: 'sample.ogg' }) |
114 | videoAudioUUID = res.body.video.uuid | |
09209296 | 115 | |
d7a25329 | 116 | await waitJobs(servers) |
09209296 | 117 | |
d7a25329 C |
118 | await checkHlsPlaylist(servers, videoAudioUUID, hlsOnly, [ DEFAULT_AUDIO_RESOLUTION ]) |
119 | }) | |
09209296 | 120 | |
d7a25329 C |
121 | it('Should update the video', async function () { |
122 | this.timeout(10000) | |
b345a804 | 123 | |
d7a25329 | 124 | await updateVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID, { name: 'video 1 updated' }) |
b345a804 | 125 | |
d7a25329 | 126 | await waitJobs(servers) |
b345a804 | 127 | |
d7a25329 C |
128 | await checkHlsPlaylist(servers, videoUUID, hlsOnly) |
129 | }) | |
b345a804 | 130 | |
d7a25329 C |
131 | it('Should delete videos', async function () { |
132 | this.timeout(10000) | |
80b8ad2a | 133 | |
d7a25329 C |
134 | await removeVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID) |
135 | await removeVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAudioUUID) | |
09209296 | 136 | |
d7a25329 | 137 | await waitJobs(servers) |
09209296 | 138 | |
d7a25329 C |
139 | for (const server of servers) { |
140 | await getVideo(server.url, videoUUID, 404) | |
141 | await getVideo(server.url, videoAudioUUID, 404) | |
142 | } | |
143 | }) | |
09209296 | 144 | |
d7a25329 C |
145 | it('Should have the playlists/segment deleted from the disk', async function () { |
146 | for (const server of servers) { | |
147 | await checkDirectoryIsEmpty(server, 'videos') | |
148 | await checkDirectoryIsEmpty(server, join('streaming-playlists', 'hls')) | |
149 | } | |
150 | }) | |
80b8ad2a | 151 | |
d7a25329 C |
152 | it('Should have an empty tmp directory', async function () { |
153 | for (const server of servers) { | |
154 | await checkTmpIsEmpty(server) | |
155 | } | |
156 | }) | |
157 | } | |
09209296 | 158 | |
d7a25329 C |
159 | before(async function () { |
160 | this.timeout(120000) | |
09209296 | 161 | |
d7a25329 C |
162 | const configOverride = { |
163 | transcoding: { | |
164 | enabled: true, | |
165 | allow_audio_files: true, | |
166 | hls: { | |
167 | enabled: true | |
168 | } | |
169 | } | |
09209296 | 170 | } |
d7a25329 C |
171 | servers = await flushAndRunMultipleServers(2, configOverride) |
172 | ||
173 | // Get the access tokens | |
174 | await setAccessTokensToServers(servers) | |
175 | ||
176 | // Server 1 and server 2 follow each other | |
177 | await doubleFollow(servers[0], servers[1]) | |
09209296 C |
178 | }) |
179 | ||
d7a25329 C |
180 | describe('With WebTorrent & HLS enabled', function () { |
181 | runTestSuite(false) | |
09209296 C |
182 | }) |
183 | ||
d7a25329 C |
184 | describe('With only HLS enabled', function () { |
185 | ||
186 | before(async function () { | |
187 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { | |
188 | transcoding: { | |
189 | enabled: true, | |
190 | allowAudioFiles: true, | |
191 | resolutions: { | |
192 | '240p': true, | |
193 | '360p': true, | |
194 | '480p': true, | |
195 | '720p': true, | |
196 | '1080p': true, | |
197 | '2160p': true | |
198 | }, | |
199 | hls: { | |
200 | enabled: true | |
201 | }, | |
202 | webtorrent: { | |
203 | enabled: false | |
204 | } | |
205 | } | |
206 | }) | |
207 | }) | |
208 | ||
209 | runTestSuite(true) | |
09209296 C |
210 | }) |
211 | ||
7c3b7976 C |
212 | after(async function () { |
213 | await cleanupTests(servers) | |
09209296 C |
214 | }) |
215 | }) |