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

[Feature] Add a way to test cancellation where the query still completes #299

Open
cleroux opened this issue Aug 25, 2022 · 0 comments · May be fixed by #300
Open

[Feature] Add a way to test cancellation where the query still completes #299

cleroux opened this issue Aug 25, 2022 · 0 comments · May be fixed by #300

Comments

@cleroux
Copy link

cleroux commented Aug 25, 2022

Hi! Thank you for this useful library!

With regard to cancelling queries in Postgres, through context cancellation or other mechanism like pg_cancel_backend(), Postgres provides no guarantee that the query will actually be cancelled, and therefore might still complete normally.

From Postgres docs:

The cancellation signal might or might not have any effect — for example, if it arrives after the backend has finished processing the query, then it will have no effect. If the cancellation is effective, it results in the current command being terminated early with an error message.

At the moment, sqlmock will always produce an error if we cancel the context passed into it.

In a highly concurrent system that supports query cancellation, we have observed this edge case happening often enough that we would like to test for it. So it would be nice if we could set up this scenario where the context is cancelled but sqlmock does not produce an error.

I hope to hear your opinion on this. If this sounds reasonable, I may be able to submit a PR. Though I admit I have not dived into the implementation of sqlmock to know how complex this might be.

Proposal

Perhaps something like .WillCompleteOnCancel().WillReturnRows(rows)

Use-cases

I would like to be able to test the case where the query might complete without error when the context is cancelled.

@cleroux cleroux linked a pull request Aug 26, 2022 that will close this issue
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 a pull request may close this issue.

1 participant