X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Flive%2Flive-views.ts;h=446d0913cb933beb33b1b3955c802dccd24e4ad7;hb=c55e3d7227fe1453869e309025996b9d75256d5d;hp=a44d21ffa45cd7c4503a48130f3806e7e67fdac4;hpb=8ebf2a5d5d126e6ef9b89109124adf2a5e9e293d;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/live/live-views.ts b/server/tests/api/live/live-views.ts index a44d21ffa..446d0913c 100644 --- a/server/tests/api/live/live-views.ts +++ b/server/tests/api/live/live-views.ts @@ -3,45 +3,42 @@ import 'mocha' import * as chai from 'chai' import { FfmpegCommand } from 'fluent-ffmpeg' -import { VideoDetails, VideoPrivacy } from '@shared/models' +import { wait } from '@shared/core-utils' +import { VideoPrivacy } from '@shared/models' import { cleanupTests, - createLive, + createMultipleServers, doubleFollow, - flushAndRunMultipleServers, - getVideo, - sendRTMPStreamInVideo, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, stopFfmpeg, - updateCustomSubConfig, - viewVideo, - wait, waitJobs, waitUntilLivePublishedOnAllServers -} from '../../../../shared/extra-utils' +} from '@shared/server-commands' const expect = chai.expect -describe('Test live', function () { - let servers: ServerInfo[] = [] +describe('Live views', function () { + let servers: PeerTubeServer[] = [] before(async function () { this.timeout(120000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) // Get the access tokens await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - live: { - enabled: true, - allowReplay: true, - transcoding: { - enabled: false + await servers[0].config.updateCustomSubConfig({ + newConfig: { + live: { + enabled: true, + allowReplay: true, + transcoding: { + enabled: false + } } } }) @@ -50,81 +47,86 @@ describe('Test live', function () { await doubleFollow(servers[0], servers[1]) }) - describe('Live views', function () { - let liveVideoId: string - let command: FfmpegCommand + let liveVideoId: string + let command: FfmpegCommand - async function countViews (expected: number) { - for (const server of servers) { - const res = await getVideo(server.url, liveVideoId) - const video: VideoDetails = res.body - - expect(video.views).to.equal(expected) - } + async function countViewers (expectedViewers: number) { + for (const server of servers) { + const video = await server.videos.get({ id: liveVideoId }) + expect(video.viewers).to.equal(expectedViewers) } + } - before(async function () { - this.timeout(30000) + async function countViews (expectedViews: number) { + for (const server of servers) { + const video = await server.videos.get({ id: liveVideoId }) + expect(video.views).to.equal(expectedViews) + } + } - const liveAttributes = { - name: 'live video', - channelId: servers[0].videoChannel.id, - privacy: VideoPrivacy.PUBLIC - } + before(async function () { + this.timeout(30000) - const res = await createLive(servers[0].url, servers[0].accessToken, liveAttributes) - liveVideoId = res.body.video.uuid + const liveAttributes = { + name: 'live video', + channelId: servers[0].store.channel.id, + privacy: VideoPrivacy.PUBLIC + } - command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId) - await waitUntilLivePublishedOnAllServers(servers, liveVideoId) - await waitJobs(servers) - }) + const live = await servers[0].live.create({ fields: liveAttributes }) + liveVideoId = live.uuid - it('Should display no views for a live', async function () { - await countViews(0) - }) + command = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoId }) + await waitUntilLivePublishedOnAllServers(servers, liveVideoId) + await waitJobs(servers) + }) - it('Should view a live twice and display 1 view', async function () { - this.timeout(30000) + it('Should display no views and viewers for a live', async function () { + await countViews(0) + await countViewers(0) + }) - await viewVideo(servers[0].url, liveVideoId) - await viewVideo(servers[0].url, liveVideoId) + it('Should view a live twice and display 1 view/viewer', async function () { + this.timeout(30000) - await wait(7000) + await servers[0].videos.view({ id: liveVideoId }) + await servers[0].videos.view({ id: liveVideoId }) - await waitJobs(servers) + await waitJobs(servers) + await countViewers(1) - await countViews(1) - }) + await wait(7000) + await countViews(1) + }) - it('Should wait and display 0 views', async function () { - this.timeout(30000) + it('Should wait and display 0 viewers while still have 1 view', async function () { + this.timeout(30000) - await wait(12000) - await waitJobs(servers) + await wait(12000) + await waitJobs(servers) - await countViews(0) - }) + await countViews(1) + await countViewers(0) + }) - it('Should view a live on a remote and on local and display 2 views', async function () { - this.timeout(30000) + it('Should view a live on a remote and on local and display 2 viewers and 3 views', async function () { + this.timeout(30000) - await viewVideo(servers[0].url, liveVideoId) - await viewVideo(servers[1].url, liveVideoId) - await viewVideo(servers[1].url, liveVideoId) + await servers[0].videos.view({ id: liveVideoId }) + await servers[1].videos.view({ id: liveVideoId }) + await servers[1].videos.view({ id: liveVideoId }) + await waitJobs(servers) - await wait(7000) - await waitJobs(servers) + await countViewers(2) - await countViews(2) - }) + await wait(7000) + await waitJobs(servers) - after(async function () { - await stopFfmpeg(command) - }) + await countViews(3) }) after(async function () { + await stopFfmpeg(command) await cleanupTests(servers) }) })