]>
Commit | Line | Data |
---|---|---|
68e70a74 C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
d23dd9fb | 5 | import { VideoPrivacy } from '@shared/models' |
68e70a74 | 6 | import { |
764b1a14 | 7 | checkLiveCleanupAfterSave, |
68e70a74 | 8 | cleanupTests, |
65e6e260 | 9 | ConfigCommand, |
254d3579 | 10 | createMultipleServers, |
4c7e60bc | 11 | doubleFollow, |
254d3579 | 12 | PeerTubeServer, |
68e70a74 C |
13 | setAccessTokensToServers, |
14 | setDefaultVideoChannel, | |
68e70a74 | 15 | wait, |
4f219914 | 16 | waitJobs |
68e70a74 C |
17 | } from '../../../../shared/extra-utils' |
18 | ||
19 | const expect = chai.expect | |
20 | ||
21 | describe('Test live constraints', function () { | |
254d3579 | 22 | let servers: PeerTubeServer[] = [] |
68e70a74 C |
23 | let userId: number |
24 | let userAccessToken: string | |
25 | let userChannelId: number | |
26 | ||
27 | async function createLiveWrapper (saveReplay: boolean) { | |
28 | const liveAttributes = { | |
29 | name: 'user live', | |
30 | channelId: userChannelId, | |
31 | privacy: VideoPrivacy.PUBLIC, | |
32 | saveReplay | |
33 | } | |
34 | ||
89d241a7 | 35 | const { uuid } = await servers[0].live.create({ token: userAccessToken, fields: liveAttributes }) |
4f219914 | 36 | return uuid |
68e70a74 C |
37 | } |
38 | ||
39 | async function checkSaveReplay (videoId: string, resolutions = [ 720 ]) { | |
40 | for (const server of servers) { | |
89d241a7 | 41 | const video = await server.videos.get({ id: videoId }) |
68e70a74 C |
42 | expect(video.isLive).to.be.false |
43 | expect(video.duration).to.be.greaterThan(0) | |
44 | } | |
45 | ||
764b1a14 | 46 | await checkLiveCleanupAfterSave(servers[0], videoId, resolutions) |
68e70a74 C |
47 | } |
48 | ||
300cb723 C |
49 | async function waitUntilLivePublishedOnAllServers (videoId: string) { |
50 | for (const server of servers) { | |
89d241a7 | 51 | await server.live.waitUntilPublished({ videoId }) |
300cb723 C |
52 | } |
53 | } | |
54 | ||
a1bb73f9 | 55 | function updateQuota (options: { total: number, daily: number }) { |
89d241a7 | 56 | return servers[0].users.update({ |
a1bb73f9 C |
57 | userId, |
58 | videoQuota: options.total, | |
59 | videoQuotaDaily: options.daily | |
60 | }) | |
61 | } | |
62 | ||
68e70a74 C |
63 | before(async function () { |
64 | this.timeout(120000) | |
65 | ||
254d3579 | 66 | servers = await createMultipleServers(2) |
68e70a74 C |
67 | |
68 | // Get the access tokens | |
69 | await setAccessTokensToServers(servers) | |
70 | await setDefaultVideoChannel(servers) | |
71 | ||
89d241a7 | 72 | await servers[0].config.updateCustomSubConfig({ |
65e6e260 C |
73 | newConfig: { |
74 | live: { | |
75 | enabled: true, | |
76 | allowReplay: true, | |
77 | transcoding: { | |
78 | enabled: false | |
79 | } | |
68e70a74 C |
80 | } |
81 | } | |
82 | }) | |
83 | ||
84 | { | |
89d241a7 | 85 | const res = await servers[0].users.generate('user1') |
a1bb73f9 C |
86 | userId = res.userId |
87 | userChannelId = res.userChannelId | |
88 | userAccessToken = res.token | |
89 | ||
90 | await updateQuota({ total: 1, daily: -1 }) | |
68e70a74 C |
91 | } |
92 | ||
93 | // Server 1 and server 2 follow each other | |
94 | await doubleFollow(servers[0], servers[1]) | |
95 | }) | |
96 | ||
97 | it('Should not have size limit if save replay is disabled', async function () { | |
98 | this.timeout(60000) | |
99 | ||
100 | const userVideoLiveoId = await createLiveWrapper(false) | |
89d241a7 | 101 | await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: false }) |
68e70a74 C |
102 | }) |
103 | ||
104 | it('Should have size limit depending on user global quota if save replay is enabled', async function () { | |
105 | this.timeout(60000) | |
106 | ||
107 | // Wait for user quota memoize cache invalidation | |
108 | await wait(5000) | |
109 | ||
110 | const userVideoLiveoId = await createLiveWrapper(true) | |
89d241a7 | 111 | await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true }) |
68e70a74 | 112 | |
300cb723 | 113 | await waitUntilLivePublishedOnAllServers(userVideoLiveoId) |
68e70a74 C |
114 | await waitJobs(servers) |
115 | ||
116 | await checkSaveReplay(userVideoLiveoId) | |
117 | }) | |
118 | ||
119 | it('Should have size limit depending on user daily quota if save replay is enabled', async function () { | |
120 | this.timeout(60000) | |
121 | ||
122 | // Wait for user quota memoize cache invalidation | |
123 | await wait(5000) | |
124 | ||
a1bb73f9 | 125 | await updateQuota({ total: -1, daily: 1 }) |
68e70a74 C |
126 | |
127 | const userVideoLiveoId = await createLiveWrapper(true) | |
89d241a7 | 128 | await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true }) |
68e70a74 | 129 | |
300cb723 | 130 | await waitUntilLivePublishedOnAllServers(userVideoLiveoId) |
68e70a74 C |
131 | await waitJobs(servers) |
132 | ||
133 | await checkSaveReplay(userVideoLiveoId) | |
134 | }) | |
135 | ||
136 | it('Should succeed without quota limit', async function () { | |
137 | this.timeout(60000) | |
138 | ||
139 | // Wait for user quota memoize cache invalidation | |
140 | await wait(5000) | |
141 | ||
a1bb73f9 | 142 | await updateQuota({ total: 10 * 1000 * 1000, daily: -1 }) |
68e70a74 C |
143 | |
144 | const userVideoLiveoId = await createLiveWrapper(true) | |
89d241a7 | 145 | await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: false }) |
68e70a74 C |
146 | }) |
147 | ||
148 | it('Should have max duration limit', async function () { | |
ffc12d3a | 149 | this.timeout(60000) |
68e70a74 | 150 | |
89d241a7 | 151 | await servers[0].config.updateCustomSubConfig({ |
65e6e260 C |
152 | newConfig: { |
153 | live: { | |
68e70a74 | 154 | enabled: true, |
65e6e260 C |
155 | allowReplay: true, |
156 | maxDuration: 1, | |
157 | transcoding: { | |
158 | enabled: true, | |
159 | resolutions: ConfigCommand.getCustomConfigResolutions(true) | |
160 | } | |
68e70a74 C |
161 | } |
162 | } | |
163 | }) | |
164 | ||
165 | const userVideoLiveoId = await createLiveWrapper(true) | |
89d241a7 | 166 | await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true }) |
68e70a74 | 167 | |
300cb723 | 168 | await waitUntilLivePublishedOnAllServers(userVideoLiveoId) |
68e70a74 C |
169 | await waitJobs(servers) |
170 | ||
8dd754c7 | 171 | await checkSaveReplay(userVideoLiveoId, [ 720, 480, 360, 240, 144 ]) |
68e70a74 C |
172 | }) |
173 | ||
174 | after(async function () { | |
175 | await cleanupTests(servers) | |
176 | }) | |
177 | }) |