From 8e644dedb2a4a427f66c17f5077ff0ce1b9740bf Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 11 Sep 2024 15:50:30 +0200 Subject: [PATCH] Fix tests --- .../tests/src/api/videos/video-storyboard.ts | 6 ++-- server/core/lib/live/live-utils.ts | 30 ++++++++----------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/packages/tests/src/api/videos/video-storyboard.ts b/packages/tests/src/api/videos/video-storyboard.ts index ebac297ca..eb2354210 100644 --- a/packages/tests/src/api/videos/video-storyboard.ts +++ b/packages/tests/src/api/videos/video-storyboard.ts @@ -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 }) } }) diff --git a/server/core/lib/live/live-utils.ts b/server/core/lib/live/live-utils.ts index d3fe45534..2760a55c2 100644 --- a/server/core/lib/live/live-utils.ts +++ b/server/core/lib/live/live-utils.ts @@ -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) {