aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-29 16:26:25 +0200
committerChocobozzz <me@florianbigard.com>2018-08-30 15:03:18 +0200
commit6b6168606bc86430f6b7821c9d5f1c80d0425ebf (patch)
tree9aea6cf0875c9fee30c373eb4924b12d47d1e23c /server/tests
parent2d9fea161fd4fc73994fc77951bafdccdc2071fd (diff)
downloadPeerTube-6b6168606bc86430f6b7821c9d5f1c80d0425ebf.tar.gz
PeerTube-6b6168606bc86430f6b7821c9d5f1c80d0425ebf.tar.zst
PeerTube-6b6168606bc86430f6b7821c9d5f1c80d0425ebf.zip
Bufferize videos views in redis
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/server/reverse-proxy.ts33
-rw-r--r--server/tests/api/server/stats.ts3
-rw-r--r--server/tests/api/videos/multiple-servers.ts10
-rw-r--r--server/tests/api/videos/single-server.ts5
-rw-r--r--server/tests/utils/server/jobs.ts8
5 files changed, 52 insertions, 7 deletions
diff --git a/server/tests/api/server/reverse-proxy.ts b/server/tests/api/server/reverse-proxy.ts
index 908b4a68c..e2c2a293e 100644
--- a/server/tests/api/server/reverse-proxy.ts
+++ b/server/tests/api/server/reverse-proxy.ts
@@ -4,7 +4,18 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { About } from '../../../../shared/models/server/about.model' 5import { About } from '../../../../shared/models/server/about.model'
6import { CustomConfig } from '../../../../shared/models/server/custom-config.model' 6import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
7import { deleteCustomConfig, getAbout, getVideo, killallServers, login, reRunServer, uploadVideo, userLogin, viewVideo } from '../../utils' 7import {
8 deleteCustomConfig,
9 getAbout,
10 getVideo,
11 killallServers,
12 login,
13 reRunServer,
14 uploadVideo,
15 userLogin,
16 viewVideo,
17 wait
18} from '../../utils'
8const expect = chai.expect 19const expect = chai.expect
9 20
10import { 21import {
@@ -30,33 +41,53 @@ describe('Test application behind a reverse proxy', function () {
30 }) 41 })
31 42
32 it('Should view a video only once with the same IP by default', async function () { 43 it('Should view a video only once with the same IP by default', async function () {
44 this.timeout(20000)
45
33 await viewVideo(server.url, videoId) 46 await viewVideo(server.url, videoId)
34 await viewVideo(server.url, videoId) 47 await viewVideo(server.url, videoId)
35 48
49 // Wait the repeatable job
50 await wait(8000)
51
36 const { body } = await getVideo(server.url, videoId) 52 const { body } = await getVideo(server.url, videoId)
37 expect(body.views).to.equal(1) 53 expect(body.views).to.equal(1)
38 }) 54 })
39 55
40 it('Should view a video 2 times with the X-Forwarded-For header set', async function () { 56 it('Should view a video 2 times with the X-Forwarded-For header set', async function () {
57 this.timeout(20000)
58
41 await viewVideo(server.url, videoId, 204, '0.0.0.1,127.0.0.1') 59 await viewVideo(server.url, videoId, 204, '0.0.0.1,127.0.0.1')
42 await viewVideo(server.url, videoId, 204, '0.0.0.2,127.0.0.1') 60 await viewVideo(server.url, videoId, 204, '0.0.0.2,127.0.0.1')
43 61
62 // Wait the repeatable job
63 await wait(8000)
64
44 const { body } = await getVideo(server.url, videoId) 65 const { body } = await getVideo(server.url, videoId)
45 expect(body.views).to.equal(3) 66 expect(body.views).to.equal(3)
46 }) 67 })
47 68
48 it('Should view a video only once with the same client IP in the X-Forwarded-For header', async function () { 69 it('Should view a video only once with the same client IP in the X-Forwarded-For header', async function () {
70 this.timeout(20000)
71
49 await viewVideo(server.url, videoId, 204, '0.0.0.4,0.0.0.3,::ffff:127.0.0.1') 72 await viewVideo(server.url, videoId, 204, '0.0.0.4,0.0.0.3,::ffff:127.0.0.1')
50 await viewVideo(server.url, videoId, 204, '0.0.0.5,0.0.0.3,127.0.0.1') 73 await viewVideo(server.url, videoId, 204, '0.0.0.5,0.0.0.3,127.0.0.1')
51 74
75 // Wait the repeatable job
76 await wait(8000)
77
52 const { body } = await getVideo(server.url, videoId) 78 const { body } = await getVideo(server.url, videoId)
53 expect(body.views).to.equal(4) 79 expect(body.views).to.equal(4)
54 }) 80 })
55 81
56 it('Should view a video two times with a different client IP in the X-Forwarded-For header', async function () { 82 it('Should view a video two times with a different client IP in the X-Forwarded-For header', async function () {
83 this.timeout(20000)
84
57 await viewVideo(server.url, videoId, 204, '0.0.0.8,0.0.0.6,127.0.0.1') 85 await viewVideo(server.url, videoId, 204, '0.0.0.8,0.0.0.6,127.0.0.1')
58 await viewVideo(server.url, videoId, 204, '0.0.0.8,0.0.0.7,127.0.0.1') 86 await viewVideo(server.url, videoId, 204, '0.0.0.8,0.0.0.7,127.0.0.1')
59 87
88 // Wait the repeatable job
89 await wait(8000)
90
60 const { body } = await getVideo(server.url, videoId) 91 const { body } = await getVideo(server.url, videoId)
61 expect(body.views).to.equal(6) 92 expect(body.views).to.equal(6)
62 }) 93 })
diff --git a/server/tests/api/server/stats.ts b/server/tests/api/server/stats.ts
index e75089a14..fc9b88805 100644
--- a/server/tests/api/server/stats.ts
+++ b/server/tests/api/server/stats.ts
@@ -46,6 +46,9 @@ describe('Test stats', function () {
46 46
47 await viewVideo(servers[0].url, videoUUID) 47 await viewVideo(servers[0].url, videoUUID)
48 48
49 // Wait the video views repeatable job
50 await wait(8000)
51
49 await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken) 52 await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
50 await waitJobs(servers) 53 await waitJobs(servers)
51 }) 54 })
diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts
index c551ccc59..4553ee855 100644
--- a/server/tests/api/videos/multiple-servers.ts
+++ b/server/tests/api/videos/multiple-servers.ts
@@ -492,7 +492,7 @@ describe('Test multiple servers', function () {
492 }) 492 })
493 493
494 it('Should view multiple videos on owned servers', async function () { 494 it('Should view multiple videos on owned servers', async function () {
495 this.timeout(15000) 495 this.timeout(30000)
496 496
497 const tasks: Promise<any>[] = [] 497 const tasks: Promise<any>[] = []
498 await viewVideo(servers[2].url, localVideosServer3[0]) 498 await viewVideo(servers[2].url, localVideosServer3[0])
@@ -511,6 +511,9 @@ describe('Test multiple servers', function () {
511 511
512 await waitJobs(servers) 512 await waitJobs(servers)
513 513
514 // Wait the repeatable job
515 await wait(6000)
516
514 for (const server of servers) { 517 for (const server of servers) {
515 const res = await getVideosList(server.url) 518 const res = await getVideosList(server.url)
516 519
@@ -524,7 +527,7 @@ describe('Test multiple servers', function () {
524 }) 527 })
525 528
526 it('Should view multiple videos on each servers', async function () { 529 it('Should view multiple videos on each servers', async function () {
527 this.timeout(15000) 530 this.timeout(30000)
528 531
529 const tasks: Promise<any>[] = [] 532 const tasks: Promise<any>[] = []
530 tasks.push(viewVideo(servers[0].url, remoteVideosServer1[0])) 533 tasks.push(viewVideo(servers[0].url, remoteVideosServer1[0]))
@@ -542,6 +545,9 @@ describe('Test multiple servers', function () {
542 545
543 await waitJobs(servers) 546 await waitJobs(servers)
544 547
548 // Wait the repeatable job
549 await wait(8000)
550
545 let baseVideos = null 551 let baseVideos = null
546 552
547 for (const server of servers) { 553 for (const server of servers) {
diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts
index a757ad9da..89408fec6 100644
--- a/server/tests/api/videos/single-server.ts
+++ b/server/tests/api/videos/single-server.ts
@@ -196,7 +196,7 @@ describe('Test a single server', function () {
196 }) 196 })
197 197
198 it('Should have the views updated', async function () { 198 it('Should have the views updated', async function () {
199 this.timeout(10000) 199 this.timeout(20000)
200 200
201 await viewVideo(server.url, videoId) 201 await viewVideo(server.url, videoId)
202 await viewVideo(server.url, videoId) 202 await viewVideo(server.url, videoId)
@@ -212,6 +212,9 @@ describe('Test a single server', function () {
212 await viewVideo(server.url, videoId) 212 await viewVideo(server.url, videoId)
213 await viewVideo(server.url, videoId) 213 await viewVideo(server.url, videoId)
214 214
215 // Wait the repeatable job
216 await wait(8000)
217
215 const res = await getVideo(server.url, videoId) 218 const res = await getVideo(server.url, videoId)
216 219
217 const video = res.body 220 const video = res.body
diff --git a/server/tests/utils/server/jobs.ts b/server/tests/utils/server/jobs.ts
index c9cb8d3a3..4c02cace5 100644
--- a/server/tests/utils/server/jobs.ts
+++ b/server/tests/utils/server/jobs.ts
@@ -1,5 +1,5 @@
1import * as request from 'supertest' 1import * as request from 'supertest'
2import { JobState } from '../../../../shared/models' 2import { Job, JobState } from '../../../../shared/models'
3import { ServerInfo, wait } from '../index' 3import { ServerInfo, wait } from '../index'
4 4
5function getJobsList (url: string, accessToken: string, state: JobState) { 5function getJobsList (url: string, accessToken: string, state: JobState) {
@@ -44,8 +44,10 @@ async function waitJobs (serversArg: ServerInfo[] | ServerInfo) {
44 for (const server of servers) { 44 for (const server of servers) {
45 for (const state of states) { 45 for (const state of states) {
46 const p = getJobsListPaginationAndSort(server.url, server.accessToken, state, 0, 10, '-createdAt') 46 const p = getJobsListPaginationAndSort(server.url, server.accessToken, state, 0, 10, '-createdAt')
47 .then(res => { 47 .then(res => res.body.data)
48 if (res.body.total > 0) pendingRequests = true 48 .then((jobs: Job[]) => jobs.filter(j => j.type !== 'videos-views'))
49 .then(jobs => {
50 if (jobs.length !== 0) pendingRequests = true
49 }) 51 })
50 tasks.push(p) 52 tasks.push(p)
51 } 53 }