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

Add WillCompleteOnCancel expectation #300

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

cleroux
Copy link

@cleroux cleroux commented Aug 26, 2022

Closes #299

I nerd-sniped myself after writing up the issue and started looking into the code. Turned out to be pretty straight-forward. So here's a PR! I hope you think it's useful. If you decide to merge this I would certainly pull this update and use this feature to write some new tests.

The goal of .WillCompleteOnCancel() is to be able to test a pretty rare edge case in Postgres (and maybe other databases?) where the Go context is cancelled but due to timing, may not succeed in actually cancelling the query. In this case the query completes without error, and functions like QueryContext() et al. do not return the "context canceled" error we normally expect.

This change is fully backward-compatible. There is no change to the default behavior which is to return ErrCancelled when the context is cancelled.

Allows setting up the scenario where the context is cancelled but the database still completes the query without error. Some databases (eg. Postgres) do not guarantee that a query will be cancelled when the cancellation signal is sent.
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.

[Feature] Add a way to test cancellation where the query still completes
1 participant