Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.

Commit f3d5017

Browse files
authored
Add stress-test with locustio (#64)
* Add load tests * Fix lint errors * Add load tests file to codecov ignore
1 parent 5f144e7 commit f3d5017

File tree

7 files changed

+33
-18
lines changed

7 files changed

+33
-18
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Automatic installation of the project with docker, for development.
4646

4747
There is already tests for the `server` and the `client`, we currently at **+90** percent coverage.
4848

49-
We also write some tests for doing load test with [locust](http://locust.io/), you can find it under `server/stress_tests/`. To do a load test just install locust and write
49+
We also write some tests for doing load test with [locust](http://locust.io/), you can find it under `server/locustfile.py`. To do a load test just install locust (it's in the `requirements.txt` file) go to `server` directory and
5050

5151
```
5252
locust --host=http://localhost

codecov.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ parsers:
3333
ignore:
3434
- "server/manage.py"
3535
- "server/config"
36+
- "server/locustfile"
3637
- "server/**/apps.py"

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ services:
5454
ports:
5555
- "8000:8000"
5656
environment:
57+
- DEBUG=False
5758
- DB_HOST=database
5859
- DB_NAME=server
5960
- DB_USER=nirgalon
6061
- DB_PASS=Zaq1234
62+
- SECRET_KEY=-#&29$$6a5n)za$$%q-9di^$$lxu5bvo!so=0e$$anel3o7^3oscz6
6163
command: bash -c "/home/app/server/entrypoint.sh && gunicorn config.wsgi -b 0.0.0.0:8000"
6264
deploy:
6365
replicas: 2

server/config/local_settings.template

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
1-
import os
2-
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
3-
41
# Enable debug trace.
52
DEBUG = True
63

7-
# SECURITY WARNING: keep the secret key used in production secret!
8-
SECRET_KEY = '{{secret_key}}'
9-
10-
# Static files (CSS, JavaScript, Images)
11-
# https://docs.djangoproject.com/en/1.10/howto/static-files/
12-
STATIC_URL = '/static/'
13-
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
14-
MEDIA_URL = '/staticuploads/'
15-
MEDIA_ROOT = os.path.join(BASE_DIR, 'staticuploads')
16-
174
DATABASES = {
185
'default': {
196
'ENGINE': 'django.db.backends.postgresql_psycopg2',

server/config/settings.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
2121

2222
# SECURITY WARNING: keep the secret key used in production secret!
23-
SECRET_KEY = '-#&29$6a5n)za$%q-9di^$lxu5bvo!so=0e$anel3o7^3oscz6'
23+
SECRET_KEY = os.environ.get('SECRET_KEY', True)
2424

2525
# SECURITY WARNING: don't run with debug turned on in production!
26-
DEBUG = True
26+
DEBUG = os.environ.get('DEBUG', False)
2727

2828
ALLOWED_HOSTS = []
2929

@@ -35,14 +35,13 @@
3535
# Application definition
3636
INSTALLED_APPS = [
3737
'api',
38-
38+
'flat_responsive',
3939
'django.contrib.admin',
4040
'django.contrib.auth',
4141
'django.contrib.contenttypes',
4242
'django.contrib.sessions',
4343
'django.contrib.messages',
4444
'django.contrib.staticfiles',
45-
4645
'admin_honeypot',
4746
'django_extensions',
4847
'rest_framework',

server/locustfile.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from locust import HttpLocust, TaskSet, task
2+
3+
4+
class UserBehavior(TaskSet):
5+
# def on_start(self):
6+
# """ on_start is called when a Locust start before any task is scheduled """
7+
# self.login()
8+
9+
# def login(self):
10+
# self.client.post("/login", {"username":"ellen_key", "password":"education"})
11+
12+
@task(1)
13+
def users(self):
14+
self.client.get('/api/users')
15+
16+
17+
class WebsiteUser(HttpLocust):
18+
task_set = UserBehavior
19+
min_wait = 5000
20+
max_wait = 9000

server/requirements.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ psycopg2==2.7.1
55
django-extensions==1.8.1
66
gunicorn==19.7.1
77

8+
# Admin
9+
django-flat-responsive==1.4.1
10+
811
# Security
912
django-admin-honeypot==1.0.0
1013

@@ -18,3 +21,6 @@ django-cors-headers==2.1.0
1821

1922
# Logging
2023
python-logstash==0.4.6
24+
25+
# Testing
26+
locustio==0.8a2

0 commit comments

Comments
 (0)