pulumi/pkg/engine/lifecycletest
Eron Wright fb28ab7592
ctrl-c should cause Pulumi to call Cancel operation on providers (#14057)
<!--- 
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->

# Description
Fixes #14054

This PR fixes a problem that the engine cannot forward a cancellation
signal to the provider, because the plugin context is already closed. An
[earlier
commit](a9ae602867)
made the plugin context be closed too eagerly, with the intent of
cancelling plugin installation. This PR attempts to decouple the
cancellation of plugin installation from the lifecycle of the plugin
context, so that plugin installation may be cancelled during the
cancelation phase as opposed to the termination phase. Then, it closes
the plugin context in termination phase.

There's an existing test case in the engine lifecycle tests called
`TestProviderCancellation`, but it didn't catch the problem because it
uses a fake plugin host that behaves differently after being closed. The
issue was fixed in https://github.com/pulumi/pulumi/pull/14063 and the
test was temporarily disabled. This PR re-enables the test case.

A new test case `TestSourceFuncCancellation` is added to test
cancellation of the source func (where plugin installation happens, see
[update.go](https://github.com/pulumi/pulumi/pull/14057/files#diff-7d2ca3e83a05073b332435271496050e28466b4f7af8c0c91bbc77947a75a3a2R378)),
as this was the original motivation of
a9ae602867.

## Checklist

- [x] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
  - [ ] I have formatted my code using `gofumpt`

<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [x] I have added tests that prove my fix is effective or that my
feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] ~Yes, there are changes in this PR that warrants bumping the
Pulumi Cloud API version~
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2023-09-29 22:12:35 +00:00
..
alias_test.go Lifecycle tests shouldn't use a closed host (#14063) 2023-09-28 21:50:18 +00:00
analyzer_test.go Lifecycle tests shouldn't use a closed host (#14063) 2023-09-28 21:50:18 +00:00
delete_before_replace_test.go Lifecycle tests shouldn't use a closed host (#14063) 2023-09-28 21:50:18 +00:00
golang_sdk_test.go Lifecycle tests shouldn't use a closed host (#14063) 2023-09-28 21:50:18 +00:00
import_test.go Lifecycle tests shouldn't use a closed host (#14063) 2023-09-28 21:50:18 +00:00
pending_delete_test.go Lifecycle tests shouldn't use a closed host (#14063) 2023-09-28 21:50:18 +00:00
provider_test.go Lifecycle tests shouldn't use a closed host (#14063) 2023-09-28 21:50:18 +00:00
pulumi_test.go ctrl-c should cause Pulumi to call Cancel operation on providers (#14057) 2023-09-29 22:12:35 +00:00
refresh_test.go ctrl-c should cause Pulumi to call Cancel operation on providers (#14057) 2023-09-29 22:12:35 +00:00
resource_reference_test.go Lifecycle tests shouldn't use a closed host (#14063) 2023-09-28 21:50:18 +00:00
step_generator_test.go Lifecycle tests shouldn't use a closed host (#14063) 2023-09-28 21:50:18 +00:00
target_test.go Lifecycle tests shouldn't use a closed host (#14063) 2023-09-28 21:50:18 +00:00
test_plan.go Lifecycle tests shouldn't use a closed host (#14063) 2023-09-28 21:50:18 +00:00
update_plan_test.go Lifecycle tests shouldn't use a closed host (#14063) 2023-09-28 21:50:18 +00:00