From 6b6168606bc86430f6b7821c9d5f1c80d0425ebf Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 29 Aug 2018 16:26:25 +0200 Subject: Bufferize videos views in redis --- server/tests/api/server/reverse-proxy.ts | 33 ++++++++++++++++++++++++++++- server/tests/api/server/stats.ts | 3 +++ server/tests/api/videos/multiple-servers.ts | 10 +++++++-- server/tests/api/videos/single-server.ts | 5 ++++- server/tests/utils/server/jobs.ts | 8 ++++--- 5 files changed, 52 insertions(+), 7 deletions(-) (limited to 'server/tests') 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' import * as chai from 'chai' import { About } from '../../../../shared/models/server/about.model' import { CustomConfig } from '../../../../shared/models/server/custom-config.model' -import { deleteCustomConfig, getAbout, getVideo, killallServers, login, reRunServer, uploadVideo, userLogin, viewVideo } from '../../utils' +import { + deleteCustomConfig, + getAbout, + getVideo, + killallServers, + login, + reRunServer, + uploadVideo, + userLogin, + viewVideo, + wait +} from '../../utils' const expect = chai.expect import { @@ -30,33 +41,53 @@ describe('Test application behind a reverse proxy', function () { }) it('Should view a video only once with the same IP by default', async function () { + this.timeout(20000) + await viewVideo(server.url, videoId) await viewVideo(server.url, videoId) + // Wait the repeatable job + await wait(8000) + const { body } = await getVideo(server.url, videoId) expect(body.views).to.equal(1) }) it('Should view a video 2 times with the X-Forwarded-For header set', async function () { + this.timeout(20000) + await viewVideo(server.url, videoId, 204, '0.0.0.1,127.0.0.1') await viewVideo(server.url, videoId, 204, '0.0.0.2,127.0.0.1') + // Wait the repeatable job + await wait(8000) + const { body } = await getVideo(server.url, videoId) expect(body.views).to.equal(3) }) it('Should view a video only once with the same client IP in the X-Forwarded-For header', async function () { + this.timeout(20000) + await viewVideo(server.url, videoId, 204, '0.0.0.4,0.0.0.3,::ffff:127.0.0.1') await viewVideo(server.url, videoId, 204, '0.0.0.5,0.0.0.3,127.0.0.1') + // Wait the repeatable job + await wait(8000) + const { body } = await getVideo(server.url, videoId) expect(body.views).to.equal(4) }) it('Should view a video two times with a different client IP in the X-Forwarded-For header', async function () { + this.timeout(20000) + await viewVideo(server.url, videoId, 204, '0.0.0.8,0.0.0.6,127.0.0.1') await viewVideo(server.url, videoId, 204, '0.0.0.8,0.0.0.7,127.0.0.1') + // Wait the repeatable job + await wait(8000) + const { body } = await getVideo(server.url, videoId) expect(body.views).to.equal(6) }) 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 () { await viewVideo(servers[0].url, videoUUID) + // Wait the video views repeatable job + await wait(8000) + await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken) await waitJobs(servers) }) 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 () { }) it('Should view multiple videos on owned servers', async function () { - this.timeout(15000) + this.timeout(30000) const tasks: Promise[] = [] await viewVideo(servers[2].url, localVideosServer3[0]) @@ -511,6 +511,9 @@ describe('Test multiple servers', function () { await waitJobs(servers) + // Wait the repeatable job + await wait(6000) + for (const server of servers) { const res = await getVideosList(server.url) @@ -524,7 +527,7 @@ describe('Test multiple servers', function () { }) it('Should view multiple videos on each servers', async function () { - this.timeout(15000) + this.timeout(30000) const tasks: Promise[] = [] tasks.push(viewVideo(servers[0].url, remoteVideosServer1[0])) @@ -542,6 +545,9 @@ describe('Test multiple servers', function () { await waitJobs(servers) + // Wait the repeatable job + await wait(8000) + let baseVideos = null 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 () { }) it('Should have the views updated', async function () { - this.timeout(10000) + this.timeout(20000) await viewVideo(server.url, videoId) await viewVideo(server.url, videoId) @@ -212,6 +212,9 @@ describe('Test a single server', function () { await viewVideo(server.url, videoId) await viewVideo(server.url, videoId) + // Wait the repeatable job + await wait(8000) + const res = await getVideo(server.url, videoId) 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 @@ import * as request from 'supertest' -import { JobState } from '../../../../shared/models' +import { Job, JobState } from '../../../../shared/models' import { ServerInfo, wait } from '../index' function getJobsList (url: string, accessToken: string, state: JobState) { @@ -44,8 +44,10 @@ async function waitJobs (serversArg: ServerInfo[] | ServerInfo) { for (const server of servers) { for (const state of states) { const p = getJobsListPaginationAndSort(server.url, server.accessToken, state, 0, 10, '-createdAt') - .then(res => { - if (res.body.total > 0) pendingRequests = true + .then(res => res.body.data) + .then((jobs: Job[]) => jobs.filter(j => j.type !== 'videos-views')) + .then(jobs => { + if (jobs.length !== 0) pendingRequests = true }) tasks.push(p) } -- cgit v1.2.3