import 'mocha'
import * as chai from 'chai'
-import { VideoPrivacy } from '@shared/models'
+import { wait } from '@shared/core-utils'
+import { LiveVideoError, VideoPrivacy } from '@shared/models'
import {
- checkLiveCleanupAfterSave,
cleanupTests,
ConfigCommand,
createMultipleServers,
PeerTubeServer,
setAccessTokensToServers,
setDefaultVideoChannel,
- wait,
- waitJobs
-} from '../../../../shared/extra-utils'
+ waitJobs,
+ waitUntilLiveReplacedByReplayOnAllServers,
+ waitUntilLiveWaitingOnAllServers
+} from '@shared/server-commands'
+import { checkLiveCleanup } from '../../shared'
const expect = chai.expect
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 })
expect(video.duration).to.be.greaterThan(0)
}
- await checkLiveCleanupAfterSave(servers[0], videoId, resolutions)
- }
-
- async function waitUntilLivePublishedOnAllServers (videoId: string) {
- for (const server of servers) {
- await server.live.waitUntilPublished({ videoId })
- }
+ await checkLiveCleanup(servers[0], videoId, resolutions)
}
function updateQuota (options: { total: number, daily: number }) {
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 waitUntilLiveReplacedByReplayOnAllServers(servers, 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 () {
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 waitUntilLiveReplacedByReplayOnAllServers(servers, 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 () {
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 })
})
}
})
- 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 waitUntilLiveReplacedByReplayOnAllServers(servers, userVideoLiveoId)
await waitJobs(servers)
- await checkSaveReplay(userVideoLiveoId, [ 720, 480, 360, 240 ])
+ 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 () {