aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/live/live-constraints.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-11-04 14:16:57 +0100
committerChocobozzz <chocobozzz@cpy.re>2020-11-09 15:33:04 +0100
commit68e70a745b2010cd0199864a2addd60d8f99c732 (patch)
treea0b1b061d205321e0f6eb80e5b44d7afd06aab14 /server/tests/api/live/live-constraints.ts
parent97969c4edf51b37eee691adba43368bb0fbb729b (diff)
downloadPeerTube-68e70a745b2010cd0199864a2addd60d8f99c732.tar.gz
PeerTube-68e70a745b2010cd0199864a2addd60d8f99c732.tar.zst
PeerTube-68e70a745b2010cd0199864a2addd60d8f99c732.zip
Add save replay live tests
Diffstat (limited to 'server/tests/api/live/live-constraints.ts')
-rw-r--r--server/tests/api/live/live-constraints.ts199
1 files changed, 199 insertions, 0 deletions
diff --git a/server/tests/api/live/live-constraints.ts b/server/tests/api/live/live-constraints.ts
new file mode 100644
index 000000000..23c8e3b0a
--- /dev/null
+++ b/server/tests/api/live/live-constraints.ts
@@ -0,0 +1,199 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
5import { User, VideoDetails, VideoPrivacy } from '@shared/models'
6import {
7 checkLiveCleanup,
8 cleanupTests,
9 createLive,
10 createUser,
11 doubleFollow,
12 flushAndRunMultipleServers,
13 getMyUserInformation,
14 getVideo,
15 runAndTestFfmpegStreamError,
16 ServerInfo,
17 setAccessTokensToServers,
18 setDefaultVideoChannel,
19 updateCustomSubConfig,
20 updateUser,
21 userLogin,
22 wait,
23 waitJobs
24} from '../../../../shared/extra-utils'
25
26const expect = chai.expect
27
28describe('Test live constraints', function () {
29 let servers: ServerInfo[] = []
30 let userId: number
31 let userAccessToken: string
32 let userChannelId: number
33
34 async function createLiveWrapper (saveReplay: boolean) {
35 const liveAttributes = {
36 name: 'user live',
37 channelId: userChannelId,
38 privacy: VideoPrivacy.PUBLIC,
39 saveReplay
40 }
41
42 const res = await createLive(servers[0].url, userAccessToken, liveAttributes)
43 return res.body.video.uuid as string
44 }
45
46 async function checkSaveReplay (videoId: string, resolutions = [ 720 ]) {
47 for (const server of servers) {
48 const res = await getVideo(server.url, videoId)
49
50 const video: VideoDetails = res.body
51 expect(video.isLive).to.be.false
52 expect(video.duration).to.be.greaterThan(0)
53 }
54
55 await checkLiveCleanup(servers[0], videoId, resolutions)
56 }
57
58 before(async function () {
59 this.timeout(120000)
60
61 servers = await flushAndRunMultipleServers(2)
62
63 // Get the access tokens
64 await setAccessTokensToServers(servers)
65 await setDefaultVideoChannel(servers)
66
67 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
68 live: {
69 enabled: true,
70 allowReplay: true,
71 transcoding: {
72 enabled: false
73 }
74 }
75 })
76
77 {
78 const user = { username: 'user1', password: 'superpassword' }
79 const res = await createUser({
80 url: servers[0].url,
81 accessToken: servers[0].accessToken,
82 username: user.username,
83 password: user.password
84 })
85 userId = res.body.user.id
86
87 userAccessToken = await userLogin(servers[0], user)
88
89 const resMe = await getMyUserInformation(servers[0].url, userAccessToken)
90 userChannelId = (resMe.body as User).videoChannels[0].id
91
92 await updateUser({
93 url: servers[0].url,
94 userId,
95 accessToken: servers[0].accessToken,
96 videoQuota: 1,
97 videoQuotaDaily: -1
98 })
99 }
100
101 // Server 1 and server 2 follow each other
102 await doubleFollow(servers[0], servers[1])
103 })
104
105 it('Should not have size limit if save replay is disabled', async function () {
106 this.timeout(60000)
107
108 const userVideoLiveoId = await createLiveWrapper(false)
109 await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, false)
110 })
111
112 it('Should have size limit depending on user global quota if save replay is enabled', async function () {
113 this.timeout(60000)
114
115 // Wait for user quota memoize cache invalidation
116 await wait(5000)
117
118 const userVideoLiveoId = await createLiveWrapper(true)
119 await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true)
120
121 await waitJobs(servers)
122
123 await checkSaveReplay(userVideoLiveoId)
124 })
125
126 it('Should have size limit depending on user daily quota if save replay is enabled', async function () {
127 this.timeout(60000)
128
129 // Wait for user quota memoize cache invalidation
130 await wait(5000)
131
132 await updateUser({
133 url: servers[0].url,
134 userId,
135 accessToken: servers[0].accessToken,
136 videoQuota: -1,
137 videoQuotaDaily: 1
138 })
139
140 const userVideoLiveoId = await createLiveWrapper(true)
141 await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true)
142
143 await waitJobs(servers)
144
145 await checkSaveReplay(userVideoLiveoId)
146 })
147
148 it('Should succeed without quota limit', async function () {
149 this.timeout(60000)
150
151 // Wait for user quota memoize cache invalidation
152 await wait(5000)
153
154 await updateUser({
155 url: servers[0].url,
156 userId,
157 accessToken: servers[0].accessToken,
158 videoQuota: 10 * 1000 * 1000,
159 videoQuotaDaily: -1
160 })
161
162 const userVideoLiveoId = await createLiveWrapper(true)
163 await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, false)
164 })
165
166 it('Should have max duration limit', async function () {
167 this.timeout(30000)
168
169 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
170 live: {
171 enabled: true,
172 allowReplay: true,
173 maxDuration: 1,
174 transcoding: {
175 enabled: true,
176 resolutions: {
177 '240p': true,
178 '360p': true,
179 '480p': true,
180 '720p': true,
181 '1080p': true,
182 '2160p': true
183 }
184 }
185 }
186 })
187
188 const userVideoLiveoId = await createLiveWrapper(true)
189 await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true)
190
191 await waitJobs(servers)
192
193 await checkSaveReplay(userVideoLiveoId, [ 720, 480, 360, 240 ])
194 })
195
196 after(async function () {
197 await cleanupTests(servers)
198 })
199})