Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky async sensor test #40813

Merged
merged 1 commit into from
Jul 16, 2024
Merged

Conversation

potiuk
Copy link
Member

@potiuk potiuk commented Jul 16, 2024

I think this one should finally fix the flaky test. The issue with it was that in Pytest parsing the test might occur a long time before executing it - depending how many tests are run between and how slow the test run.

The original test calculated the reference time at parsing time and it assumed on hour ahead (when minutes where 0-ed were enough) for the "deferral" to happen. But if parsing was executed (thus reference time calculation happened) before end of hour and execution after end hour, then the +1 hour from beginning of the reference hour already passed.

The fix is to move the reference time calculation to inside the test, so that it is not calculated a long time before the test is run.

The test runs on public runners are generally slower "per container", that's why it happened more frequently on public runners.


^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.

I think this one should finally fix the flaky test. The issue with
it was that in Pytest parsing the test might occur a long time
before executing it - depending how many tests are run between
and how slow the test run.

The original test calculated the reference time at parsing time and
it assumed on hour ahead (when minutes where 0-ed were enough) for
the "deferral" to happen. But if parsing was executed (thus reference time
calculation happened) before end of hour and execution after end hour,
then the +1 hour from beginning of the reference hour already passed.

The fix is to move the reference time calculation to inside the
test, so that it is not calculated a long time before the test is run.

The test runs on public runners are generally slower "per container",
that's why it happened more frequently on public runners.
@boring-cyborg boring-cyborg bot added the area:core-operators Operators, Sensors and hooks within Core Airflow label Jul 16, 2024
@potiuk
Copy link
Member Author

potiuk commented Jul 16, 2024

I believe I found out why the async parse test was flaky finally @hussein-awala ?

Copy link
Member

@hussein-awala hussein-awala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had this hypothesis yesterday but the date looked good in the failed ci job, but yeah what you describe completes my analysis.

@potiuk potiuk merged commit 4891976 into apache:main Jul 16, 2024
48 checks passed
@potiuk potiuk deleted the fix-time-delta-flaky-test branch July 16, 2024 13:08
@potiuk
Copy link
Member Author

potiuk commented Jul 16, 2024

Yeah. The tests in "Other" run for ~ 11 minutes and this one was somewhere around 90% , so chances to hit this one were quite significant. Plus - when it happened it happend in most of the tests because they were starting around the same time + it seems that for scheduled build in the night it happened always, because the workflow starts at 0:40 and it takes about 10 minutes to start the tests from starting of the CI workflow. 🤯

@potiuk
Copy link
Member Author

potiuk commented Jul 16, 2024

And I think this is what confused me with my initial attempt about add - I noticed the hour difference from what I expected in the test (when I used "show timestamp" in the logs and I assumed it was the side effect of mutating the reference time ...

But in this case it was the TIME that shifted 😱

@ephraimbuddy ephraimbuddy added the changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..) label Jul 23, 2024
@ephraimbuddy ephraimbuddy added this to the Airflow 2.10.0 milestone Jul 23, 2024
romsharon98 pushed a commit to romsharon98/airflow that referenced this pull request Jul 26, 2024
I think this one should finally fix the flaky test. The issue with
it was that in Pytest parsing the test might occur a long time
before executing it - depending how many tests are run between
and how slow the test run.

The original test calculated the reference time at parsing time and
it assumed on hour ahead (when minutes where 0-ed were enough) for
the "deferral" to happen. But if parsing was executed (thus reference time
calculation happened) before end of hour and execution after end hour,
then the +1 hour from beginning of the reference hour already passed.

The fix is to move the reference time calculation to inside the
test, so that it is not calculated a long time before the test is run.

The test runs on public runners are generally slower "per container",
that's why it happened more frequently on public runners.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:core-operators Operators, Sensors and hooks within Core Airflow changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants