Skip to content

Conversation

@khvn26
Copy link
Member

@khvn26 khvn26 commented Jun 5, 2025

This PR is a PoC for the run_tasks fixture.

By default, we run tasks synchronously in tests. However, in order to test complex workflows that require asynchronous processing, we need a way to schedule and run tasks as they would've been run with TASK_PROCESSOR_MODE enabled. The new fixture makes sure TASK_RUN_METHOD is set to TASK_PROCESSOR in the context of a test using it, and allows to run a pre-determined number of tasks to verify their operation.

Usage:

def test_logic_involving_async_processing(run_tasks: RunTasksFixture) -> None:
   # When
   # code scheduling a task is called
   my_logic()

   # Then
   task_runs = run_tasks(num_tasks=1)

   # The task was failed
   assert task_runs[0].result == "FAILURE"

We can probably pack the assertion logic in a fixture as well to allow something like an AssertTaskRunFixture:

def test_logic_involving_async_processing(assert_task_run: AssertTaskRunFixture) -> None:
   # When
   my_logic()

   # Then
   assert_task_run("my_module.my_task", "FAILURE")

@khvn26 khvn26 requested a review from a team as a code owner June 5, 2025 16:44
@khvn26 khvn26 requested review from Zaimwa9 and removed request for a team June 5, 2025 16:44
@codecov-commenter
Copy link

codecov-commenter commented Jun 5, 2025

Codecov Report

Attention: Patch coverage is 74.41860% with 11 lines in your changes missing coverage. Please review.

Project coverage is 94.08%. Comparing base (abec78b) to head (aea8a76).

Files with missing lines Patch % Lines
src/common/test_tools/plugin.py 50.00% 8 Missing ⚠️
src/common/test_tools/types.py 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #85      +/-   ##
==========================================
- Coverage   94.42%   94.08%   -0.35%     
==========================================
  Files          74       73       -1     
  Lines        2208     2232      +24     
==========================================
+ Hits         2085     2100      +15     
- Misses        123      132       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@khvn26 khvn26 merged commit 9bd0855 into main Jun 12, 2025
4 checks passed
This was referenced Jul 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants