From f443a74649174b2f9347c158e30f8ac7aa3e958a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 4 Mar 2022 13:40:02 +0100 Subject: Add latency setting support --- server/tests/api/check-params/config.ts | 3 +++ server/tests/api/check-params/live.ts | 32 ++++++++++++++++++++++++++++++-- server/tests/api/live/live.ts | 9 ++++++++- server/tests/api/server/config.ts | 5 +++++ 4 files changed, 46 insertions(+), 3 deletions(-) (limited to 'server/tests') diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts index ce067a892..900f642c2 100644 --- a/server/tests/api/check-params/config.ts +++ b/server/tests/api/check-params/config.ts @@ -125,6 +125,9 @@ describe('Test config API validators', function () { enabled: true, allowReplay: false, + latencySetting: { + enabled: false + }, maxDuration: 30, maxInstanceLives: -1, maxUserLives: 50, diff --git a/server/tests/api/check-params/live.ts b/server/tests/api/check-params/live.ts index 8aee6164c..b253f5e20 100644 --- a/server/tests/api/check-params/live.ts +++ b/server/tests/api/check-params/live.ts @@ -3,7 +3,7 @@ import 'mocha' import { omit } from 'lodash' import { buildAbsoluteFixturePath } from '@shared/core-utils' -import { HttpStatusCode, VideoCreateResult, VideoPrivacy } from '@shared/models' +import { HttpStatusCode, LiveVideoLatencyMode, VideoCreateResult, VideoPrivacy } from '@shared/models' import { cleanupTests, createSingleServer, @@ -38,6 +38,9 @@ describe('Test video lives API validator', function () { newConfig: { live: { enabled: true, + latencySetting: { + enabled: false + }, maxInstanceLives: 20, maxUserLives: 20, allowReplay: true @@ -81,7 +84,8 @@ describe('Test video lives API validator', function () { privacy: VideoPrivacy.PUBLIC, channelId, saveReplay: false, - permanentLive: false + permanentLive: false, + latencyMode: LiveVideoLatencyMode.DEFAULT } }) @@ -214,6 +218,18 @@ describe('Test video lives API validator', function () { await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) + it('Should fail with bad latency setting', async function () { + const fields = { ...baseCorrectParams, latencyMode: 42 } + + await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) + }) + + it('Should fail to set latency if the server does not allow it', async function () { + const fields = { ...baseCorrectParams, latencyMode: LiveVideoLatencyMode.HIGH_LATENCY } + + await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) + }) + it('Should succeed with the correct parameters', async function () { this.timeout(30000) @@ -393,6 +409,18 @@ describe('Test video lives API validator', function () { await command.update({ videoId: video.id, fields, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) + it('Should fail with bad latency setting', async function () { + const fields = { latencyMode: 42 } + + await command.update({ videoId: video.id, fields, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + }) + + it('Should fail to set latency if the server does not allow it', async function () { + const fields = { latencyMode: LiveVideoLatencyMode.HIGH_LATENCY } + + await command.update({ videoId: video.id, fields, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) + }) + it('Should succeed with the correct params', async function () { await command.update({ videoId: video.id, fields: { saveReplay: false } }) await command.update({ videoId: video.uuid, fields: { saveReplay: false } }) diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts index d756a02c1..aeb039696 100644 --- a/server/tests/api/live/live.ts +++ b/server/tests/api/live/live.ts @@ -10,6 +10,7 @@ import { HttpStatusCode, LiveVideo, LiveVideoCreate, + LiveVideoLatencyMode, VideoDetails, VideoPrivacy, VideoState, @@ -52,6 +53,9 @@ describe('Test live', function () { live: { enabled: true, allowReplay: true, + latencySetting: { + enabled: true + }, transcoding: { enabled: false } @@ -85,6 +89,7 @@ describe('Test live', function () { commentsEnabled: false, downloadEnabled: false, saveReplay: true, + latencyMode: LiveVideoLatencyMode.SMALL_LATENCY, privacy: VideoPrivacy.PUBLIC, previewfile: 'video_short1-preview.webm.jpg', thumbnailfile: 'video_short1.webm.jpg' @@ -131,6 +136,7 @@ describe('Test live', function () { } expect(live.saveReplay).to.be.true + expect(live.latencyMode).to.equal(LiveVideoLatencyMode.SMALL_LATENCY) } }) @@ -175,7 +181,7 @@ describe('Test live', function () { it('Should update the live', async function () { this.timeout(10000) - await commands[0].update({ videoId: liveVideoUUID, fields: { saveReplay: false } }) + await commands[0].update({ videoId: liveVideoUUID, fields: { saveReplay: false, latencyMode: LiveVideoLatencyMode.DEFAULT } }) await waitJobs(servers) }) @@ -192,6 +198,7 @@ describe('Test live', function () { } expect(live.saveReplay).to.be.false + expect(live.latencyMode).to.equal(LiveVideoLatencyMode.DEFAULT) } }) diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index 565b2953a..5028b65e6 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts @@ -82,6 +82,7 @@ function checkInitialConfig (server: PeerTubeServer, data: CustomConfig) { expect(data.live.enabled).to.be.false expect(data.live.allowReplay).to.be.false + expect(data.live.latencySetting.enabled).to.be.true expect(data.live.maxDuration).to.equal(-1) expect(data.live.maxInstanceLives).to.equal(20) expect(data.live.maxUserLives).to.equal(3) @@ -185,6 +186,7 @@ function checkUpdatedConfig (data: CustomConfig) { expect(data.live.enabled).to.be.true expect(data.live.allowReplay).to.be.true + expect(data.live.latencySetting.enabled).to.be.false expect(data.live.maxDuration).to.equal(5000) expect(data.live.maxInstanceLives).to.equal(-1) expect(data.live.maxUserLives).to.equal(10) @@ -326,6 +328,9 @@ const newCustomConfig: CustomConfig = { live: { enabled: true, allowReplay: true, + latencySetting: { + enabled: false + }, maxDuration: 5000, maxInstanceLives: -1, maxUserLives: 10, -- cgit v1.2.3