aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/shared/live.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/shared/live.ts')
-rw-r--r--server/tests/shared/live.ts131
1 files changed, 108 insertions, 23 deletions
diff --git a/server/tests/shared/live.ts b/server/tests/shared/live.ts
index 4bd4786fc..da3691711 100644
--- a/server/tests/shared/live.ts
+++ b/server/tests/shared/live.ts
@@ -3,39 +3,103 @@
3import { expect } from 'chai' 3import { expect } from 'chai'
4import { pathExists, readdir } from 'fs-extra' 4import { pathExists, readdir } from 'fs-extra'
5import { join } from 'path' 5import { join } from 'path'
6import { LiveVideo } from '@shared/models' 6import { LiveVideo, VideoStreamingPlaylistType } from '@shared/models'
7import { PeerTubeServer } from '@shared/server-commands' 7import { ObjectStorageCommand, PeerTubeServer } from '@shared/server-commands'
8import { checkLiveSegmentHash, checkResolutionsInMasterPlaylist } from './streaming-playlists'
8 9
9async function checkLiveCleanup (server: PeerTubeServer, videoUUID: string, savedResolutions: number[] = []) { 10async function checkLiveCleanup (server: PeerTubeServer, videoUUID: string, savedResolutions: number[] = []) {
10 let live: LiveVideo
11
12 try {
13 live = await server.live.get({ videoId: videoUUID })
14 } catch {}
15
16 const basePath = server.servers.buildDirectory('streaming-playlists') 11 const basePath = server.servers.buildDirectory('streaming-playlists')
17 const hlsPath = join(basePath, 'hls', videoUUID) 12 const hlsPath = join(basePath, 'hls', videoUUID)
18 13
19 if (savedResolutions.length === 0) { 14 if (savedResolutions.length === 0) {
15 return checkUnsavedLiveCleanup(server, videoUUID, hlsPath)
16 }
20 17
21 if (live?.permanentLive) { 18 return checkSavedLiveCleanup(hlsPath, savedResolutions)
22 expect(await pathExists(hlsPath)).to.be.true 19}
23
24 const hlsFiles = await readdir(hlsPath)
25 expect(hlsFiles).to.have.lengthOf(1) // Only replays directory
26
27 const replayDir = join(hlsPath, 'replay')
28 expect(await pathExists(replayDir)).to.be.true
29 20
30 const replayFiles = await readdir(join(hlsPath, 'replay')) 21// ---------------------------------------------------------------------------
31 expect(replayFiles).to.have.lengthOf(0) 22
32 } else { 23async function testVideoResolutions (options: {
33 expect(await pathExists(hlsPath)).to.be.false 24 originServer: PeerTubeServer
25 servers: PeerTubeServer[]
26 liveVideoId: string
27 resolutions: number[]
28 transcoded: boolean
29 objectStorage: boolean
30}) {
31 const { originServer, servers, liveVideoId, resolutions, transcoded, objectStorage } = options
32
33 for (const server of servers) {
34 const { data } = await server.videos.list()
35 expect(data.find(v => v.uuid === liveVideoId)).to.exist
36
37 const video = await server.videos.get({ id: liveVideoId })
38 expect(video.streamingPlaylists).to.have.lengthOf(1)
39
40 const hlsPlaylist = video.streamingPlaylists.find(s => s.type === VideoStreamingPlaylistType.HLS)
41 expect(hlsPlaylist).to.exist
42 expect(hlsPlaylist.files).to.have.lengthOf(0) // Only fragmented mp4 files are displayed
43
44 await checkResolutionsInMasterPlaylist({
45 server,
46 playlistUrl: hlsPlaylist.playlistUrl,
47 resolutions,
48 transcoded,
49 withRetry: objectStorage
50 })
51
52 if (objectStorage) {
53 expect(hlsPlaylist.playlistUrl).to.contain(ObjectStorageCommand.getPlaylistBaseUrl())
34 } 54 }
35 55
36 return 56 for (let i = 0; i < resolutions.length; i++) {
57 const segmentNum = 3
58 const segmentName = `${i}-00000${segmentNum}.ts`
59 await originServer.live.waitUntilSegmentGeneration({
60 server: originServer,
61 videoUUID: video.uuid,
62 playlistNumber: i,
63 segment: segmentNum,
64 objectStorage
65 })
66
67 const baseUrl = objectStorage
68 ? ObjectStorageCommand.getPlaylistBaseUrl() + 'hls'
69 : originServer.url + '/static/streaming-playlists/hls'
70
71 if (objectStorage) {
72 expect(hlsPlaylist.segmentsSha256Url).to.contain(ObjectStorageCommand.getPlaylistBaseUrl())
73 }
74
75 const subPlaylist = await originServer.streamingPlaylists.get({
76 url: `${baseUrl}/${video.uuid}/${i}.m3u8`,
77 withRetry: objectStorage // With object storage, the request may fail because of inconsistent data in S3
78 })
79
80 expect(subPlaylist).to.contain(segmentName)
81
82 await checkLiveSegmentHash({
83 server,
84 baseUrlSegment: baseUrl,
85 videoUUID: video.uuid,
86 segmentName,
87 hlsPlaylist
88 })
89 }
37 } 90 }
91}
92
93// ---------------------------------------------------------------------------
94
95export {
96 checkLiveCleanup,
97 testVideoResolutions
98}
99
100// ---------------------------------------------------------------------------
38 101
102async function checkSavedLiveCleanup (hlsPath: string, savedResolutions: number[] = []) {
39 const files = await readdir(hlsPath) 103 const files = await readdir(hlsPath)
40 104
41 // fragmented file and playlist per resolution + master playlist + segments sha256 json file 105 // fragmented file and playlist per resolution + master playlist + segments sha256 json file
@@ -56,6 +120,27 @@ async function checkLiveCleanup (server: PeerTubeServer, videoUUID: string, save
56 expect(shaFile).to.exist 120 expect(shaFile).to.exist
57} 121}
58 122
59export { 123async function checkUnsavedLiveCleanup (server: PeerTubeServer, videoUUID: string, hlsPath: string) {
60 checkLiveCleanup 124 let live: LiveVideo
125
126 try {
127 live = await server.live.get({ videoId: videoUUID })
128 } catch {}
129
130 if (live?.permanentLive) {
131 expect(await pathExists(hlsPath)).to.be.true
132
133 const hlsFiles = await readdir(hlsPath)
134 expect(hlsFiles).to.have.lengthOf(1) // Only replays directory
135
136 const replayDir = join(hlsPath, 'replay')
137 expect(await pathExists(replayDir)).to.be.true
138
139 const replayFiles = await readdir(join(hlsPath, 'replay'))
140 expect(replayFiles).to.have.lengthOf(0)
141
142 return
143 }
144
145 expect(await pathExists(hlsPath)).to.be.false
61} 146}