Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add perf tests and pgbouncer in dev #652

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions core/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# update

import os
import sys
import json

import environ
Expand Down Expand Up @@ -136,6 +137,11 @@ def get_installed_apps(proj_apps):
}
}

# Skip pgbouncer for running tests
if 'test' in sys.argv or 'test_coverage' in sys.argv:
DATABASES['default']['HOST'] = 'db'
DATABASES['default']['NAME'] = 'test_db'

CONN_MAX_AGE = 600

CACHES = {
Expand Down
16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ services:
- ${DATE_DB_PORT}:5432
environment:
- POSTGRES_PASSWORD=${DATE_DB_PASSWORD}
- POSTGRES_MAX_CONNECTIONS=1000
pgbouncer:
image: edoburu/pgbouncer
depends_on:
- db
environment:
- DB_HOST=db
- DB_PORT=5432
- DB_USER=postgres
- DB_PASSWORD=${DATE_DB_PASSWORD}
- POOL_MODE=transaction
- AUTH_TYPE=scram-sha-256
- MAX_CLIENT_CONN=1000
- ADMIN_USERS=postgres,admin
web:
build: .
restart: always
Expand All @@ -24,6 +38,7 @@ services:
- DEBUG=${DATE_DEBUG}
- DEVELOP=${DATE_DEVELOP}
- PROJECT_NAME=${PROJECT_NAME}
- DB_HOST=pgbouncer
- DB_PASSWORD=${DATE_DB_PASSWORD}
- USE_S3=${USE_S3}
- AWS_S3_ENDPOINT_URL=${S3_ENDPOINT_URL}
Expand All @@ -43,6 +58,7 @@ services:
- CF_TURNSTILE_SITE_KEY=${CF_TURNSTILE_SITE_KEY}
- CF_TURNSTILE_SECRET_KEY=${CF_TURNSTILE_SECRET_KEY}
depends_on:
- pgbouncer
- db
- redis
celery:
Expand Down
39 changes: 39 additions & 0 deletions test/perf/test-event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import http from 'k6/http';
import { check } from 'k6';
import { uuidv4 } from 'https://jslib.k6.io/k6-utils/1.4.0/index.js';

export let options = {
stages: [
{ duration: '5s', target: 500 }, // ramp-up to 10 users
],
};

export default function () {
// Step 1: Get the CSRF token
let response = http.get('http://localhost:8000/events/perftest');
let csrfToken = response.html().find('input[name="csrfmiddlewaretoken"]').attr('value');

let uuid = uuidv4();

// Step 2: Post the form data with the CSRF token
let formData = {
csrfmiddlewaretoken: csrfToken,
// Add your form fields here
user: 'test',
email: uuid + '@test.datateknologerna.org',
};

let headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Referer': 'http://localhost:8000/events/perftest',
'Cookie': response.headers['Set-Cookie'],
};

let postResponse = http.post('http://localhost:8000/events/perftest/', formData, { headers: headers });

// Step 3: Check the response
check(postResponse, {
'status is 200': (r) => r.status === 200,
// Add more checks as needed
});
}
Loading