From 53023be33af420675d0060eb95c99a8038457564 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 23 Jun 2022 10:29:43 +0200 Subject: Fix fast restream in saved permanent live --- server/tests/api/live/index.ts | 1 + server/tests/api/live/live-fast-restream.ts | 128 ++++++++++++++++++++++++++++ server/tests/api/live/live-save-replay.ts | 41 --------- server/tests/api/live/live.ts | 8 +- 4 files changed, 133 insertions(+), 45 deletions(-) create mode 100644 server/tests/api/live/live-fast-restream.ts (limited to 'server/tests/api') diff --git a/server/tests/api/live/index.ts b/server/tests/api/live/index.ts index 71bc150d8..c88943f65 100644 --- a/server/tests/api/live/index.ts +++ b/server/tests/api/live/index.ts @@ -1,4 +1,5 @@ import './live-constraints' +import './live-fast-restream' import './live-socket-messages' import './live-permanent' import './live-rtmps' diff --git a/server/tests/api/live/live-fast-restream.ts b/server/tests/api/live/live-fast-restream.ts new file mode 100644 index 000000000..4b5d041ec --- /dev/null +++ b/server/tests/api/live/live-fast-restream.ts @@ -0,0 +1,128 @@ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ + +import 'mocha' +import * as chai from 'chai' +import { wait } from '@shared/core-utils' +import { HttpStatusCode, LiveVideoCreate, VideoPrivacy } from '@shared/models' +import { + cleanupTests, + createSingleServer, + makeRawRequest, + PeerTubeServer, + setAccessTokensToServers, + setDefaultVideoChannel, + stopFfmpeg, + waitJobs +} from '@shared/server-commands' + +const expect = chai.expect + +describe('Fast restream in live', function () { + let server: PeerTubeServer + + async function createLiveWrapper (options: { permanent: boolean, replay: boolean }) { + const attributes: LiveVideoCreate = { + channelId: server.store.channel.id, + privacy: VideoPrivacy.PUBLIC, + name: 'my super live', + saveReplay: options.replay, + permanentLive: options.permanent + } + + const { uuid } = await server.live.create({ fields: attributes }) + return uuid + } + + async function fastRestreamWrapper ({ replay }: { replay: boolean }) { + const liveVideoUUID = await createLiveWrapper({ permanent: true, replay }) + await waitJobs([ server ]) + + const rtmpOptions = { + videoId: liveVideoUUID, + copyCodecs: true, + fixtureName: 'video_short.mp4' + } + + // Streaming session #1 + let ffmpegCommand = await server.live.sendRTMPStreamInVideo(rtmpOptions) + await server.live.waitUntilPublished({ videoId: liveVideoUUID }) + await stopFfmpeg(ffmpegCommand) + await server.live.waitUntilWaiting({ videoId: liveVideoUUID }) + + // Streaming session #2 + ffmpegCommand = await server.live.sendRTMPStreamInVideo(rtmpOptions) + await server.live.waitUntilSegmentGeneration({ videoUUID: liveVideoUUID, segment: 0, playlistNumber: 0, totalSessions: 2 }) + + return { ffmpegCommand, liveVideoUUID } + } + + async function ensureLastLiveWorks (liveId: string) { + // Equivalent to PEERTUBE_TEST_CONSTANTS.VIDEO_LIVE.CLEANUP_DELAY + for (let i = 0; i < 100; i++) { + const video = await server.videos.get({ id: liveId }) + expect(video.streamingPlaylists).to.have.lengthOf(1) + + await server.live.getSegment({ videoUUID: liveId, segment: 0, playlistNumber: 0 }) + await makeRawRequest(video.streamingPlaylists[0].playlistUrl, HttpStatusCode.OK_200) + + await wait(100) + } + } + + async function runTest (replay: boolean) { + const { ffmpegCommand, liveVideoUUID } = await fastRestreamWrapper({ replay }) + + await ensureLastLiveWorks(liveVideoUUID) + + await stopFfmpeg(ffmpegCommand) + await server.live.waitUntilWaiting({ videoId: liveVideoUUID }) + + // Wait for replays + await waitJobs([ server ]) + + const { total, data: sessions } = await server.live.listSessions({ videoId: liveVideoUUID }) + + expect(total).to.equal(2) + expect(sessions).to.have.lengthOf(2) + + for (const session of sessions) { + expect(session.error).to.be.null + + if (replay) { + expect(session.replayVideo).to.exist + + await server.videos.get({ id: session.replayVideo.uuid }) + } else { + expect(session.replayVideo).to.not.exist + } + } + } + + before(async function () { + this.timeout(120000) + + const env = { 'PEERTUBE_TEST_CONSTANTS.VIDEO_LIVE.CLEANUP_DELAY': '10000' } + server = await createSingleServer(1, {}, { env }) + + // Get the access tokens + await setAccessTokensToServers([ server ]) + await setDefaultVideoChannel([ server ]) + + await server.config.enableMinimumTranscoding(false, true) + await server.config.enableLive({ allowReplay: true, transcoding: true, resolutions: 'min' }) + }) + + it('Should correctly fast reastream in a permanent live with and without save replay', async function () { + this.timeout(240000) + + // A test can take a long time, so prefer to run them in parallel + await Promise.all([ + runTest(true), + runTest(false) + ]) + }) + + after(async function () { + await cleanupTests([ server ]) + }) +}) diff --git a/server/tests/api/live/live-save-replay.ts b/server/tests/api/live/live-save-replay.ts index 99d500711..7ddcb04ef 100644 --- a/server/tests/api/live/live-save-replay.ts +++ b/server/tests/api/live/live-save-replay.ts @@ -12,7 +12,6 @@ import { createMultipleServers, doubleFollow, findExternalSavedVideo, - makeRawRequest, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, @@ -442,46 +441,6 @@ describe('Save replay setting', function () { await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404) await checkLiveCleanup(servers[0], liveVideoUUID, []) }) - - it('Should correctly save replays with multiple sessions', async function () { - this.timeout(120000) - - liveVideoUUID = await createLiveWrapper({ permanent: true, replay: true }) - await waitJobs(servers) - - // Streaming session #1 - ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) - await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID) - await stopFfmpeg(ffmpegCommand) - await servers[0].live.waitUntilWaiting({ videoId: liveVideoUUID }) - - // Streaming session #2 - ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) - await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID) - - await wait(5000) - const video = await servers[0].videos.get({ id: liveVideoUUID }) - expect(video.streamingPlaylists).to.have.lengthOf(1) - await makeRawRequest(video.streamingPlaylists[0].playlistUrl) - - await stopFfmpeg(ffmpegCommand) - await waitUntilLiveWaitingOnAllServers(servers, liveVideoUUID) - - // Wait for replays - await waitJobs(servers) - - const { total, data: sessions } = await servers[0].live.listSessions({ videoId: liveVideoUUID }) - - expect(total).to.equal(2) - expect(sessions).to.have.lengthOf(2) - - for (const session of sessions) { - expect(session.error).to.be.null - expect(session.replayVideo).to.exist - - await servers[0].videos.get({ id: session.replayVideo.uuid }) - } - }) }) after(async function () { diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts index 9b8fbe3e2..5d354aad1 100644 --- a/server/tests/api/live/live.ts +++ b/server/tests/api/live/live.ts @@ -395,7 +395,7 @@ describe('Test live', function () { for (let i = 0; i < resolutions.length; i++) { const segmentNum = 3 const segmentName = `${i}-00000${segmentNum}.ts` - await commands[0].waitUntilSegmentGeneration({ videoUUID: video.uuid, resolution: i, segment: segmentNum }) + await commands[0].waitUntilSegmentGeneration({ videoUUID: video.uuid, playlistNumber: i, segment: segmentNum }) const subPlaylist = await servers[0].streamingPlaylists.get({ url: `${servers[0].url}/static/streaming-playlists/hls/${video.uuid}/${i}.m3u8` @@ -628,9 +628,9 @@ describe('Test live', function () { commands[0].waitUntilPublished({ videoId: liveVideoReplayId }) ]) - await commands[0].waitUntilSegmentGeneration({ videoUUID: liveVideoId, resolution: 0, segment: 2 }) - await commands[0].waitUntilSegmentGeneration({ videoUUID: liveVideoReplayId, resolution: 0, segment: 2 }) - await commands[0].waitUntilSegmentGeneration({ videoUUID: permanentLiveVideoReplayId, resolution: 0, segment: 2 }) + await commands[0].waitUntilSegmentGeneration({ videoUUID: liveVideoId, playlistNumber: 0, segment: 2 }) + await commands[0].waitUntilSegmentGeneration({ videoUUID: liveVideoReplayId, playlistNumber: 0, segment: 2 }) + await commands[0].waitUntilSegmentGeneration({ videoUUID: permanentLiveVideoReplayId, playlistNumber: 0, segment: 2 }) { const video = await servers[0].videos.get({ id: permanentLiveVideoReplayId }) -- cgit v1.2.3 From 20886f4bf968dd23b50f66137b1aaac06cb8edfb Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 8 Jun 2022 14:58:34 +0200 Subject: Fix search index tests --- server/tests/api/search/search-index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/search/search-index.ts b/server/tests/api/search/search-index.ts index 287abe455..53b91e1cb 100644 --- a/server/tests/api/search/search-index.ts +++ b/server/tests/api/search/search-index.ts @@ -136,14 +136,14 @@ describe('Test index search', function () { expect(video.account.url).to.equal('https://framatube.org/accounts/framasoft') // TODO: remove, deprecated in 4.2 expect(video.account.avatar).to.exist - expect(video.account.avatars.length).to.equal(1, 'Account should have one avatar image') + expect(video.account.avatars.length).to.equal(2, 'Account should have one avatar image') expect(video.channel.host).to.equal('framatube.org') expect(video.channel.name).to.equal('joinpeertube') expect(video.channel.url).to.equal('https://framatube.org/video-channels/joinpeertube') // TODO: remove, deprecated in 4.2 expect(video.channel.avatar).to.exist - expect(video.channel.avatars.length).to.equal(1, 'Channel should have one avatar image') + expect(video.channel.avatars.length).to.equal(2, 'Channel should have one avatar image') } const baseSearch: VideosSearchQuery = { @@ -322,7 +322,7 @@ describe('Test index search', function () { expect(videoChannel.host).to.equal('framatube.org') // TODO: remove, deprecated in 4.2 expect(videoChannel.avatar).to.exist - expect(videoChannel.avatars.length).to.equal(1, 'Channel should have two avatar images') + expect(videoChannel.avatars.length).to.equal(2, 'Channel should have two avatar images') expect(videoChannel.displayName).to.exist expect(videoChannel.ownerAccount.url).to.equal('https://framatube.org/accounts/framasoft') @@ -330,7 +330,7 @@ describe('Test index search', function () { expect(videoChannel.ownerAccount.host).to.equal('framatube.org') // TODO: remove, deprecated in 4.2 expect(videoChannel.ownerAccount.avatar).to.exist - expect(videoChannel.ownerAccount.avatars.length).to.equal(1, 'Account should have two avatar images') + expect(videoChannel.ownerAccount.avatars.length).to.equal(2, 'Account should have two avatar images') } it('Should make a simple search and not have results', async function () { -- cgit v1.2.3