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-12-17 04:58:15 -06:00
|
|
|
import { wait } from '@shared/core-utils'
|
2021-07-15 03:02:54 -05:00
|
|
|
import { VideoPrivacy } from '@shared/models'
|
2020-11-04 07:16:57 -06:00
|
|
|
import {
|
|
|
|
cleanupTests,
|
2021-07-07 04:51:09 -05:00
|
|
|
ConfigCommand,
|
2021-07-16 02:47:51 -05:00
|
|
|
createMultipleServers,
|
2021-07-16 07:27:30 -05:00
|
|
|
doubleFollow,
|
2021-07-16 02:47:51 -05:00
|
|
|
PeerTubeServer,
|
2020-11-04 07:16:57 -06:00
|
|
|
setAccessTokensToServers,
|
|
|
|
setDefaultVideoChannel,
|
2021-07-08 03:18:40 -05:00
|
|
|
waitJobs
|
2021-12-17 04:58:15 -06:00
|
|
|
} from '@shared/server-commands'
|
2022-04-21 02:06:52 -05:00
|
|
|
import { checkLiveCleanup } from '../../shared'
|
2020-11-04 07:16:57 -06:00
|
|
|
|
|
|
|
const expect = chai.expect
|
|
|
|
|
|
|
|
describe('Test live constraints', function () {
|
2021-07-16 02:47:51 -05:00
|
|
|
let servers: PeerTubeServer[] = []
|
2020-11-04 07:16:57 -06:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-07-16 02:04:35 -05:00
|
|
|
const { uuid } = await servers[0].live.create({ token: userAccessToken, fields: liveAttributes })
|
2021-07-08 03:18:40 -05:00
|
|
|
return uuid
|
2020-11-04 07:16:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
async function checkSaveReplay (videoId: string, resolutions = [ 720 ]) {
|
|
|
|
for (const server of servers) {
|
2021-07-16 02:04:35 -05:00
|
|
|
const video = await server.videos.get({ id: videoId })
|
2020-11-04 07:16:57 -06:00
|
|
|
expect(video.isLive).to.be.false
|
|
|
|
expect(video.duration).to.be.greaterThan(0)
|
|
|
|
}
|
|
|
|
|
2022-04-21 02:06:52 -05:00
|
|
|
await checkLiveCleanup(servers[0], videoId, resolutions)
|
2020-11-04 07:16:57 -06:00
|
|
|
}
|
|
|
|
|
2021-02-19 04:23:51 -06:00
|
|
|
async function waitUntilLivePublishedOnAllServers (videoId: string) {
|
|
|
|
for (const server of servers) {
|
2021-07-16 02:04:35 -05:00
|
|
|
await server.live.waitUntilPublished({ videoId })
|
2021-02-19 04:23:51 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-07 04:53:46 -05:00
|
|
|
function updateQuota (options: { total: number, daily: number }) {
|
2021-07-16 02:04:35 -05:00
|
|
|
return servers[0].users.update({
|
2021-05-07 04:53:46 -05:00
|
|
|
userId,
|
|
|
|
videoQuota: options.total,
|
|
|
|
videoQuotaDaily: options.daily
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-11-04 07:16:57 -06:00
|
|
|
before(async function () {
|
|
|
|
this.timeout(120000)
|
|
|
|
|
2021-07-16 02:47:51 -05:00
|
|
|
servers = await createMultipleServers(2)
|
2020-11-04 07:16:57 -06:00
|
|
|
|
|
|
|
// Get the access tokens
|
|
|
|
await setAccessTokensToServers(servers)
|
|
|
|
await setDefaultVideoChannel(servers)
|
|
|
|
|
2021-07-16 02:04:35 -05:00
|
|
|
await servers[0].config.updateCustomSubConfig({
|
2021-07-07 04:51:09 -05:00
|
|
|
newConfig: {
|
|
|
|
live: {
|
|
|
|
enabled: true,
|
|
|
|
allowReplay: true,
|
|
|
|
transcoding: {
|
|
|
|
enabled: false
|
|
|
|
}
|
2020-11-04 07:16:57 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
{
|
2021-07-16 02:04:35 -05:00
|
|
|
const res = await servers[0].users.generate('user1')
|
2021-05-07 04:53:46 -05:00
|
|
|
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)
|
2021-07-16 02:04:35 -05:00
|
|
|
await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: false })
|
2020-11-04 07:16:57 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
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)
|
2021-07-16 02:04:35 -05:00
|
|
|
await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true })
|
2020-11-04 07:16:57 -06:00
|
|
|
|
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)
|
2021-07-16 02:04:35 -05:00
|
|
|
await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true })
|
2020-11-04 07:16:57 -06:00
|
|
|
|
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)
|
2021-07-16 02:04:35 -05:00
|
|
|
await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: false })
|
2020-11-04 07:16:57 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
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
|
|
|
|
2021-07-16 02:04:35 -05:00
|
|
|
await servers[0].config.updateCustomSubConfig({
|
2021-07-07 04:51:09 -05:00
|
|
|
newConfig: {
|
|
|
|
live: {
|
2020-11-04 07:16:57 -06:00
|
|
|
enabled: true,
|
2021-07-07 04:51:09 -05:00
|
|
|
allowReplay: true,
|
|
|
|
maxDuration: 1,
|
|
|
|
transcoding: {
|
|
|
|
enabled: true,
|
|
|
|
resolutions: ConfigCommand.getCustomConfigResolutions(true)
|
|
|
|
}
|
2020-11-04 07:16:57 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
const userVideoLiveoId = await createLiveWrapper(true)
|
2021-07-16 02:04:35 -05:00
|
|
|
await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true })
|
2020-11-04 07:16:57 -06:00
|
|
|
|
2021-02-19 04:23:51 -06:00
|
|
|
await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
|
2020-11-04 07:16:57 -06:00
|
|
|
await waitJobs(servers)
|
|
|
|
|
2021-11-05 04:23:02 -05:00
|
|
|
await checkSaveReplay(userVideoLiveoId, [ 720, 480, 360, 240, 144 ])
|
2020-11-04 07:16:57 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
after(async function () {
|
|
|
|
await cleanupTests(servers)
|
|
|
|
})
|
|
|
|
})
|