X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fshared%2Flive.ts;h=47e0dc481e6f6b35e6cf51db1431eb6af4f0fe90;hb=b8598d40f650a31fe09a4a5426dcdc2c5c0d566c;hp=aa79622cbb57cce134f987620220974662ccb892;hpb=cfd57d2ca0bb058087f7dc90fcc3e8442b0288e1;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/shared/live.ts b/server/tests/shared/live.ts index aa79622cb..47e0dc481 100644 --- a/server/tests/shared/live.ts +++ b/server/tests/shared/live.ts @@ -3,15 +3,29 @@ import { expect } from 'chai' import { pathExists, readdir } from 'fs-extra' import { join } from 'path' -import { wait } from '@shared/core-utils' import { LiveVideo, VideoStreamingPlaylistType } from '@shared/models' import { ObjectStorageCommand, PeerTubeServer } from '@shared/server-commands' import { checkLiveSegmentHash, checkResolutionsInMasterPlaylist } from './streaming-playlists' -async function checkLiveCleanup (server: PeerTubeServer, videoUUID: string, savedResolutions: number[] = []) { +async function checkLiveCleanup (options: { + server: PeerTubeServer + videoUUID: string + permanent: boolean + savedResolutions?: number[] +}) { + const { server, videoUUID, permanent, savedResolutions = [] } = options + const basePath = server.servers.buildDirectory('streaming-playlists') const hlsPath = join(basePath, 'hls', videoUUID) + if (permanent) { + if (!await pathExists(hlsPath)) return + + const files = await readdir(hlsPath) + expect(files).to.have.lengthOf(0) + return + } + if (savedResolutions.length === 0) { return checkUnsavedLiveCleanup(server, videoUUID, hlsPath) } @@ -42,29 +56,41 @@ async function testVideoResolutions (options: { expect(hlsPlaylist).to.exist expect(hlsPlaylist.files).to.have.lengthOf(0) // Only fragmented mp4 files are displayed - await checkResolutionsInMasterPlaylist({ server, playlistUrl: hlsPlaylist.playlistUrl, resolutions, transcoded }) + await checkResolutionsInMasterPlaylist({ + server, + playlistUrl: hlsPlaylist.playlistUrl, + resolutions, + transcoded, + withRetry: objectStorage + }) if (objectStorage) { - expect(hlsPlaylist.playlistUrl).to.contain(ObjectStorageCommand.getPlaylistBaseUrl()) + expect(hlsPlaylist.playlistUrl).to.contain(ObjectStorageCommand.getMockPlaylistBaseUrl()) } for (let i = 0; i < resolutions.length; i++) { const segmentNum = 3 const segmentName = `${i}-00000${segmentNum}.ts` - await originServer.live.waitUntilSegmentGeneration({ videoUUID: video.uuid, playlistNumber: i, segment: segmentNum }) + await originServer.live.waitUntilSegmentGeneration({ + server: originServer, + videoUUID: video.uuid, + playlistNumber: i, + segment: segmentNum, + objectStorage + }) const baseUrl = objectStorage - ? ObjectStorageCommand.getPlaylistBaseUrl() + 'hls' + ? ObjectStorageCommand.getMockPlaylistBaseUrl() + 'hls' : originServer.url + '/static/streaming-playlists/hls' if (objectStorage) { - // Playlist file upload - await wait(500) - - expect(hlsPlaylist.segmentsSha256Url).to.contain(ObjectStorageCommand.getPlaylistBaseUrl()) + expect(hlsPlaylist.segmentsSha256Url).to.contain(ObjectStorageCommand.getMockPlaylistBaseUrl()) } - const subPlaylist = await originServer.streamingPlaylists.get({ url: `${baseUrl}/${video.uuid}/${i}.m3u8` }) + 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 + }) expect(subPlaylist).to.contain(segmentName)