aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/live/live-constraints.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/live/live-constraints.ts')
-rw-r--r--server/tests/api/live/live-constraints.ts77
1 files changed, 35 insertions, 42 deletions
diff --git a/server/tests/api/live/live-constraints.ts b/server/tests/api/live/live-constraints.ts
index cc635de33..20346113d 100644
--- a/server/tests/api/live/live-constraints.ts
+++ b/server/tests/api/live/live-constraints.ts
@@ -2,31 +2,24 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { VideoDetails, VideoPrivacy } from '@shared/models' 5import { VideoPrivacy } from '@shared/models'
6import { 6import {
7 checkLiveCleanup, 7 checkLiveCleanup,
8 cleanupTests, 8 cleanupTests,
9 createLive, 9 ConfigCommand,
10 createMultipleServers,
10 doubleFollow, 11 doubleFollow,
11 flushAndRunMultipleServers, 12 PeerTubeServer,
12 generateUser,
13 getCustomConfigResolutions,
14 getVideo,
15 runAndTestFfmpegStreamError,
16 ServerInfo,
17 setAccessTokensToServers, 13 setAccessTokensToServers,
18 setDefaultVideoChannel, 14 setDefaultVideoChannel,
19 updateCustomSubConfig,
20 updateUser,
21 wait, 15 wait,
22 waitJobs, 16 waitJobs
23 waitUntilLivePublished
24} from '../../../../shared/extra-utils' 17} from '../../../../shared/extra-utils'
25 18
26const expect = chai.expect 19const expect = chai.expect
27 20
28describe('Test live constraints', function () { 21describe('Test live constraints', function () {
29 let servers: ServerInfo[] = [] 22 let servers: PeerTubeServer[] = []
30 let userId: number 23 let userId: number
31 let userAccessToken: string 24 let userAccessToken: string
32 let userChannelId: number 25 let userChannelId: number
@@ -39,15 +32,13 @@ describe('Test live constraints', function () {
39 saveReplay 32 saveReplay
40 } 33 }
41 34
42 const res = await createLive(servers[0].url, userAccessToken, liveAttributes) 35 const { uuid } = await servers[0].live.create({ token: userAccessToken, fields: liveAttributes })
43 return res.body.video.uuid as string 36 return uuid
44 } 37 }
45 38
46 async function checkSaveReplay (videoId: string, resolutions = [ 720 ]) { 39 async function checkSaveReplay (videoId: string, resolutions = [ 720 ]) {
47 for (const server of servers) { 40 for (const server of servers) {
48 const res = await getVideo(server.url, videoId) 41 const video = await server.videos.get({ id: videoId })
49
50 const video: VideoDetails = res.body
51 expect(video.isLive).to.be.false 42 expect(video.isLive).to.be.false
52 expect(video.duration).to.be.greaterThan(0) 43 expect(video.duration).to.be.greaterThan(0)
53 } 44 }
@@ -57,14 +48,12 @@ describe('Test live constraints', function () {
57 48
58 async function waitUntilLivePublishedOnAllServers (videoId: string) { 49 async function waitUntilLivePublishedOnAllServers (videoId: string) {
59 for (const server of servers) { 50 for (const server of servers) {
60 await waitUntilLivePublished(server.url, server.accessToken, videoId) 51 await server.live.waitUntilPublished({ videoId })
61 } 52 }
62 } 53 }
63 54
64 function updateQuota (options: { total: number, daily: number }) { 55 function updateQuota (options: { total: number, daily: number }) {
65 return updateUser({ 56 return servers[0].users.update({
66 url: servers[0].url,
67 accessToken: servers[0].accessToken,
68 userId, 57 userId,
69 videoQuota: options.total, 58 videoQuota: options.total,
70 videoQuotaDaily: options.daily 59 videoQuotaDaily: options.daily
@@ -74,24 +63,26 @@ describe('Test live constraints', function () {
74 before(async function () { 63 before(async function () {
75 this.timeout(120000) 64 this.timeout(120000)
76 65
77 servers = await flushAndRunMultipleServers(2) 66 servers = await createMultipleServers(2)
78 67
79 // Get the access tokens 68 // Get the access tokens
80 await setAccessTokensToServers(servers) 69 await setAccessTokensToServers(servers)
81 await setDefaultVideoChannel(servers) 70 await setDefaultVideoChannel(servers)
82 71
83 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { 72 await servers[0].config.updateCustomSubConfig({
84 live: { 73 newConfig: {
85 enabled: true, 74 live: {
86 allowReplay: true, 75 enabled: true,
87 transcoding: { 76 allowReplay: true,
88 enabled: false 77 transcoding: {
78 enabled: false
79 }
89 } 80 }
90 } 81 }
91 }) 82 })
92 83
93 { 84 {
94 const res = await generateUser(servers[0], 'user1') 85 const res = await servers[0].users.generate('user1')
95 userId = res.userId 86 userId = res.userId
96 userChannelId = res.userChannelId 87 userChannelId = res.userChannelId
97 userAccessToken = res.token 88 userAccessToken = res.token
@@ -107,7 +98,7 @@ describe('Test live constraints', function () {
107 this.timeout(60000) 98 this.timeout(60000)
108 99
109 const userVideoLiveoId = await createLiveWrapper(false) 100 const userVideoLiveoId = await createLiveWrapper(false)
110 await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, false) 101 await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: false })
111 }) 102 })
112 103
113 it('Should have size limit depending on user global quota if save replay is enabled', async function () { 104 it('Should have size limit depending on user global quota if save replay is enabled', async function () {
@@ -117,7 +108,7 @@ describe('Test live constraints', function () {
117 await wait(5000) 108 await wait(5000)
118 109
119 const userVideoLiveoId = await createLiveWrapper(true) 110 const userVideoLiveoId = await createLiveWrapper(true)
120 await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true) 111 await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true })
121 112
122 await waitUntilLivePublishedOnAllServers(userVideoLiveoId) 113 await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
123 await waitJobs(servers) 114 await waitJobs(servers)
@@ -134,7 +125,7 @@ describe('Test live constraints', function () {
134 await updateQuota({ total: -1, daily: 1 }) 125 await updateQuota({ total: -1, daily: 1 })
135 126
136 const userVideoLiveoId = await createLiveWrapper(true) 127 const userVideoLiveoId = await createLiveWrapper(true)
137 await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true) 128 await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true })
138 129
139 await waitUntilLivePublishedOnAllServers(userVideoLiveoId) 130 await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
140 await waitJobs(servers) 131 await waitJobs(servers)
@@ -151,26 +142,28 @@ describe('Test live constraints', function () {
151 await updateQuota({ total: 10 * 1000 * 1000, daily: -1 }) 142 await updateQuota({ total: 10 * 1000 * 1000, daily: -1 })
152 143
153 const userVideoLiveoId = await createLiveWrapper(true) 144 const userVideoLiveoId = await createLiveWrapper(true)
154 await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, false) 145 await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: false })
155 }) 146 })
156 147
157 it('Should have max duration limit', async function () { 148 it('Should have max duration limit', async function () {
158 this.timeout(60000) 149 this.timeout(60000)
159 150
160 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { 151 await servers[0].config.updateCustomSubConfig({
161 live: { 152 newConfig: {
162 enabled: true, 153 live: {
163 allowReplay: true,
164 maxDuration: 1,
165 transcoding: {
166 enabled: true, 154 enabled: true,
167 resolutions: getCustomConfigResolutions(true) 155 allowReplay: true,
156 maxDuration: 1,
157 transcoding: {
158 enabled: true,
159 resolutions: ConfigCommand.getCustomConfigResolutions(true)
160 }
168 } 161 }
169 } 162 }
170 }) 163 })
171 164
172 const userVideoLiveoId = await createLiveWrapper(true) 165 const userVideoLiveoId = await createLiveWrapper(true)
173 await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true) 166 await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true })
174 167
175 await waitUntilLivePublishedOnAllServers(userVideoLiveoId) 168 await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
176 await waitJobs(servers) 169 await waitJobs(servers)