Skip to content

Share router and worker test setup through scenario builders and fixtures #884

Description

@bencap

Problem

Router and worker tests re-type the same setup, and the copies have drifted.

  • 129 of 706 router tests spell out create_experiment → create_seq_score_set → mock_worker_variant_insertion → publish_score_set inline. No helper builds a published score set with variants.
  • publish_score_set (tests/helpers/util/score_set.py) doesn't patch the job queue, so all 195 call sites wrap it in their own patch.object(ArqRedis, "enqueue_job"). 107 assert assert_called_once() and 88 don't, and the patch target is spelled two ways.
  • send_slack_job_error is patched 42 times in 11 files, none of them in a conftest.
  • The same Variant → MappedVariant block appears 22 times in 5 worker test files.
  • Tests use three worker contexts, none shaped like production's standalone_ctx() (worker/settings/lifecycle.py). mock_worker_ctx (tests/worker/conftest_optional.py, 641 references) has no "state", so the job-log write guarded in worker/lib/decorators/job_management.py is skipped in every test that uses it.

Scope

  • A published_score_set_with_variants scenario builder in tests/builders/scenarios.py, built through the routes per Build DB test objects with factory_boy and side-effecting ones with HTTP scenario builders #782, returning a dataclass handle.
  • publish_score_set patches the queue itself and returns the mock.
  • Fixtures for the job queue and for send_slack_job_error, replacing per-test patches as tests are touched.
  • One worker context fixture with production's keys (pool, redis, hdp, state), replacing the three.
  • A MappedVariant factory replacing the 22 inline blocks.

Acceptance criteria

  • The scenario builder and fixtures exist, and test_collections.py and test_experiments.py use them in place of inline setup.
  • The worker context fixture matches standalone_ctx()'s keys, and a test asserts the job log is written.
  • No worker test builds a MappedVariant inline.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app: backendTask implementation touches the backend

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions