From bb4ba6d94c5051fdd665ebe63fffcc105778b8be Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 3 Dec 2020 14:10:54 +0100 Subject: Add permanent live support --- server/tests/api/check-params/live.ts | 15 ++- server/tests/api/live/index.ts | 1 + server/tests/api/live/live-permanent.ts | 190 ++++++++++++++++++++++++++++++++ 3 files changed, 205 insertions(+), 1 deletion(-) create mode 100644 server/tests/api/live/live-permanent.ts (limited to 'server/tests') diff --git a/server/tests/api/check-params/live.ts b/server/tests/api/check-params/live.ts index 2b2d1beec..055f2f295 100644 --- a/server/tests/api/check-params/live.ts +++ b/server/tests/api/check-params/live.ts @@ -84,7 +84,8 @@ describe('Test video lives API validator', function () { tags: [ 'tag1', 'tag2' ], privacy: VideoPrivacy.PUBLIC, channelId, - saveReplay: false + saveReplay: false, + permanentLive: false } }) @@ -211,6 +212,12 @@ describe('Test video lives API validator', function () { await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) }) + it('Should fail with save replay and permanent live set to true', async function () { + const fields = immutableAssign(baseCorrectParams, { saveReplay: true, permanentLive: true }) + + await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) + }) + it('Should succeed with the correct parameters', async function () { this.timeout(30000) @@ -372,6 +379,12 @@ describe('Test video lives API validator', function () { await updateLive(server.url, server.accessToken, videoIdNotLive, {}, 404) }) + it('Should fail with save replay and permanent live set to true', async function () { + const fields = { saveReplay: true, permanentLive: true } + + await updateLive(server.url, server.accessToken, videoId, fields, 400) + }) + it('Should succeed with the correct params', async function () { await updateLive(server.url, server.accessToken, videoId, { saveReplay: false }) }) diff --git a/server/tests/api/live/index.ts b/server/tests/api/live/index.ts index 32219969a..c733f564e 100644 --- a/server/tests/api/live/index.ts +++ b/server/tests/api/live/index.ts @@ -1,3 +1,4 @@ import './live-constraints' +import './live-permanent' import './live-save-replay' import './live' diff --git a/server/tests/api/live/live-permanent.ts b/server/tests/api/live/live-permanent.ts new file mode 100644 index 000000000..a64588ed7 --- /dev/null +++ b/server/tests/api/live/live-permanent.ts @@ -0,0 +1,190 @@ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ + +import 'mocha' +import * as chai from 'chai' +import { LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState } from '@shared/models' +import { + checkLiveCleanup, + cleanupTests, + createLive, + doubleFollow, + flushAndRunMultipleServers, + getLive, + getPlaylistsCount, + getVideo, + sendRTMPStreamInVideo, + ServerInfo, + setAccessTokensToServers, + setDefaultVideoChannel, + stopFfmpeg, + updateCustomSubConfig, + updateLive, + wait, + waitJobs, + waitUntilLiveStarts +} from '../../../../shared/extra-utils' + +const expect = chai.expect + +describe('Permenant live', function () { + let servers: ServerInfo[] = [] + let videoUUID: string + + async function createLiveWrapper (permanentLive: boolean) { + const attributes: LiveVideoCreate = { + channelId: servers[0].videoChannel.id, + privacy: VideoPrivacy.PUBLIC, + name: 'my super live', + saveReplay: false, + permanentLive + } + + const res = await createLive(servers[0].url, servers[0].accessToken, attributes) + return res.body.video.uuid + } + + async function checkVideoState (videoId: string, state: VideoState) { + for (const server of servers) { + const res = await getVideo(server.url, videoId) + expect((res.body as VideoDetails).state.id).to.equal(state) + } + } + + before(async function () { + this.timeout(120000) + + servers = await flushAndRunMultipleServers(2) + + // Get the access tokens + await setAccessTokensToServers(servers) + await setDefaultVideoChannel(servers) + + // Server 1 and server 2 follow each other + await doubleFollow(servers[0], servers[1]) + + await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { + live: { + enabled: true, + allowReplay: true, + maxDuration: null, + transcoding: { + enabled: true, + resolutions: { + '240p': true, + '360p': true, + '480p': true, + '720p': true, + '1080p': true, + '2160p': true + } + } + } + }) + }) + + it('Should create a non permanent live and update it to be a permanent live', async function () { + this.timeout(20000) + + const videoUUID = await createLiveWrapper(false) + + { + const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID) + expect(res.body.permanentLive).to.be.false + } + + await updateLive(servers[0].url, servers[0].accessToken, videoUUID, { permanentLive: true }) + + { + const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID) + expect(res.body.permanentLive).to.be.true + } + }) + + it('Should create a permanent live', async function () { + this.timeout(20000) + + videoUUID = await createLiveWrapper(true) + + const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID) + expect(res.body.permanentLive).to.be.true + + await waitJobs(servers) + }) + + it('Should stream into this permanent live', async function () { + this.timeout(40000) + + const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, videoUUID) + + for (const server of servers) { + await waitUntilLiveStarts(server.url, server.accessToken, videoUUID) + } + + await checkVideoState(videoUUID, VideoState.PUBLISHED) + + await stopFfmpeg(command) + + await waitJobs(servers) + }) + + it('Should not have cleaned up this live', async function () { + this.timeout(40000) + + await wait(5000) + await waitJobs(servers) + + for (const server of servers) { + const res = await getVideo(server.url, videoUUID) + + const videoDetails = res.body as VideoDetails + expect(videoDetails.streamingPlaylists).to.have.lengthOf(1) + } + }) + + it('Should have set this live to waiting for live state', async function () { + this.timeout(20000) + + await checkVideoState(videoUUID, VideoState.WAITING_FOR_LIVE) + }) + + it('Should be able to stream again in the permanent live', async function () { + this.timeout(20000) + + await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { + live: { + enabled: true, + allowReplay: true, + maxDuration: null, + transcoding: { + enabled: true, + resolutions: { + '240p': false, + '360p': false, + '480p': false, + '720p': false, + '1080p': false, + '2160p': false + } + } + } + }) + + const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, videoUUID) + + for (const server of servers) { + await waitUntilLiveStarts(server.url, server.accessToken, videoUUID) + } + + await checkVideoState(videoUUID, VideoState.PUBLISHED) + + const count = await getPlaylistsCount(servers[0], videoUUID) + // master playlist and 720p playlist + expect(count).to.equal(2) + + await stopFfmpeg(command) + }) + + after(async function () { + await cleanupTests(servers) + }) +}) -- cgit v1.2.3