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 test_recover_from_resource_too_old exception #28475

Merged
merged 1 commit into from
Dec 19, 2022

Conversation

potiuk
Copy link
Member

@potiuk potiuk commented Dec 19, 2022

After #28047 the test_recover_from_resource_too_old started to fail in a flaky way. Turned out that - depend on some other test run the Singleton ResourceVersion could containt not one but two namespaces (including default namespace).

Also while fixing the tests it's been noticed that the test missed an assert - it did not assert that the Exception was in fact thrown, so the test could have succeeded even if the exception was not really thrown (there was assert in "except" clause but if the exception was not thrown, it would not have been called at all).


^ 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.

@boring-cyborg boring-cyborg bot added the area:Scheduler including HA (high availability) scheduler label Dec 19, 2022
@potiuk potiuk force-pushed the fix-failing-resource-version-test branch from 9c7e6fa to 1d80b80 Compare December 19, 2022 19:39
@potiuk potiuk changed the title Fixed flaky Resource exception Fixed flaky test_recover_from_resource_too_old exception Dec 19, 2022
@potiuk potiuk changed the title Fixed flaky test_recover_from_resource_too_old exception Fix flaky test_recover_from_resource_too_old exception Dec 19, 2022
After apache#28047 the test_recover_from_resource_too_old started to
fail in a flaky way. Turned out that - depend on some other test
run the Singleton ResourceVersion could containt not one but
two namespaces (including default namespace).

Also while fixing the tests it's been noticed that the test
missed an assert - it did not assert that the Exception was in fact
thrown, so the test could have succeeded even if the exception was
not really thrown (there was assert in "except" clause but if the
exception was not thrown, it would not have been called at all).
@potiuk potiuk force-pushed the fix-failing-resource-version-test branch from 1d80b80 to a72c542 Compare December 19, 2022 19:41
@@ -1249,12 +1249,13 @@ def effect():
try:
# self.watcher._run() is mocked and return "500" as last resource_version
self.watcher.run()
assert False, "Should have raised Exception"
Copy link
Member

Choose a reason for hiding this comment

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

The change in line 1258 is all good to me.
But is this change at line 1252 necessary? I don't fully get it yet . The watcher is already mocked and will fail

Copy link
Member Author

Choose a reason for hiding this comment

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

This is just consistency change. The author actually expected the sentinel exception (and it's the one that is raised form the watcher to break the loop) but the path when (potentially) no exception is thrown would not run this assert:

except Exception as e:
                assert e.args == ("sentinel",)

Sure, we know what happens inside the run method and by inspecting it, we know it is not going to happen most likely - because exception is the only way to get out of the loop. But ... this might change in the future.

Not likely and stupid example but if someonedoes fast "return 0" in the watcher.run() - the test would have succeeded as well (no exception and resource = 0, assert e.args == ("sentinel", ) would have not been called).

Adding the assert simply makes absolutely sure that the exception was thrown (because otherwise assert would fail). That's the usual pattern :)

@potiuk potiuk merged commit 0311ac9 into apache:main Dec 19, 2022
@potiuk potiuk deleted the fix-failing-resource-version-test branch December 19, 2022 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:Scheduler including HA (high availability) scheduler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants