Skip to content

Make DelayedConstraint work with ThrowsContraint - #4815

Merged
stevenaw merged 1 commit into
nunit:mainfrom
Dreamescaper:make_delayed_work_with_throws
Sep 6, 2024
Merged

Make DelayedConstraint work with ThrowsContraint#4815
stevenaw merged 1 commit into
nunit:mainfrom
Dreamescaper:make_delayed_work_with_throws

Conversation

@Dreamescaper

Copy link
Copy Markdown
Member

Fixes #4281.

Previously, DelayedConstraint would execute the delegate by itself. However, underlying contraints might have additional logic for delegate handling - like ThrowsConstraint, which catches the exception.

Therefore, the fix is to pass the delegate to the constraint instead of executing it.

This fix has a change in the behavior. Currently, the test would fail if the delegate throws an exception. Now, since the delegate is invoked inside of try-catch block, it would be retried (for all constraints, not only Throws ones).
In my opinion, that's an expected behavior.
Still, let me know if you have any concerns.

@manfred-brands manfred-brands left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@Dreamescaper Thanks. Looks good and a simple change.

@stevenaw stevenaw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for spotting this and contributing the fix @Dreamescaper !
I agree, the change in behaviour here is correcting an unwanted one (a bug) which is a good thing

@stevenaw
stevenaw merged commit 0928fb1 into nunit:main Sep 6, 2024
@Dreamescaper
Dreamescaper deleted the make_delayed_work_with_throws branch September 6, 2024 12:51
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.

Throws and Delayed (.After) Constraints do not cooperate, resulting in incorrectly failing test

3 participants