aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/live
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/live')
-rw-r--r--server/tests/api/live/live-views.ts109
1 files changed, 58 insertions, 51 deletions
diff --git a/server/tests/api/live/live-views.ts b/server/tests/api/live/live-views.ts
index 5e3a79c64..9186af8e7 100644
--- a/server/tests/api/live/live-views.ts
+++ b/server/tests/api/live/live-views.ts
@@ -19,7 +19,7 @@ import {
19 19
20const expect = chai.expect 20const expect = chai.expect
21 21
22describe('Test live', function () { 22describe('Live views', function () {
23 let servers: PeerTubeServer[] = [] 23 let servers: PeerTubeServer[] = []
24 24
25 before(async function () { 25 before(async function () {
@@ -47,79 +47,86 @@ describe('Test live', function () {
47 await doubleFollow(servers[0], servers[1]) 47 await doubleFollow(servers[0], servers[1])
48 }) 48 })
49 49
50 describe('Live views', function () { 50 let liveVideoId: string
51 let liveVideoId: string 51 let command: FfmpegCommand
52 let command: FfmpegCommand
53 52
54 async function countViews (expected: number) { 53 async function countViewers (expectedViewers: number) {
55 for (const server of servers) { 54 for (const server of servers) {
56 const video = await server.videos.get({ id: liveVideoId }) 55 const video = await server.videos.get({ id: liveVideoId })
57 expect(video.views).to.equal(expected) 56 expect(video.viewers).to.equal(expectedViewers)
58 }
59 } 57 }
58 }
60 59
61 before(async function () { 60 async function countViews (expectedViews: number) {
62 this.timeout(30000) 61 for (const server of servers) {
62 const video = await server.videos.get({ id: liveVideoId })
63 expect(video.views).to.equal(expectedViews)
64 }
65 }
63 66
64 const liveAttributes = { 67 before(async function () {
65 name: 'live video', 68 this.timeout(30000)
66 channelId: servers[0].store.channel.id,
67 privacy: VideoPrivacy.PUBLIC
68 }
69 69
70 const live = await servers[0].live.create({ fields: liveAttributes }) 70 const liveAttributes = {
71 liveVideoId = live.uuid 71 name: 'live video',
72 channelId: servers[0].store.channel.id,
73 privacy: VideoPrivacy.PUBLIC
74 }
72 75
73 command = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoId }) 76 const live = await servers[0].live.create({ fields: liveAttributes })
74 await waitUntilLivePublishedOnAllServers(servers, liveVideoId) 77 liveVideoId = live.uuid
75 await waitJobs(servers)
76 })
77 78
78 it('Should display no views for a live', async function () { 79 command = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoId })
79 await countViews(0) 80 await waitUntilLivePublishedOnAllServers(servers, liveVideoId)
80 }) 81 await waitJobs(servers)
82 })
81 83
82 it('Should view a live twice and display 1 view', async function () { 84 it('Should display no views and viewers for a live', async function () {
83 this.timeout(30000) 85 await countViews(0)
86 await countViewers(0)
87 })
84 88
85 await servers[0].videos.view({ id: liveVideoId }) 89 it('Should view a live twice and display 1 view/viewer', async function () {
86 await servers[0].videos.view({ id: liveVideoId }) 90 this.timeout(30000)
87 91
88 await wait(7000) 92 await servers[0].videos.view({ id: liveVideoId })
93 await servers[0].videos.view({ id: liveVideoId })
89 94
90 await waitJobs(servers) 95 await waitJobs(servers)
96 await countViewers(1)
91 97
92 await countViews(1) 98 await wait(7000)
93 }) 99 await countViews(1)
100 })
94 101
95 it('Should wait and display 0 views', async function () { 102 it('Should wait and display 0 viewers while still have 1 view', async function () {
96 this.timeout(30000) 103 this.timeout(30000)
97 104
98 await wait(12000) 105 await wait(12000)
99 await waitJobs(servers) 106 await waitJobs(servers)
100 107
101 await countViews(0) 108 await countViews(1)
102 }) 109 await countViewers(0)
110 })
103 111
104 it('Should view a live on a remote and on local and display 2 views', async function () { 112 it('Should view a live on a remote and on local and display 2 viewers and 3 views', async function () {
105 this.timeout(30000) 113 this.timeout(30000)
106 114
107 await servers[0].videos.view({ id: liveVideoId }) 115 await servers[0].videos.view({ id: liveVideoId })
108 await servers[1].videos.view({ id: liveVideoId }) 116 await servers[1].videos.view({ id: liveVideoId })
109 await servers[1].videos.view({ id: liveVideoId }) 117 await servers[1].videos.view({ id: liveVideoId })
118 await waitJobs(servers)
110 119
111 await wait(7000) 120 await countViewers(2)
112 await waitJobs(servers)
113 121
114 await countViews(2) 122 await wait(7000)
115 }) 123 await waitJobs(servers)
116 124
117 after(async function () { 125 await countViews(3)
118 await stopFfmpeg(command)
119 })
120 }) 126 })
121 127
122 after(async function () { 128 after(async function () {
129 await stopFfmpeg(command)
123 await cleanupTests(servers) 130 await cleanupTests(servers)
124 }) 131 })
125}) 132})