treeherder/tests
Joel Maher 6f19e70342
pin version of click used by black to avoid missing reference to _unicodefunc. (#7412)
2022-03-30 11:57:48 -07:00
..
autoclassify Bug 1594822 - Remove Autoclassify and Crossreference without migration (#6915) 2020-12-15 11:08:07 -08:00
changelog Test integrate black (#6277) 2020-04-08 14:47:37 -04:00
client Apply black formating to the whole repo (#6332) 2020-04-21 10:35:59 -04:00
e2e Bug 1704311 - Bugscache changes (#7100) 2021-04-13 10:54:31 -07:00
etl Bug 1754464 - Store some failures classification from mozci as FailureClassification (#7406) 2022-03-23 09:20:44 -07:00
intermittents_commenter Bug 1496319 - add build type to IFV bot comments (#6961) 2021-01-19 15:37:37 -08:00
log_parser pin version of click used by black to avoid missing reference to _unicodefunc. (#7412) 2022-03-30 11:57:48 -07:00
model Bug 1752531 - Fix failing test (#7369) 2022-02-02 17:21:21 +02:00
perf Bug 1759702 - Add noise profile to sort criteria (#7409) 2022-03-18 10:56:34 +02:00
perfalert Bug 1740450 - Wrong improvement status of regression alerts (#7313) 2021-11-12 15:59:59 +02:00
push_health Revert "Bug 1626746 - Push health use mozci on backend (#6763)" (#7133) 2021-05-06 19:15:46 -07:00
sample_data Bug 1720181 - migration to remove SETA table (#7371) 2022-01-31 13:06:15 -08:00
services Bug 1746622 - Listen to mozci classification pulse messages and save results in Treeherder database (#7356) 2022-02-07 09:27:51 -08:00
test_worker Apply black formating to the whole repo (#6332) 2020-04-21 10:35:59 -04:00
ui Bug 1761776 - Added fxrecord framework (#7411) 2022-03-29 09:25:59 +03:00
utils Bug 1746622 - Listen to mozci classification pulse messages and save results in Treeherder database (#7356) 2022-02-07 09:27:51 -08:00
webapp Bug 1755460 - Exclude the results where should_alert is False (#7405) 2022-03-08 10:00:29 +02:00
README.md Fix logging for extraction code (#6622) 2020-07-17 14:02:32 -04:00
__init__.py fix RefDataManager and add firts working test on it 2013-04-17 17:13:24 +01:00
conftest.py Bug 1754464 - Store some failures classification from mozci as FailureClassification (#7406) 2022-03-23 09:20:44 -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 pin version of click used by black to avoid missing reference to _unicodefunc. (#7412) 2022-03-30 11:57:48 -07:00
sampledata.py Apply black formating to the whole repo (#6332) 2020-04-21 10:35:59 -04:00
settings.py Re-re-re-remove activedata and bigquery (#7056) 2021-03-23 09:15:32 -04: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 Remove heroku v2 (#7271) 2021-09-16 11:30:12 +01:00
test_utils.py Bug 1570906 - Don't alert on Tier 3 perf jobs 2021-03-24 09:03:59 +02: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  # venv is buggy on Windows
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

... or MacOS

python -m venv .venv             # IMPORTANT: Notice the dot in the name
source .venv/bin/activate
export LDFLAGS=-L/usr/local/opt/openssl/lib   # https://github.com/PyMySQL/mysqlclient-python/issues/131#issuecomment-503644579
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

Running 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:

Linux/MacOS

source .venv/bin/activate

Windows

.venv\Script\activate

Followed by either one of the two commands below.

All tests

pytest tests

Start TDD-enhanced test runner in the background

Whenever code changes are detected within the project, command below will run only the associated tests. Test runs will be triggered for either application or tests code changes.

This workflow ensures a considerably faster feedback loop for those wanting to do test driven development.

ptw --runner "pytest --testmon" --clear

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