Fix tests

This commit is contained in:
Chocobozzz 2024-09-11 15:50:30 +02:00
parent 71bdad9f5e
commit 8e644dedb2
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 16 additions and 20 deletions

View File

@ -42,8 +42,8 @@ async function checkStoryboard (options: {
expect(storyboard.storyboardPath).to.exist
if (tilesCount) {
expect(storyboard.totalWidth).to.equal(spriteWidth * Math.min(tilesCount, 10))
expect(storyboard.totalHeight).to.equal(spriteHeight * Math.max((tilesCount / 10), 1))
expect(storyboard.totalWidth).to.equal(spriteWidth * Math.min(tilesCount, 11))
expect(storyboard.totalHeight).to.equal(spriteHeight * Math.max((tilesCount / 11), 1))
}
const { body } = await makeGetRequest({ url: server.url, path: storyboard.storyboardPath, expectedStatus: HttpStatusCode.OK_200 })
@ -86,7 +86,7 @@ describe('Test video storyboard', function () {
await waitJobs(servers)
for (const server of servers) {
await checkStoryboard({ server, uuid, spriteDuration: 2, spriteHeight: 154, tilesCount: 60 })
await checkStoryboard({ server, uuid, spriteDuration: 2, spriteHeight: 154, tilesCount: 66 })
}
})

View File

@ -1,20 +1,21 @@
import { pathExists, remove } from 'fs-extra/esm'
import { readdir, rmdir } from 'fs/promises'
import { basename, join } from 'path'
import { LiveVideoLatencyMode, LiveVideoLatencyModeType, FileStorage, VideoState } from '@peertube/peertube-models'
import { wait } from '@peertube/peertube-core-utils'
import { FileStorage, LiveVideoLatencyMode, LiveVideoLatencyModeType, VideoState } from '@peertube/peertube-models'
import { logger } from '@server/helpers/logger.js'
import { VIDEO_LIVE } from '@server/initializers/constants.js'
import { MStreamingPlaylist, MStreamingPlaylistVideo, MVideo } from '@server/types/models/index.js'
import { pathExists, remove, } from 'fs-extra/esm'
import { readdir, rmdir } from 'fs/promises'
import { basename, join } from 'path'
import { listHLSFileKeysOf, removeHLSFileObjectStorageByFullKey, removeHLSObjectStorage } from '../object-storage/index.js'
import { getLiveDirectory, getLiveReplayBaseDirectory } from '../paths.js'
function buildConcatenatedName (segmentOrPlaylistPath: string) {
export function buildConcatenatedName (segmentOrPlaylistPath: string) {
const num = basename(segmentOrPlaylistPath).match(/^(\d+)(-|\.)/)
return 'concat-' + num[1] + '.ts'
}
async function cleanupAndDestroyPermanentLive (video: MVideo, streamingPlaylist: MStreamingPlaylist) {
export async function cleanupAndDestroyPermanentLive (video: MVideo, streamingPlaylist: MStreamingPlaylist) {
await cleanupTMPLiveFiles(video, streamingPlaylist)
if (video.state === VideoState.WAITING_FOR_LIVE) {
@ -22,6 +23,7 @@ async function cleanupAndDestroyPermanentLive (video: MVideo, streamingPlaylist:
// Object storage doesn't have the concept of directories so we don't need to duplicate the logic here
try {
await rmdir(getLiveReplayBaseDirectory(video))
await wait(100)
await rmdir(getLiveDirectory(video))
} catch (err) {
logger.debug('Cannot cleanup permanent local live files', { err })
@ -31,7 +33,7 @@ async function cleanupAndDestroyPermanentLive (video: MVideo, streamingPlaylist:
await streamingPlaylist.destroy()
}
async function cleanupUnsavedNormalLive (video: MVideo, streamingPlaylist: MStreamingPlaylist) {
export async function cleanupUnsavedNormalLive (video: MVideo, streamingPlaylist: MStreamingPlaylist) {
const hlsDirectory = getLiveDirectory(video)
// We uploaded files to object storage too, remove them
@ -44,13 +46,13 @@ async function cleanupUnsavedNormalLive (video: MVideo, streamingPlaylist: MStre
await streamingPlaylist.destroy()
}
async function cleanupTMPLiveFiles (video: MVideo, streamingPlaylist: MStreamingPlaylist) {
export async function cleanupTMPLiveFiles (video: MVideo, streamingPlaylist: MStreamingPlaylist) {
await cleanupTMPLiveFilesFromObjectStorage(streamingPlaylist.withVideo(video))
await cleanupTMPLiveFilesFromFilesystem(video)
}
function getLiveSegmentTime (latencyMode: LiveVideoLatencyModeType) {
export function getLiveSegmentTime (latencyMode: LiveVideoLatencyModeType) {
if (latencyMode === LiveVideoLatencyMode.SMALL_LATENCY) {
return VIDEO_LIVE.SEGMENT_TIME_SECONDS.SMALL_LATENCY
}
@ -58,14 +60,8 @@ function getLiveSegmentTime (latencyMode: LiveVideoLatencyModeType) {
return VIDEO_LIVE.SEGMENT_TIME_SECONDS.DEFAULT_LATENCY
}
export {
cleanupAndDestroyPermanentLive,
cleanupUnsavedNormalLive,
cleanupTMPLiveFiles,
getLiveSegmentTime,
buildConcatenatedName
}
// ---------------------------------------------------------------------------
// Private
// ---------------------------------------------------------------------------
function isTMPLiveFile (name: string) {