Skip to content

Fix flaky test_run_no_log in DbApiHook#63860

Open
henry3260 wants to merge 1 commit intoapache:mainfrom
henry3260:fix-flaky-test_run_no_log
Open

Fix flaky test_run_no_log in DbApiHook#63860
henry3260 wants to merge 1 commit intoapache:mainfrom
henry3260:fix-flaky-test_run_no_log

Conversation

@henry3260
Copy link
Contributor

Why

The previous implementation tried to work around this by using a fragile assertion: assert len(caplog.messages) in [1, 2]. However, this is an anti-pattern for two major reasons:

  1. The previous implementation cannot clearly test what we want to test: By asserting the length of the logs rather than their content, the true intent of the test is obscured. It could theoretically pass even if the target message was never logged
  2. It is also flaky: It still leads to CI failures if multiple background tasks happen to be garbage-collected simultaneously (making the log length 3 or more).

closes: #45774


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TestDbApiHook::test_run_no_log randomly fails

1 participant