treeherder/tests
Kyle Lahnakoski 690010736f
Bug 1631082 - Fix extraction of alerts into BigQuery (#6316)
* add alert tests, fix alert extract

* enable extract testing in travis

Co-authored-by: Kyle Lahnakoski <kyle@lahnakoski.com>
2020-04-17 16:47:24 -04:00
..
autoclassify Bug 1599526 - Push Health handle tasks with timout errors (#5723) 2019-12-12 12:24:22 -08:00
changelog Test integrate black (#6277) 2020-04-08 14:47:37 -04:00
client Bug 1530267 - Remove __future_ imports 2019-02-25 20:39:03 +00:00
e2e Bug 1528811 - Remove job-collection related classes from thclient (#4661) 2019-02-20 06:49:54 +00:00
etl Bug 1603249 - Use taskcluster API to fetch artifacts in UI (#6242) 2020-04-03 11:38:27 -07:00
extract Bug 1631082 - Fix extraction of alerts into BigQuery (#6316) 2020-04-17 16:47:24 -04:00
intermittents_commenter Bug 1526764 - Make test_intermittents_commenter pass under Python 3 (#4615) 2019-02-11 17:51:15 +00:00
log_parser Support test environment outside of Docker container (#5716) 2020-02-05 14:55:03 -05:00
model Bug 1597368 - faster cycle data (#5724) 2019-12-12 19:17:42 -05:00
perfalert Bug 1612547 - Define component for doing backfills using existing reports 2020-04-14 13:02:44 +03:00
push_health Bug 1612224 - Compare current Health push to its parent (#6165) 2020-03-26 16:59:38 -07:00
sample_data Bug 1612547 - Define component for doing backfills using existing reports 2020-04-14 13:02:44 +03:00
selenium Add seed-isort-config hook (#6182) 2020-04-07 08:14:36 -04:00
services Bug 1612547 - Define component for doing backfills using existing reports 2020-04-14 13:02:44 +03:00
seta SETA improvements (#6002) 2020-02-18 11:51:53 -05:00
test_worker Bug 1574651 - ingest from multiple rabbitmq servers (#5399) 2019-10-10 16:53:18 -07:00
ui Bug 1627968 - Rename Health view to Tests view 2020-04-13 09:31:24 +03:00
utils Bug 1612547 - Define component for doing backfills using existing reports 2020-04-14 13:02:44 +03:00
webapp Bug 1611334 - Remove support for GraphQL (#6235) 2020-04-07 17:36:57 -04:00
README.md Reduce list of Python requirements (#6141) 2020-04-07 14:40:36 -04:00
__init__.py fix RefDataManager and add firts working test on it 2013-04-17 17:13:24 +01:00
conftest.py Bug 1603249 - Use taskcluster API to fetch artifacts in UI (#6242) 2020-04-03 11:38:27 -07:00
env.bat Bug 1610347 - Extract jobs/perf/alert to BigQuery (#5839) 2020-02-06 13:16:26 -05:00
sample_data_generator.py Bug 1530267 - Remove __future_ imports 2019-02-25 20:39:03 +00:00
sampledata.py Bug 1611334 - Remove support for GraphQL (#6235) 2020-04-07 17:36:57 -04:00
settings.py Bug 1612229 - Push Health Usage Dashboard (#6137) 2020-03-16 14:25:11 -07:00
test_middleware.py Bug 1530602 - Adjust Content-Security-Policy to fix ajv.compile() (#4703) 2019-02-26 08:04:53 +00:00
test_setup.py Bug 1616975 - Create a unified changelog (#5949) 2020-03-13 13:27:12 -07:00
test_utils.py Bug 1295997 - Skip parsing logs whose compressed size exceeds 5MB (#4700) 2019-02-25 19:04:38 +00:00

README.md

Backend development

The backend test suite can be run outside the Docker container.

Start the services

We need all but the main backend service running. Since multiple backend instances are allowed, we will simply start everything up

# ENSURE THE IMAGES ARE CLEAN
docker rm "/mysql"
docker rm "/frontend"
docker rm "/rabbitmq" 
docker rm "/redis"
docker rm "/backend"
docker-compose down
docker volume rm treeherder_mysql_data 

# SETUP ALL IMAGES
docker-compose up --build

Install into virtual environment

Treeherder requires specific library versions that will likely interfere with what you have installed. It is best to setup a virtual environment to contain the quirks it introduces.

Be sure you are in the treeherder main directory

python -m venv .venv             # IMPORTANT: Notice the dot in the name
source .venv/bin/activate
pip install -r requirements/dev.txt
pip install -r requirements/common.txt

...or Windows...

python -m pip install virtualenv
rem IMPORTANT: Notice the dot in `.venv`
python -m virtualenv .venv             
.venv\Scripts\activate
pip install -r requirements\dev.txt
pip install -r requirements\common.txt

The pip install order is important: We want the common requirements to overwrite the dev requirements (in the event there are conflicts)

Set environment variables

For Windows, Treeherder requires a number of environment variables that point to the services. In our case, those services are in local docker containers.

.\tests\env.bat

If you plan to use an IDE, here is the same, as a very long line

BROKER_URL=localhost//guest:guest@rabbitmq//;DATABASE_URL=mysql://root@localhost:3306/treeherder;REDIS_URL=redis://localhost:6379;SITE_URL=http://backend:8000/;TREEHERDER_DEBUG=True;TREEHERDER_DJANGO_SECRET_KEY=secret-key-of-at-least-50-characters-to-pass-check-deploy;NEW_RELIC_DEVELOPER_MODE=True

Ensure everything is working

Django can perform a number of checks to ensure you are configured correctly

./manage.py check

Run the tests

Be sure docker-compose is up, you are in the treeherder main directory, your virtual environment is activated, and your environment variables are set:

source .venv/bin/activate
pytest tests

Pre commit checks

If you made some changes, and want to submit a pull request; run the ./runtests.sh script (found in the main directory). It will run some linters to check your submission.

For Windows, you can run the checks in a container (see below)

Run tests in container

After docker-compose up, you may spin up any number of backend containers. You may want to run ingestion tasks, go exploring, or run the tests.

docker-compose exec backend bash

docker-compose has three execution modes

  • exec - run just the service, and assume the others are running
  • run - run all the services, but do not open their ports
  • up - run all the services with ports open

More can be read here: docker-composes up vs run vs exec

Inside this container

pytest tests

Setup git pre-commit hook

Running checks locally will allow you to catch linting errors faster. We put the git pre-commit hook into the virtual environment to avoid polluting your dev machine

.venv\Scripts\activate
pip install pre-commit
pre-commit install