mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 01:41:48 -06:00
Merge pull request #29776 from hashicorp/alisdair/fix-flaky-init-cancel-test
cli: Fix flaky init cancel test
This commit is contained in:
commit
1bc3e593f5
@ -1372,14 +1372,12 @@ func TestInit_cancel(t *testing.T) {
|
|||||||
defer os.RemoveAll(td)
|
defer os.RemoveAll(td)
|
||||||
defer testChdir(t, td)()
|
defer testChdir(t, td)()
|
||||||
|
|
||||||
providerSource, closeSrc := newMockProviderSource(t, map[string][]string{
|
// Use a provider source implementation which is designed to hang indefinitely,
|
||||||
"test": {"1.2.3", "1.2.4"},
|
// to avoid a race between the closed shutdown channel and the provider source
|
||||||
"test-beta": {"1.2.4"},
|
// operations.
|
||||||
"source": {"1.2.2", "1.2.3", "1.2.1"},
|
providerSource := &getproviders.HangingSource{}
|
||||||
})
|
|
||||||
defer closeSrc()
|
|
||||||
|
|
||||||
// our shutdown channel is pre-closed so init will exit as soon as it
|
// Our shutdown channel is pre-closed so init will exit as soon as it
|
||||||
// starts a cancelable portion of the process.
|
// starts a cancelable portion of the process.
|
||||||
shutdownCh := make(chan struct{})
|
shutdownCh := make(chan struct{})
|
||||||
close(shutdownCh)
|
close(shutdownCh)
|
||||||
@ -1401,7 +1399,7 @@ func TestInit_cancel(t *testing.T) {
|
|||||||
args := []string{}
|
args := []string{}
|
||||||
|
|
||||||
if code := c.Run(args); code == 0 {
|
if code := c.Run(args); code == 0 {
|
||||||
t.Fatalf("succeeded; wanted error")
|
t.Fatalf("succeeded; wanted error\n%s", ui.OutputWriter.String())
|
||||||
}
|
}
|
||||||
// Currently the first operation that is cancelable is provider
|
// Currently the first operation that is cancelable is provider
|
||||||
// installation, so our error message comes from there. If we
|
// installation, so our error message comes from there. If we
|
||||||
|
29
internal/getproviders/hanging_source.go
Normal file
29
internal/getproviders/hanging_source.go
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package getproviders
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/internal/addrs"
|
||||||
|
)
|
||||||
|
|
||||||
|
// HangingSource is an implementation of Source which hangs until the given
|
||||||
|
// context is cancelled. This is useful only for unit tests of user-controlled
|
||||||
|
// cancels.
|
||||||
|
type HangingSource struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ Source = (*HangingSource)(nil)
|
||||||
|
|
||||||
|
func (s *HangingSource) AvailableVersions(ctx context.Context, provider addrs.Provider) (VersionList, Warnings, error) {
|
||||||
|
<-ctx.Done()
|
||||||
|
return nil, nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *HangingSource) PackageMeta(ctx context.Context, provider addrs.Provider, version Version, target Platform) (PackageMeta, error) {
|
||||||
|
<-ctx.Done()
|
||||||
|
return PackageMeta{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *HangingSource) ForDisplay(provider addrs.Provider) string {
|
||||||
|
return "hanging source"
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user