treeherder/tests
Kyle Lahnakoski 0fe0362759
Use pip-tools for requirements (#6140)
* update imports, add pip-tools

* first compiled output

* add *.in files (copy of *.txt)

* common.txt from master

* update *.in

* allow upgrade on big-query requirements.txt

* run --upgrade

* example upgrade

* docs

* fix install order

* show how to slim requirements/common.in

* isort

* slim common.in

* isort

* run pip-compile

* fix formatting

* ensure requirements/common.txt is installed last

Co-authored-by: Kyle Lahnakoski <kyle@lahnakoski.com>
2020-04-01 08:15:15 -04:00
..
autoclassify Bug 1599526 - Push Health handle tasks with timout errors (#5723) 2019-12-12 12:24:22 -08:00
changelog Bug 1616975 - Create a unified changelog (#5949) 2020-03-13 13:27:12 -07: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 1509181 - Fix ingestion of GitHub pushes (#6065) 2020-02-28 09:10:52 -05:00
extract Update hashes, fix docker isort, more docs (#6199) 2020-03-30 15:40:42 -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 1571369 - Store backfill reports per alert summary (#5539) 2019-11-14 08:29:55 -05:00
push_health Bug 1612224 - Compare current Health push to its parent (#6165) 2020-03-26 16:59:38 -07:00
sample_data Bug 1612229 - Push Health Usage Dashboard (#6137) 2020-03-16 14:25:11 -07:00
selenium Bug 1618889 - Remove reduntant Selenium Graphs view tests 2020-03-17 13:13:11 +02:00
services Support test environment outside of Docker container (#5716) 2020-02-05 14:55:03 -05: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 1612224 - Compare current Health push to its parent (#6165) 2020-03-26 16:59:38 -07:00
utils Add chunked_qs_reverse function 2018-05-04 08:57:50 +01:00
webapp Bug 1612224 - Compare current Health push to its parent (#6165) 2020-03-26 16:59:38 -07:00
README.md Use pip-tools for requirements (#6140) 2020-04-01 08:15:15 -04:00
__init__.py fix RefDataManager and add firts working test on it 2013-04-17 17:13:24 +01:00
conftest.py Bug 1612224 - Compare current Health push to its parent (#6165) 2020-03-26 16:59:38 -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 1395254 - Consume Taskcluster Pulse messages from standard queue exchanges 2019-07-29 09:42: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 -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