PeerTube/server/tests/api/live/live-constraints.ts

185 lines
5.0 KiB
TypeScript
Raw Normal View History

2020-11-04 07:16:57 -06:00
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha'
import * as chai from 'chai'
2021-05-07 04:53:46 -05:00
import { VideoDetails, VideoPrivacy } from '@shared/models'
2020-11-04 07:16:57 -06:00
import {
checkLiveCleanup,
cleanupTests,
createLive,
doubleFollow,
flushAndRunMultipleServers,
2021-05-07 04:53:46 -05:00
generateUser,
getCustomConfigResolutions,
2020-11-04 07:16:57 -06:00
getVideo,
runAndTestFfmpegStreamError,
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
updateCustomSubConfig,
updateUser,
wait,
2021-02-19 04:23:51 -06:00
waitJobs,
waitUntilLivePublished
2020-11-04 07:16:57 -06:00
} from '../../../../shared/extra-utils'
const expect = chai.expect
describe('Test live constraints', function () {
let servers: ServerInfo[] = []
let userId: number
let userAccessToken: string
let userChannelId: number
async function createLiveWrapper (saveReplay: boolean) {
const liveAttributes = {
name: 'user live',
channelId: userChannelId,
privacy: VideoPrivacy.PUBLIC,
saveReplay
}
const res = await createLive(servers[0].url, userAccessToken, liveAttributes)
return res.body.video.uuid as string
}
async function checkSaveReplay (videoId: string, resolutions = [ 720 ]) {
for (const server of servers) {
const res = await getVideo(server.url, videoId)
const video: VideoDetails = res.body
expect(video.isLive).to.be.false
expect(video.duration).to.be.greaterThan(0)
}
await checkLiveCleanup(servers[0], videoId, resolutions)
}
2021-02-19 04:23:51 -06:00
async function waitUntilLivePublishedOnAllServers (videoId: string) {
for (const server of servers) {
await waitUntilLivePublished(server.url, server.accessToken, videoId)
}
}
2021-05-07 04:53:46 -05:00
function updateQuota (options: { total: number, daily: number }) {
return updateUser({
url: servers[0].url,
accessToken: servers[0].accessToken,
userId,
videoQuota: options.total,
videoQuotaDaily: options.daily
})
}
2020-11-04 07:16:57 -06:00
before(async function () {
this.timeout(120000)
servers = await flushAndRunMultipleServers(2)
// Get the access tokens
await setAccessTokensToServers(servers)
await setDefaultVideoChannel(servers)
await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
live: {
enabled: true,
allowReplay: true,
transcoding: {
enabled: false
}
}
})
{
2021-05-07 04:53:46 -05:00
const res = await generateUser(servers[0], 'user1')
userId = res.userId
userChannelId = res.userChannelId
userAccessToken = res.token
await updateQuota({ total: 1, daily: -1 })
2020-11-04 07:16:57 -06:00
}
// Server 1 and server 2 follow each other
await doubleFollow(servers[0], servers[1])
})
it('Should not have size limit if save replay is disabled', async function () {
this.timeout(60000)
const userVideoLiveoId = await createLiveWrapper(false)
await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, false)
})
it('Should have size limit depending on user global quota if save replay is enabled', async function () {
this.timeout(60000)
// Wait for user quota memoize cache invalidation
await wait(5000)
const userVideoLiveoId = await createLiveWrapper(true)
await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true)
2021-02-19 04:23:51 -06:00
await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
2020-11-04 07:16:57 -06:00
await waitJobs(servers)
await checkSaveReplay(userVideoLiveoId)
})
it('Should have size limit depending on user daily quota if save replay is enabled', async function () {
this.timeout(60000)
// Wait for user quota memoize cache invalidation
await wait(5000)
2021-05-07 04:53:46 -05:00
await updateQuota({ total: -1, daily: 1 })
2020-11-04 07:16:57 -06:00
const userVideoLiveoId = await createLiveWrapper(true)
await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true)
2021-02-19 04:23:51 -06:00
await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
2020-11-04 07:16:57 -06:00
await waitJobs(servers)
await checkSaveReplay(userVideoLiveoId)
})
it('Should succeed without quota limit', async function () {
this.timeout(60000)
// Wait for user quota memoize cache invalidation
await wait(5000)
2021-05-07 04:53:46 -05:00
await updateQuota({ total: 10 * 1000 * 1000, daily: -1 })
2020-11-04 07:16:57 -06:00
const userVideoLiveoId = await createLiveWrapper(true)
await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, false)
})
it('Should have max duration limit', async function () {
2020-12-02 09:58:45 -06:00
this.timeout(60000)
2020-11-04 07:16:57 -06:00
await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
live: {
enabled: true,
allowReplay: true,
maxDuration: 1,
transcoding: {
enabled: true,
2021-05-07 04:53:46 -05:00
resolutions: getCustomConfigResolutions(true)
2020-11-04 07:16:57 -06:00
}
}
})
const userVideoLiveoId = await createLiveWrapper(true)
await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true)
2021-02-19 04:23:51 -06:00
await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
2020-11-04 07:16:57 -06:00
await waitJobs(servers)
await checkSaveReplay(userVideoLiveoId, [ 720, 480, 360, 240 ])
})
after(async function () {
await cleanupTests(servers)
})
})