aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/live/live-constraints.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-05-03 11:38:07 +0200
committerChocobozzz <me@florianbigard.com>2022-05-03 14:49:15 +0200
commit26e3e98ff0e222a9fb9226938ac6902af77921bd (patch)
tree73d1c6f2524e380862d3365f12043fc319d40841 /server/tests/api/live/live-constraints.ts
parent86c5229b4d726202378ef46854383bcafca22310 (diff)
downloadPeerTube-26e3e98ff0e222a9fb9226938ac6902af77921bd.tar.gz
PeerTube-26e3e98ff0e222a9fb9226938ac6902af77921bd.tar.zst
PeerTube-26e3e98ff0e222a9fb9226938ac6902af77921bd.zip
Support live session in server
Diffstat (limited to 'server/tests/api/live/live-constraints.ts')
-rw-r--r--server/tests/api/live/live-constraints.ts52
1 files changed, 42 insertions, 10 deletions
diff --git a/server/tests/api/live/live-constraints.ts b/server/tests/api/live/live-constraints.ts
index b92dc7b89..b81973395 100644
--- a/server/tests/api/live/live-constraints.ts
+++ b/server/tests/api/live/live-constraints.ts
@@ -3,7 +3,7 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { wait } from '@shared/core-utils' 5import { wait } from '@shared/core-utils'
6import { VideoPrivacy } from '@shared/models' 6import { LiveVideoError, VideoPrivacy } from '@shared/models'
7import { 7import {
8 cleanupTests, 8 cleanupTests,
9 ConfigCommand, 9 ConfigCommand,
@@ -12,7 +12,8 @@ import {
12 PeerTubeServer, 12 PeerTubeServer,
13 setAccessTokensToServers, 13 setAccessTokensToServers,
14 setDefaultVideoChannel, 14 setDefaultVideoChannel,
15 waitJobs 15 waitJobs,
16 waitUntilLiveWaitingOnAllServers
16} from '@shared/server-commands' 17} from '@shared/server-commands'
17import { checkLiveCleanup } from '../../shared' 18import { checkLiveCleanup } from '../../shared'
18 19
@@ -24,12 +25,18 @@ describe('Test live constraints', function () {
24 let userAccessToken: string 25 let userAccessToken: string
25 let userChannelId: number 26 let userChannelId: number
26 27
27 async function createLiveWrapper (saveReplay: boolean) { 28 async function createLiveWrapper (options: {
29 replay: boolean
30 permanent: boolean
31 }) {
32 const { replay, permanent } = options
33
28 const liveAttributes = { 34 const liveAttributes = {
29 name: 'user live', 35 name: 'user live',
30 channelId: userChannelId, 36 channelId: userChannelId,
31 privacy: VideoPrivacy.PUBLIC, 37 privacy: VideoPrivacy.PUBLIC,
32 saveReplay 38 saveReplay: replay,
39 permanentLive: permanent
33 } 40 }
34 41
35 const { uuid } = await servers[0].live.create({ token: userAccessToken, fields: liveAttributes }) 42 const { uuid } = await servers[0].live.create({ token: userAccessToken, fields: liveAttributes })
@@ -97,23 +104,42 @@ describe('Test live constraints', function () {
97 it('Should not have size limit if save replay is disabled', async function () { 104 it('Should not have size limit if save replay is disabled', async function () {
98 this.timeout(60000) 105 this.timeout(60000)
99 106
100 const userVideoLiveoId = await createLiveWrapper(false) 107 const userVideoLiveoId = await createLiveWrapper({ replay: false, permanent: false })
101 await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: false }) 108 await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: false })
102 }) 109 })
103 110
104 it('Should have size limit depending on user global quota if save replay is enabled', async function () { 111 it('Should have size limit depending on user global quota if save replay is enabled on non permanent live', async function () {
105 this.timeout(60000) 112 this.timeout(60000)
106 113
107 // Wait for user quota memoize cache invalidation 114 // Wait for user quota memoize cache invalidation
108 await wait(5000) 115 await wait(5000)
109 116
110 const userVideoLiveoId = await createLiveWrapper(true) 117 const userVideoLiveoId = await createLiveWrapper({ replay: true, permanent: false })
111 await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true }) 118 await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true })
112 119
113 await waitUntilLivePublishedOnAllServers(userVideoLiveoId) 120 await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
114 await waitJobs(servers) 121 await waitJobs(servers)
115 122
116 await checkSaveReplay(userVideoLiveoId) 123 await checkSaveReplay(userVideoLiveoId)
124
125 const session = await servers[0].live.getReplaySession({ videoId: userVideoLiveoId })
126 expect(session.error).to.equal(LiveVideoError.QUOTA_EXCEEDED)
127 })
128
129 it('Should have size limit depending on user global quota if save replay is enabled on a permanent live', async function () {
130 this.timeout(60000)
131
132 // Wait for user quota memoize cache invalidation
133 await wait(5000)
134
135 const userVideoLiveoId = await createLiveWrapper({ replay: true, permanent: true })
136 await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true })
137
138 await waitJobs(servers)
139 await waitUntilLiveWaitingOnAllServers(servers, userVideoLiveoId)
140
141 const session = await servers[0].live.findLatestSession({ videoId: userVideoLiveoId })
142 expect(session.error).to.equal(LiveVideoError.QUOTA_EXCEEDED)
117 }) 143 })
118 144
119 it('Should have size limit depending on user daily quota if save replay is enabled', async function () { 145 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 () {
124 150
125 await updateQuota({ total: -1, daily: 1 }) 151 await updateQuota({ total: -1, daily: 1 })
126 152
127 const userVideoLiveoId = await createLiveWrapper(true) 153 const userVideoLiveoId = await createLiveWrapper({ replay: true, permanent: false })
128 await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true }) 154 await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true })
129 155
130 await waitUntilLivePublishedOnAllServers(userVideoLiveoId) 156 await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
131 await waitJobs(servers) 157 await waitJobs(servers)
132 158
133 await checkSaveReplay(userVideoLiveoId) 159 await checkSaveReplay(userVideoLiveoId)
160
161 const session = await servers[0].live.getReplaySession({ videoId: userVideoLiveoId })
162 expect(session.error).to.equal(LiveVideoError.QUOTA_EXCEEDED)
134 }) 163 })
135 164
136 it('Should succeed without quota limit', async function () { 165 it('Should succeed without quota limit', async function () {
@@ -141,7 +170,7 @@ describe('Test live constraints', function () {
141 170
142 await updateQuota({ total: 10 * 1000 * 1000, daily: -1 }) 171 await updateQuota({ total: 10 * 1000 * 1000, daily: -1 })
143 172
144 const userVideoLiveoId = await createLiveWrapper(true) 173 const userVideoLiveoId = await createLiveWrapper({ replay: true, permanent: false })
145 await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: false }) 174 await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: false })
146 }) 175 })
147 176
@@ -162,13 +191,16 @@ describe('Test live constraints', function () {
162 } 191 }
163 }) 192 })
164 193
165 const userVideoLiveoId = await createLiveWrapper(true) 194 const userVideoLiveoId = await createLiveWrapper({ replay: true, permanent: false })
166 await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true }) 195 await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true })
167 196
168 await waitUntilLivePublishedOnAllServers(userVideoLiveoId) 197 await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
169 await waitJobs(servers) 198 await waitJobs(servers)
170 199
171 await checkSaveReplay(userVideoLiveoId, [ 720, 480, 360, 240, 144 ]) 200 await checkSaveReplay(userVideoLiveoId, [ 720, 480, 360, 240, 144 ])
201
202 const session = await servers[0].live.getReplaySession({ videoId: userVideoLiveoId })
203 expect(session.error).to.equal(LiveVideoError.DURATION_EXCEEDED)
172 }) 204 })
173 205
174 after(async function () { 206 after(async function () {