1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-06 03:50:26 +02:00

Support live session in server

This commit is contained in:
Chocobozzz 2022-05-03 11:38:07 +02:00
parent 86c5229b4d
commit 26e3e98ff0
No known key found for this signature in database
GPG key ID: 583A612D890159BE
29 changed files with 814 additions and 66 deletions

View file

@ -3,7 +3,7 @@
import 'mocha'
import * as chai from 'chai'
import { wait } from '@shared/core-utils'
import { VideoPrivacy } from '@shared/models'
import { LiveVideoError, VideoPrivacy } from '@shared/models'
import {
cleanupTests,
ConfigCommand,
@ -12,7 +12,8 @@ import {
PeerTubeServer,
setAccessTokensToServers,
setDefaultVideoChannel,
waitJobs
waitJobs,
waitUntilLiveWaitingOnAllServers
} from '@shared/server-commands'
import { checkLiveCleanup } from '../../shared'
@ -24,12 +25,18 @@ describe('Test live constraints', function () {
let userAccessToken: string
let userChannelId: number
async function createLiveWrapper (saveReplay: boolean) {
async function createLiveWrapper (options: {
replay: boolean
permanent: boolean
}) {
const { replay, permanent } = options
const liveAttributes = {
name: 'user live',
channelId: userChannelId,
privacy: VideoPrivacy.PUBLIC,
saveReplay
saveReplay: replay,
permanentLive: permanent
}
const { uuid } = await servers[0].live.create({ token: userAccessToken, fields: liveAttributes })
@ -97,23 +104,42 @@ describe('Test live constraints', function () {
it('Should not have size limit if save replay is disabled', async function () {
this.timeout(60000)
const userVideoLiveoId = await createLiveWrapper(false)
const userVideoLiveoId = await createLiveWrapper({ replay: false, permanent: false })
await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: false })
})
it('Should have size limit depending on user global quota if save replay is enabled', async function () {
it('Should have size limit depending on user global quota if save replay is enabled on non permanent live', async function () {
this.timeout(60000)
// Wait for user quota memoize cache invalidation
await wait(5000)
const userVideoLiveoId = await createLiveWrapper(true)
const userVideoLiveoId = await createLiveWrapper({ replay: true, permanent: false })
await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true })
await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
await waitJobs(servers)
await checkSaveReplay(userVideoLiveoId)
const session = await servers[0].live.getReplaySession({ videoId: userVideoLiveoId })
expect(session.error).to.equal(LiveVideoError.QUOTA_EXCEEDED)
})
it('Should have size limit depending on user global quota if save replay is enabled on a permanent live', async function () {
this.timeout(60000)
// Wait for user quota memoize cache invalidation
await wait(5000)
const userVideoLiveoId = await createLiveWrapper({ replay: true, permanent: true })
await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true })
await waitJobs(servers)
await waitUntilLiveWaitingOnAllServers(servers, userVideoLiveoId)
const session = await servers[0].live.findLatestSession({ videoId: userVideoLiveoId })
expect(session.error).to.equal(LiveVideoError.QUOTA_EXCEEDED)
})
it('Should have size limit depending on user daily quota if save replay is enabled', async function () {
@ -124,13 +150,16 @@ describe('Test live constraints', function () {
await updateQuota({ total: -1, daily: 1 })
const userVideoLiveoId = await createLiveWrapper(true)
const userVideoLiveoId = await createLiveWrapper({ replay: true, permanent: false })
await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true })
await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
await waitJobs(servers)
await checkSaveReplay(userVideoLiveoId)
const session = await servers[0].live.getReplaySession({ videoId: userVideoLiveoId })
expect(session.error).to.equal(LiveVideoError.QUOTA_EXCEEDED)
})
it('Should succeed without quota limit', async function () {
@ -141,7 +170,7 @@ describe('Test live constraints', function () {
await updateQuota({ total: 10 * 1000 * 1000, daily: -1 })
const userVideoLiveoId = await createLiveWrapper(true)
const userVideoLiveoId = await createLiveWrapper({ replay: true, permanent: false })
await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: false })
})
@ -162,13 +191,16 @@ describe('Test live constraints', function () {
}
})
const userVideoLiveoId = await createLiveWrapper(true)
const userVideoLiveoId = await createLiveWrapper({ replay: true, permanent: false })
await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true })
await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
await waitJobs(servers)
await checkSaveReplay(userVideoLiveoId, [ 720, 480, 360, 240, 144 ])
const session = await servers[0].live.getReplaySession({ videoId: userVideoLiveoId })
expect(session.error).to.equal(LiveVideoError.DURATION_EXCEEDED)
})
after(async function () {