diff options
author | Chocobozzz <me@florianbigard.com> | 2022-05-03 11:38:07 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-05-03 14:49:15 +0200 |
commit | 26e3e98ff0e222a9fb9226938ac6902af77921bd (patch) | |
tree | 73d1c6f2524e380862d3365f12043fc319d40841 /server/tests/api/live | |
parent | 86c5229b4d726202378ef46854383bcafca22310 (diff) | |
download | PeerTube-26e3e98ff0e222a9fb9226938ac6902af77921bd.tar.gz PeerTube-26e3e98ff0e222a9fb9226938ac6902af77921bd.tar.zst PeerTube-26e3e98ff0e222a9fb9226938ac6902af77921bd.zip |
Support live session in server
Diffstat (limited to 'server/tests/api/live')
-rw-r--r-- | server/tests/api/live/live-constraints.ts | 52 | ||||
-rw-r--r-- | server/tests/api/live/live-permanent.ts | 17 | ||||
-rw-r--r-- | server/tests/api/live/live-save-replay.ts | 72 | ||||
-rw-r--r-- | server/tests/api/live/live.ts | 8 |
4 files changed, 138 insertions, 11 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 @@ | |||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { wait } from '@shared/core-utils' | 5 | import { wait } from '@shared/core-utils' |
6 | import { VideoPrivacy } from '@shared/models' | 6 | import { LiveVideoError, VideoPrivacy } from '@shared/models' |
7 | import { | 7 | import { |
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' |
17 | import { checkLiveCleanup } from '../../shared' | 18 | import { 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 () { |
diff --git a/server/tests/api/live/live-permanent.ts b/server/tests/api/live/live-permanent.ts index a88d71dd9..92eac9e5f 100644 --- a/server/tests/api/live/live-permanent.ts +++ b/server/tests/api/live/live-permanent.ts | |||
@@ -172,6 +172,23 @@ describe('Permanent live', function () { | |||
172 | await stopFfmpeg(ffmpegCommand) | 172 | await stopFfmpeg(ffmpegCommand) |
173 | }) | 173 | }) |
174 | 174 | ||
175 | it('Should have appropriate sessions', async function () { | ||
176 | this.timeout(60000) | ||
177 | |||
178 | await servers[0].live.waitUntilWaiting({ videoId: videoUUID }) | ||
179 | |||
180 | const { data, total } = await servers[0].live.listSessions({ videoId: videoUUID }) | ||
181 | expect(total).to.equal(2) | ||
182 | expect(data).to.have.lengthOf(2) | ||
183 | |||
184 | for (const session of data) { | ||
185 | expect(session.startDate).to.exist | ||
186 | expect(session.endDate).to.exist | ||
187 | |||
188 | expect(session.error).to.not.exist | ||
189 | } | ||
190 | }) | ||
191 | |||
175 | after(async function () { | 192 | after(async function () { |
176 | await cleanupTests(servers) | 193 | await cleanupTests(servers) |
177 | }) | 194 | }) |
diff --git a/server/tests/api/live/live-save-replay.ts b/server/tests/api/live/live-save-replay.ts index fc6acc624..7ddcb04ef 100644 --- a/server/tests/api/live/live-save-replay.ts +++ b/server/tests/api/live/live-save-replay.ts | |||
@@ -5,7 +5,7 @@ import * as chai from 'chai' | |||
5 | import { FfmpegCommand } from 'fluent-ffmpeg' | 5 | import { FfmpegCommand } from 'fluent-ffmpeg' |
6 | import { checkLiveCleanup } from '@server/tests/shared' | 6 | import { checkLiveCleanup } from '@server/tests/shared' |
7 | import { wait } from '@shared/core-utils' | 7 | import { wait } from '@shared/core-utils' |
8 | import { HttpStatusCode, LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models' | 8 | import { HttpStatusCode, LiveVideoCreate, LiveVideoError, VideoPrivacy, VideoState } from '@shared/models' |
9 | import { | 9 | import { |
10 | cleanupTests, | 10 | cleanupTests, |
11 | ConfigCommand, | 11 | ConfigCommand, |
@@ -143,6 +143,9 @@ describe('Save replay setting', function () { | |||
143 | }) | 143 | }) |
144 | 144 | ||
145 | describe('With save replay disabled', function () { | 145 | describe('With save replay disabled', function () { |
146 | let sessionStartDateMin: Date | ||
147 | let sessionStartDateMax: Date | ||
148 | let sessionEndDateMin: Date | ||
146 | 149 | ||
147 | it('Should correctly create and federate the "waiting for stream" live', async function () { | 150 | it('Should correctly create and federate the "waiting for stream" live', async function () { |
148 | this.timeout(20000) | 151 | this.timeout(20000) |
@@ -160,7 +163,9 @@ describe('Save replay setting', function () { | |||
160 | 163 | ||
161 | ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) | 164 | ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) |
162 | 165 | ||
166 | sessionStartDateMin = new Date() | ||
163 | await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID) | 167 | await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID) |
168 | sessionStartDateMax = new Date() | ||
164 | 169 | ||
165 | await waitJobs(servers) | 170 | await waitJobs(servers) |
166 | 171 | ||
@@ -171,6 +176,7 @@ describe('Save replay setting', function () { | |||
171 | it('Should correctly delete the video files after the stream ended', async function () { | 176 | it('Should correctly delete the video files after the stream ended', async function () { |
172 | this.timeout(40000) | 177 | this.timeout(40000) |
173 | 178 | ||
179 | sessionEndDateMin = new Date() | ||
174 | await stopFfmpeg(ffmpegCommand) | 180 | await stopFfmpeg(ffmpegCommand) |
175 | 181 | ||
176 | for (const server of servers) { | 182 | for (const server of servers) { |
@@ -186,6 +192,24 @@ describe('Save replay setting', function () { | |||
186 | await checkLiveCleanup(servers[0], liveVideoUUID, []) | 192 | await checkLiveCleanup(servers[0], liveVideoUUID, []) |
187 | }) | 193 | }) |
188 | 194 | ||
195 | it('Should have appropriate ended session', async function () { | ||
196 | const { data, total } = await servers[0].live.listSessions({ videoId: liveVideoUUID }) | ||
197 | expect(total).to.equal(1) | ||
198 | expect(data).to.have.lengthOf(1) | ||
199 | |||
200 | const session = data[0] | ||
201 | |||
202 | const startDate = new Date(session.startDate) | ||
203 | expect(startDate).to.be.above(sessionStartDateMin) | ||
204 | expect(startDate).to.be.below(sessionStartDateMax) | ||
205 | |||
206 | expect(session.endDate).to.exist | ||
207 | expect(new Date(session.endDate)).to.be.above(sessionEndDateMin) | ||
208 | |||
209 | expect(session.error).to.not.exist | ||
210 | expect(session.replayVideo).to.not.exist | ||
211 | }) | ||
212 | |||
189 | it('Should correctly terminate the stream on blacklist and delete the live', async function () { | 213 | it('Should correctly terminate the stream on blacklist and delete the live', async function () { |
190 | this.timeout(40000) | 214 | this.timeout(40000) |
191 | 215 | ||
@@ -201,6 +225,15 @@ describe('Save replay setting', function () { | |||
201 | await checkLiveCleanup(servers[0], liveVideoUUID, []) | 225 | await checkLiveCleanup(servers[0], liveVideoUUID, []) |
202 | }) | 226 | }) |
203 | 227 | ||
228 | it('Should have blacklisted session error', async function () { | ||
229 | const session = await servers[0].live.findLatestSession({ videoId: liveVideoUUID }) | ||
230 | expect(session.startDate).to.exist | ||
231 | expect(session.endDate).to.exist | ||
232 | |||
233 | expect(session.error).to.equal(LiveVideoError.BLACKLISTED) | ||
234 | expect(session.replayVideo).to.not.exist | ||
235 | }) | ||
236 | |||
204 | it('Should correctly terminate the stream on delete and delete the video', async function () { | 237 | it('Should correctly terminate the stream on delete and delete the video', async function () { |
205 | this.timeout(40000) | 238 | this.timeout(40000) |
206 | 239 | ||
@@ -249,6 +282,22 @@ describe('Save replay setting', function () { | |||
249 | await checkVideoState(liveVideoUUID, VideoState.PUBLISHED) | 282 | await checkVideoState(liveVideoUUID, VideoState.PUBLISHED) |
250 | }) | 283 | }) |
251 | 284 | ||
285 | it('Should find the replay live session', async function () { | ||
286 | const session = await servers[0].live.getReplaySession({ videoId: liveVideoUUID }) | ||
287 | |||
288 | expect(session).to.exist | ||
289 | |||
290 | expect(session.startDate).to.exist | ||
291 | expect(session.endDate).to.exist | ||
292 | |||
293 | expect(session.error).to.not.exist | ||
294 | |||
295 | expect(session.replayVideo).to.exist | ||
296 | expect(session.replayVideo.id).to.exist | ||
297 | expect(session.replayVideo.shortUUID).to.exist | ||
298 | expect(session.replayVideo.uuid).to.equal(liveVideoUUID) | ||
299 | }) | ||
300 | |||
252 | it('Should update the saved live and correctly federate the updated attributes', async function () { | 301 | it('Should update the saved live and correctly federate the updated attributes', async function () { |
253 | this.timeout(30000) | 302 | this.timeout(30000) |
254 | 303 | ||
@@ -337,6 +386,27 @@ describe('Save replay setting', function () { | |||
337 | lastReplayUUID = video.uuid | 386 | lastReplayUUID = video.uuid |
338 | }) | 387 | }) |
339 | 388 | ||
389 | it('Should have appropriate ended session and replay live session', async function () { | ||
390 | const { data, total } = await servers[0].live.listSessions({ videoId: liveVideoUUID }) | ||
391 | expect(total).to.equal(1) | ||
392 | expect(data).to.have.lengthOf(1) | ||
393 | |||
394 | const sessionFromLive = data[0] | ||
395 | const sessionFromReplay = await servers[0].live.getReplaySession({ videoId: lastReplayUUID }) | ||
396 | |||
397 | for (const session of [ sessionFromLive, sessionFromReplay ]) { | ||
398 | expect(session.startDate).to.exist | ||
399 | expect(session.endDate).to.exist | ||
400 | |||
401 | expect(session.error).to.not.exist | ||
402 | |||
403 | expect(session.replayVideo).to.exist | ||
404 | expect(session.replayVideo.id).to.exist | ||
405 | expect(session.replayVideo.shortUUID).to.exist | ||
406 | expect(session.replayVideo.uuid).to.equal(lastReplayUUID) | ||
407 | } | ||
408 | }) | ||
409 | |||
340 | it('Should have cleaned up the live files', async function () { | 410 | it('Should have cleaned up the live files', async function () { |
341 | await checkLiveCleanup(servers[0], liveVideoUUID, []) | 411 | await checkLiveCleanup(servers[0], liveVideoUUID, []) |
342 | }) | 412 | }) |
diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts index ab7251e31..9b8fbe3e2 100644 --- a/server/tests/api/live/live.ts +++ b/server/tests/api/live/live.ts | |||
@@ -594,6 +594,8 @@ describe('Test live', function () { | |||
594 | 594 | ||
595 | let permanentLiveReplayName: string | 595 | let permanentLiveReplayName: string |
596 | 596 | ||
597 | let beforeServerRestart: Date | ||
598 | |||
597 | async function createLiveWrapper (options: { saveReplay: boolean, permanent: boolean }) { | 599 | async function createLiveWrapper (options: { saveReplay: boolean, permanent: boolean }) { |
598 | const liveAttributes: LiveVideoCreate = { | 600 | const liveAttributes: LiveVideoCreate = { |
599 | name: 'live video', | 601 | name: 'live video', |
@@ -636,6 +638,8 @@ describe('Test live', function () { | |||
636 | } | 638 | } |
637 | 639 | ||
638 | await killallServers([ servers[0] ]) | 640 | await killallServers([ servers[0] ]) |
641 | |||
642 | beforeServerRestart = new Date() | ||
639 | await servers[0].run() | 643 | await servers[0].run() |
640 | 644 | ||
641 | await wait(5000) | 645 | await wait(5000) |
@@ -653,6 +657,10 @@ describe('Test live', function () { | |||
653 | this.timeout(120000) | 657 | this.timeout(120000) |
654 | 658 | ||
655 | await commands[0].waitUntilPublished({ videoId: liveVideoReplayId }) | 659 | await commands[0].waitUntilPublished({ videoId: liveVideoReplayId }) |
660 | |||
661 | const session = await commands[0].getReplaySession({ videoId: liveVideoReplayId }) | ||
662 | expect(session.endDate).to.exist | ||
663 | expect(new Date(session.endDate)).to.be.above(beforeServerRestart) | ||
656 | }) | 664 | }) |
657 | 665 | ||
658 | it('Should have saved a permanent live replay', async function () { | 666 | it('Should have saved a permanent live replay', async function () { |