import { expect } from 'chai'
import { pathExists, readdir } from 'fs-extra'
import { join } from 'path'
+import { sha1 } from '@shared/extra-utils'
import { LiveVideo, VideoStreamingPlaylistType } from '@shared/models'
import { ObjectStorageCommand, PeerTubeServer } from '@shared/server-commands'
+import { SQLCommand } from './sql-command'
import { checkLiveSegmentHash, checkResolutionsInMasterPlaylist } from './streaming-playlists'
async function checkLiveCleanup (options: {
// ---------------------------------------------------------------------------
-async function testVideoResolutions (options: {
+async function testLiveVideoResolutions (options: {
+ sqlCommand: SQLCommand
originServer: PeerTubeServer
+
servers: PeerTubeServer[]
liveVideoId: string
resolutions: number[]
transcoded: boolean
- objectStorage: boolean
+
+ objectStorage?: ObjectStorageCommand
+ objectStorageBaseUrl?: string
}) {
- const { originServer, servers, liveVideoId, resolutions, transcoded, objectStorage } = options
+ const {
+ originServer,
+ sqlCommand,
+ servers,
+ liveVideoId,
+ resolutions,
+ transcoded,
+ objectStorage,
+ objectStorageBaseUrl = objectStorage?.getMockPlaylistBaseUrl()
+ } = options
for (const server of servers) {
const { data } = await server.videos.list()
playlistUrl: hlsPlaylist.playlistUrl,
resolutions,
transcoded,
- withRetry: objectStorage
+ withRetry: !!objectStorage
})
if (objectStorage) {
- expect(hlsPlaylist.playlistUrl).to.contain(ObjectStorageCommand.getMockPlaylistBaseUrl())
+ expect(hlsPlaylist.playlistUrl).to.contain(objectStorageBaseUrl)
}
for (let i = 0; i < resolutions.length; i++) {
videoUUID: video.uuid,
playlistNumber: i,
segment: segmentNum,
- objectStorage
+ objectStorage,
+ objectStorageBaseUrl
})
const baseUrl = objectStorage
- ? ObjectStorageCommand.getMockPlaylistBaseUrl() + 'hls'
+ ? join(objectStorageBaseUrl, 'hls')
: originServer.url + '/static/streaming-playlists/hls'
if (objectStorage) {
- expect(hlsPlaylist.segmentsSha256Url).to.contain(ObjectStorageCommand.getMockPlaylistBaseUrl())
+ expect(hlsPlaylist.segmentsSha256Url).to.contain(objectStorageBaseUrl)
}
const subPlaylist = await originServer.streamingPlaylists.get({
url: `${baseUrl}/${video.uuid}/${i}.m3u8`,
- withRetry: objectStorage // With object storage, the request may fail because of inconsistent data in S3
+ withRetry: !!objectStorage // With object storage, the request may fail because of inconsistent data in S3
})
expect(subPlaylist).to.contain(segmentName)
baseUrlSegment: baseUrl,
videoUUID: video.uuid,
segmentName,
- hlsPlaylist
+ hlsPlaylist,
+ withRetry: !!objectStorage // With object storage, the request may fail because of inconsistent data in S3
})
+
+ if (originServer.internalServerNumber === server.internalServerNumber) {
+ const infohash = sha1(`${2 + hlsPlaylist.playlistUrl}+V${i}`)
+ const dbInfohashes = await sqlCommand.getPlaylistInfohash(hlsPlaylist.id)
+
+ expect(dbInfohashes).to.include(infohash)
+ }
}
}
}
export {
checkLiveCleanup,
- testVideoResolutions
+ testLiveVideoResolutions
}
// ---------------------------------------------------------------------------
const files = await readdir(hlsPath)
// fragmented file and playlist per resolution + master playlist + segments sha256 json file
- expect(files).to.have.lengthOf(savedResolutions.length * 2 + 2)
+ expect(files, `Directory content: ${files.join(', ')}`).to.have.lengthOf(savedResolutions.length * 2 + 2)
for (const resolution of savedResolutions) {
const fragmentedFile = files.find(f => f.endsWith(`-${resolution}-fragmented.mp4`))