X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Flive%2Flive-save-replay.ts;h=3d4736c8fb65e635de22779547b5f3b2bea44b7b;hb=693c6586cb896a84ff0f897b1c242bcf7bdcbaee;hp=3ffa0c093ccb721cab69aa589c380d505acc8129;hpb=68e70a745b2010cd0199864a2addd60d8f99c732;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/live/live-save-replay.ts b/server/tests/api/live/live-save-replay.ts index 3ffa0c093..3d4736c8f 100644 --- a/server/tests/api/live/live-save-replay.ts +++ b/server/tests/api/live/live-save-replay.ts @@ -4,6 +4,7 @@ import 'mocha' import * as chai from 'chai' import { FfmpegCommand } from 'fluent-ffmpeg' import { LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState } from '@shared/models' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { addVideoToBlacklist, checkLiveCleanup, @@ -11,6 +12,7 @@ import { createLive, doubleFollow, flushAndRunMultipleServers, + getCustomConfigResolutions, getVideo, getVideosList, removeVideo, @@ -22,8 +24,11 @@ import { testFfmpegStreamError, updateCustomSubConfig, updateVideo, + wait, waitJobs, - waitUntilLiveStarts + waitUntilLiveEnded, + waitUntilLivePublished, + waitUntilLiveSaved } from '../../../../shared/extra-utils' const expect = chai.expect @@ -73,6 +78,18 @@ describe('Save replay setting', function () { } } + async function waitUntilLivePublishedOnAllServers (videoId: string) { + for (const server of servers) { + await waitUntilLivePublished(server.url, server.accessToken, videoId) + } + } + + async function waitUntilLiveSavedOnAllServers (videoId: string) { + for (const server of servers) { + await waitUntilLiveSaved(server.url, server.accessToken, videoId) + } + } + before(async function () { this.timeout(120000) @@ -89,17 +106,10 @@ describe('Save replay setting', function () { live: { enabled: true, allowReplay: true, - maxDuration: null, + maxDuration: -1, transcoding: { enabled: false, - resolutions: { - '240p': true, - '360p': true, - '480p': true, - '720p': true, - '1080p': true, - '2160p': true - } + resolutions: getCustomConfigResolutions(true) } } }) @@ -118,31 +128,35 @@ describe('Save replay setting', function () { await waitJobs(servers) - await checkVideosExist(liveVideoUUID, false, 200) + await checkVideosExist(liveVideoUUID, false, HttpStatusCode.OK_200) await checkVideoState(liveVideoUUID, VideoState.WAITING_FOR_LIVE) }) it('Should correctly have updated the live and federated it when streaming in the live', async function () { - this.timeout(20000) + this.timeout(30000) ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) - await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoUUID) + + await waitUntilLivePublishedOnAllServers(liveVideoUUID) await waitJobs(servers) - await checkVideosExist(liveVideoUUID, true, 200) + await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) await checkVideoState(liveVideoUUID, VideoState.PUBLISHED) }) it('Should correctly delete the video files after the stream ended', async function () { - this.timeout(30000) + this.timeout(40000) await stopFfmpeg(ffmpegCommand) + for (const server of servers) { + await waitUntilLiveEnded(server.url, server.accessToken, liveVideoUUID) + } await waitJobs(servers) // Live still exist, but cannot be played anymore - await checkVideosExist(liveVideoUUID, false, 200) + await checkVideosExist(liveVideoUUID, false, HttpStatusCode.OK_200) await checkVideoState(liveVideoUUID, VideoState.LIVE_ENDED) // No resolutions saved since we did not save replay @@ -155,10 +169,11 @@ describe('Save replay setting', function () { liveVideoUUID = await createLiveWrapper(false) ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) - await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoUUID) + + await waitUntilLivePublishedOnAllServers(liveVideoUUID) await waitJobs(servers) - await checkVideosExist(liveVideoUUID, true, 200) + await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) await Promise.all([ addVideoToBlacklist(servers[0].url, servers[0].accessToken, liveVideoUUID, 'bad live', true), @@ -169,9 +184,11 @@ describe('Save replay setting', function () { await checkVideosExist(liveVideoUUID, false) - await getVideo(servers[0].url, liveVideoUUID, 401) - await getVideo(servers[1].url, liveVideoUUID, 404) + await getVideo(servers[0].url, liveVideoUUID, HttpStatusCode.UNAUTHORIZED_401) + await getVideo(servers[1].url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) + await wait(5000) + await waitJobs(servers) await checkLiveCleanup(servers[0], liveVideoUUID, []) }) @@ -181,19 +198,21 @@ describe('Save replay setting', function () { liveVideoUUID = await createLiveWrapper(false) ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) - await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoUUID) + + await waitUntilLivePublishedOnAllServers(liveVideoUUID) await waitJobs(servers) - await checkVideosExist(liveVideoUUID, true, 200) + await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) await Promise.all([ testFfmpegStreamError(ffmpegCommand, true), removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) ]) + await wait(5000) await waitJobs(servers) - await checkVideosExist(liveVideoUUID, false, 404) + await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404) await checkLiveCleanup(servers[0], liveVideoUUID, []) }) }) @@ -207,7 +226,7 @@ describe('Save replay setting', function () { await waitJobs(servers) - await checkVideosExist(liveVideoUUID, false, 200) + await checkVideosExist(liveVideoUUID, false, HttpStatusCode.OK_200) await checkVideoState(liveVideoUUID, VideoState.WAITING_FOR_LIVE) }) @@ -215,11 +234,11 @@ describe('Save replay setting', function () { this.timeout(20000) ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) - await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoUUID) + await waitUntilLivePublishedOnAllServers(liveVideoUUID) await waitJobs(servers) - await checkVideosExist(liveVideoUUID, true, 200) + await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) await checkVideoState(liveVideoUUID, VideoState.PUBLISHED) }) @@ -228,10 +247,11 @@ describe('Save replay setting', function () { await stopFfmpeg(ffmpegCommand) + await waitUntilLiveSavedOnAllServers(liveVideoUUID) await waitJobs(servers) // Live has been transcoded - await checkVideosExist(liveVideoUUID, true, 200) + await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) await checkVideoState(liveVideoUUID, VideoState.PUBLISHED) }) @@ -258,10 +278,10 @@ describe('Save replay setting', function () { liveVideoUUID = await createLiveWrapper(true) ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) - await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoUUID) + await waitUntilLivePublishedOnAllServers(liveVideoUUID) await waitJobs(servers) - await checkVideosExist(liveVideoUUID, true, 200) + await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) await Promise.all([ addVideoToBlacklist(servers[0].url, servers[0].accessToken, liveVideoUUID, 'bad live', true), @@ -272,9 +292,11 @@ describe('Save replay setting', function () { await checkVideosExist(liveVideoUUID, false) - await getVideo(servers[0].url, liveVideoUUID, 401) - await getVideo(servers[1].url, liveVideoUUID, 404) + await getVideo(servers[0].url, liveVideoUUID, HttpStatusCode.UNAUTHORIZED_401) + await getVideo(servers[1].url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) + await wait(5000) + await waitJobs(servers) await checkLiveCleanup(servers[0], liveVideoUUID, [ 720 ]) }) @@ -284,19 +306,20 @@ describe('Save replay setting', function () { liveVideoUUID = await createLiveWrapper(true) ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) - await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoUUID) + await waitUntilLivePublishedOnAllServers(liveVideoUUID) await waitJobs(servers) - await checkVideosExist(liveVideoUUID, true, 200) + await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) await Promise.all([ removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID), testFfmpegStreamError(ffmpegCommand, true) ]) + await wait(5000) await waitJobs(servers) - await checkVideosExist(liveVideoUUID, false, 404) + await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404) await checkLiveCleanup(servers[0], liveVideoUUID, []) }) })