treeherder/tests
Joel Maher 23a642030b
Revert "Bug 1851253 - adjust cache code to support two backends in the future. r=aryx (#7837)" (#7840)
This reverts commit 2b28f7e2cc.
2023-10-12 08:58:13 -07:00
..
autoclassify
changelog New Black changes 2023-06-20 10:58:40 +02:00
client Update development dependencies (#7497) 2022-07-27 05:39:45 -07:00
e2e New Black changes 2023-06-20 10:58:40 +02:00
etl Order in tests 2023-08-11 11:45:43 +02:00
intermittents_commenter support marking NEW failures as FC_id=6 (#7691) 2023-05-16 05:41:29 -07:00
jest Use babel config 2022-05-19 15:36:14 +02:00
log_parser store duration along with group status (#7816) 2023-09-28 08:53:09 -07:00
model Fix mitten to work with -cf in the job names (#7810) 2023-09-21 15:43:44 -07:00
perf Enforce querysets order between mysql and psql 2023-08-11 11:45:43 +02:00
perfalert New Black changes 2023-06-20 10:58:40 +02:00
push_health Revert 2 changes to the `push` API endpoint 2023-10-10 17:58:17 +02:00
sample_data Bug 1855919 - Fix the backout policy message to be less aggressive (#7820) 2023-10-05 12:02:38 +03: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 Upgrade Celery to v5 (#7434) 2022-05-05 23:30:20 +02:00
ui Add tests for the Debug Tools column in alerts view (#7731) 2023-09-13 14:37:11 +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 Add TaskclusterMetadata to the alert summary API endpoint (#7740) 2023-09-20 12:43:33 +03:00
README.md add --no-deps to pip install. r=suhaib (#7664) 2023-03-22 10:34:23 -07:00
__init__.py
conftest.py store duration along with group status (#7816) 2023-09-28 08:53:09 -07:00
env.bat
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
settings.py Bug 1849257 - disable django debug toolbar for test execution 2023-08-30 21:46:08 +02:00
test_middleware.py Fix WhiteNoise issues 2023-07-07 00:46:47 +02:00
test_setup.py Revert "Bug 1851253 - adjust cache code to support two backends in the future. r=aryx (#7837)" (#7840) 2023-10-12 08:58:13 -07:00
test_utils.py New Black changes 2023-06-20 10:58:40 +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 --no-deps -r requirements/dev.txt
pip install --no-deps -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 --no-deps -r requirements\dev.txt
pip install --no-deps -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 --no-deps -r requirements/dev.txt
pip install --no-deps -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