Files
awx/awx/main/tests
Seth Foster 2c71bcda32 Improve transactional integrity for starting controller jobs in dispatcherd (#16300)
Remove SELECT FOR UPDATE from job dispatch to reduce transaction rollbacks
                                                                                                                                                                                                                                                                                           
  Move status transition from BaseTask.transition_status (which used
  SELECT FOR UPDATE inside transaction.atomic()) into                                                                                                                                                                                                                                      
  dispatch_waiting_jobs. The new approach uses filter().update() which                                                                                                                                                                                                                     
  is atomic at the database level without requiring explicit row locks,
  reducing transaction contention and rollbacks observed in perfscale
  testing.

  The transition_status method was an artifact of the feature flag era
  where we needed to support both old and new code paths. Since
  dispatch_waiting_jobs is already a singleton
  (on_duplicate='queue_one') scoped to the local node, the
  de-duplication logic is unnecessary.

  Status is updated after task submission to dispatcherd, so the job's
  UUID is in the dispatch pipeline before being marked running —
  preventing the reaper from incorrectly reaping jobs during the
  handoff window. RunJob.run() handles the race where a worker picks
  up the task before the status update lands by accepting waiting and
  transitioning it to running itself.

  Signed-off-by: Seth Foster <fosterbseth@gmail.com>
  Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-26 14:16:36 -05:00
..

Test Environments

Several of the subfolders of awx/main/tests/ indicate a different required environment where you can run the tests. Those folders are:

  • functional/ - requires a test database and no other services running
  • live/ - must run in tools_awx_1 container launched by make docker-compose
  • unit/ - does not require a test database or any active services

Functional and unit test environment

The functional and unit tests have an invocation in make test, and this attaches several other things like schema that piggybacks on requests. These tests are ran from the root AWX folder.

Functional tests

Only tests in the functional/ folder should use the @pytest.mark.django_db decorator. This is the only difference between the functional and unit folders, the test environment is otherwise the same for both.

Functional tests use a sqlite3 database, so the postgres service is not necessary.

Live tests

The live tests have an invocation in make live_test which will change directory before running, which is required to pick up a different pytest configuration.

This will use the postges container from make docker-compose for the database, and will disable the pytest-django features of running with a test database and running tests in transactions. This means that any changes done in the course of the test could potentially be seen in your browser via the API or UI, and anything the test fails to clean up will remain in the database.

Folders that should not contain tests

  • data/ - just files other tests use
  • docs/ - utilities for schema generation
  • factories/ - general utilities
  • manual/ - python files to be ran directly