From 6e9fc12b080677f8a267711763492f5b67241e4f Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Thu, 4 Apr 2019 14:24:39 -0700 Subject: [PATCH] Remove extraneous contexts from tests --- .../vagrant/plugin/capabilities_test.go | 74 +++----- ext/go-plugin/vagrant/plugin/config_test.go | 53 +++--- ext/go-plugin/vagrant/plugin/provider_test.go | 163 ++++++------------ ext/go-plugin/vagrant/plugin/synced_folder.go | 4 +- .../vagrant/plugin/synced_folder_test.go | 117 +++++-------- 5 files changed, 145 insertions(+), 266 deletions(-) diff --git a/ext/go-plugin/vagrant/plugin/capabilities_test.go b/ext/go-plugin/vagrant/plugin/capabilities_test.go index 26438e3dd..583de5510 100644 --- a/ext/go-plugin/vagrant/plugin/capabilities_test.go +++ b/ext/go-plugin/vagrant/plugin/capabilities_test.go @@ -5,8 +5,6 @@ import ( "testing" "time" - "golang.org/x/sync/errgroup" - "github.com/hashicorp/go-plugin" "github.com/hashicorp/vagrant/ext/go-plugin/vagrant" ) @@ -134,15 +132,13 @@ func TestCapabilities_GuestCapability_context_cancel(t *testing.T) { args := []string{"pause", "test_value", "next_test_value"} ctx, cancel := context.WithCancel(context.Background()) - g, _ := errgroup.WithContext(ctx) defer cancel() - g.Go(func() (err error) { - _, err = impl.GuestCapability(ctx, cap, args, m) - return - }) - time.Sleep(2 * time.Millisecond) - cancel() - if g.Wait() != context.Canceled { + go func() { + time.Sleep(2 * time.Millisecond) + cancel() + }() + _, err = impl.GuestCapability(ctx, cap, args, m) + if err != context.Canceled { t.Fatalf("bad resp: %s", err) } } @@ -168,14 +164,10 @@ func TestCapabilities_GuestCapability_context_timeout(t *testing.T) { m := &vagrant.Machine{} args := []string{"pause", "test_value", "next_test_value"} - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Millisecond) - g, _ := errgroup.WithContext(ctx) + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Millisecond) defer cancel() - g.Go(func() (err error) { - _, err = impl.GuestCapability(ctx, cap, args, m) - return - }) - if g.Wait() != context.DeadlineExceeded { + _, err = impl.GuestCapability(ctx, cap, args, m) + if err != context.DeadlineExceeded { t.Fatalf("bad resp: %s", err) } } @@ -303,15 +295,13 @@ func TestCapabilities_HostCapability_context_cancel(t *testing.T) { args := []string{"pause", "test_value", "next_test_value"} ctx, cancel := context.WithCancel(context.Background()) - g, _ := errgroup.WithContext(ctx) defer cancel() - g.Go(func() (err error) { - _, err = impl.HostCapability(ctx, cap, args, e) - return - }) - time.Sleep(2 * time.Millisecond) - cancel() - if g.Wait() != context.Canceled { + go func() { + time.Sleep(2 * time.Millisecond) + cancel() + }() + _, err = impl.HostCapability(ctx, cap, args, e) + if err != context.Canceled { t.Fatalf("bad resp: %s", err) } } @@ -337,14 +327,10 @@ func TestCapabilities_HostCapability_context_timeout(t *testing.T) { e := &vagrant.Environment{} args := []string{"pause", "test_value", "next_test_value"} - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Millisecond) - g, _ := errgroup.WithContext(ctx) + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Millisecond) defer cancel() - g.Go(func() (err error) { - _, err = impl.HostCapability(ctx, cap, args, e) - return - }) - if g.Wait() != context.DeadlineExceeded { + _, err = impl.HostCapability(ctx, cap, args, e) + if err != context.DeadlineExceeded { t.Fatalf("bad resp: %s", err) } } @@ -472,15 +458,13 @@ func TestCapabilities_ProviderCapability_context_cancel(t *testing.T) { args := []string{"pause", "test_value", "next_test_value"} ctx, cancel := context.WithCancel(context.Background()) - g, _ := errgroup.WithContext(ctx) defer cancel() - g.Go(func() (err error) { - _, err = impl.ProviderCapability(ctx, cap, args, m) - return - }) - time.Sleep(2 * time.Millisecond) - cancel() - if g.Wait() != context.Canceled { + go func() { + time.Sleep(2 * time.Millisecond) + cancel() + }() + _, err = impl.ProviderCapability(ctx, cap, args, m) + if err != context.Canceled { t.Fatalf("bad resp: %s", err) } } @@ -506,14 +490,10 @@ func TestCapabilities_ProviderCapability_context_timeout(t *testing.T) { m := &vagrant.Machine{} args := []string{"pause", "test_value", "next_test_value"} - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Millisecond) - g, _ := errgroup.WithContext(ctx) + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Millisecond) defer cancel() - g.Go(func() (err error) { - _, err = impl.ProviderCapability(ctx, cap, args, m) - return - }) - if g.Wait() != context.DeadlineExceeded { + _, err = impl.ProviderCapability(ctx, cap, args, m) + if err != context.DeadlineExceeded { t.Fatalf("bad resp: %s", err) } } diff --git a/ext/go-plugin/vagrant/plugin/config_test.go b/ext/go-plugin/vagrant/plugin/config_test.go index 10d2975ec..2100123c2 100644 --- a/ext/go-plugin/vagrant/plugin/config_test.go +++ b/ext/go-plugin/vagrant/plugin/config_test.go @@ -5,8 +5,6 @@ import ( "testing" "time" - "golang.org/x/sync/errgroup" - "github.com/hashicorp/go-plugin" "github.com/hashicorp/vagrant/ext/go-plugin/vagrant" ) @@ -84,14 +82,9 @@ func TestConfigPlugin_Load_context_timeout(t *testing.T) { } data := map[string]interface{}{"pause": true} - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Millisecond) + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Millisecond) defer cancel() - n := make(chan struct{}) - go func() { - _, err = impl.ConfigLoad(ctx, data) - n <- struct{}{} - }() - <-n + _, err = impl.ConfigLoad(ctx, data) if err != context.DeadlineExceeded { t.Fatalf("bad resp: %s", err) } @@ -114,15 +107,13 @@ func TestConfigPlugin_Load_context_cancel(t *testing.T) { data := map[string]interface{}{"pause": true} ctx, cancel := context.WithCancel(context.Background()) - g, _ := errgroup.WithContext(ctx) defer cancel() - g.Go(func() (err error) { - _, err = impl.ConfigLoad(ctx, data) - return - }) - time.Sleep(2 * time.Millisecond) - cancel() - if g.Wait() != context.Canceled { + go func() { + time.Sleep(2 * time.Millisecond) + cancel() + }() + _, err = impl.ConfigLoad(ctx, data) + if err != context.Canceled { t.Fatalf("bad resp: %s", err) } } @@ -176,15 +167,13 @@ func TestConfigPlugin_Validate_context_cancel(t *testing.T) { machine := &vagrant.Machine{} ctx, cancel := context.WithCancel(context.Background()) - g, _ := errgroup.WithContext(ctx) defer cancel() - g.Go(func() (err error) { - _, err = impl.ConfigValidate(ctx, data, machine) - return - }) - time.Sleep(2 * time.Millisecond) - cancel() - if g.Wait() != context.Canceled { + go func() { + time.Sleep(2 * time.Millisecond) + cancel() + }() + _, err = impl.ConfigValidate(ctx, data, machine) + if err != context.Canceled { t.Fatalf("bad resp: %s", err) } } @@ -245,15 +234,13 @@ func TestConfigPlugin_Finalize_context_cancel(t *testing.T) { "test_key": "test_val", "other_key": "other_val"} ctx, cancel := context.WithCancel(context.Background()) - g, _ := errgroup.WithContext(ctx) defer cancel() - g.Go(func() (err error) { - _, err = impl.ConfigFinalize(ctx, data) - return - }) - time.Sleep(2 * time.Millisecond) - cancel() - if g.Wait() != context.Canceled { + go func() { + time.Sleep(2 * time.Millisecond) + cancel() + }() + _, err = impl.ConfigFinalize(ctx, data) + if err != context.Canceled { t.Fatalf("bad resp: %s", err) } } diff --git a/ext/go-plugin/vagrant/plugin/provider_test.go b/ext/go-plugin/vagrant/plugin/provider_test.go index 14ae3db19..d9af0071b 100644 --- a/ext/go-plugin/vagrant/plugin/provider_test.go +++ b/ext/go-plugin/vagrant/plugin/provider_test.go @@ -6,8 +6,6 @@ import ( "testing" "time" - "golang.org/x/sync/errgroup" - "github.com/hashicorp/go-plugin" "github.com/hashicorp/vagrant/ext/go-plugin/vagrant" ) @@ -73,15 +71,13 @@ func TestProvider_Action_context_cancel(t *testing.T) { } ctx, cancel := context.WithCancel(context.Background()) - g, _ := errgroup.WithContext(ctx) defer cancel() - g.Go(func() (err error) { - _, err = impl.Action(ctx, "pause", &vagrant.Machine{}) - return - }) - time.Sleep(2 * time.Millisecond) - cancel() - if g.Wait() != context.Canceled { + go func() { + time.Sleep(2 * time.Millisecond) + cancel() + }() + _, err = impl.Action(ctx, "pause", &vagrant.Machine{}) + if err != context.Canceled { t.Fatalf("bad resp: %s", err) } } @@ -101,14 +97,9 @@ func TestProvider_Action_context_timeout(t *testing.T) { t.Fatalf("bad %#v", raw) } - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Millisecond) + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Millisecond) defer cancel() - n := make(chan struct{}) - go func() { - _, err = impl.Action(ctx, "pause", &vagrant.Machine{}) - n <- struct{}{} - }() - <-n + _, err = impl.Action(ctx, "pause", &vagrant.Machine{}) if err != context.DeadlineExceeded { t.Fatalf("bad resp: %s", err) } @@ -154,15 +145,13 @@ func TestProvider_IsInstalled_context_cancel(t *testing.T) { } ctx, cancel := context.WithCancel(context.Background()) - g, _ := errgroup.WithContext(ctx) defer cancel() - g.Go(func() (err error) { - _, err = impl.IsInstalled(ctx, &vagrant.Machine{Name: "pause"}) - return - }) - time.Sleep(2 * time.Millisecond) - cancel() - if g.Wait() != context.Canceled { + go func() { + time.Sleep(2 * time.Millisecond) + cancel() + }() + _, err = impl.IsInstalled(ctx, &vagrant.Machine{Name: "pause"}) + if err != context.Canceled { t.Fatalf("bad resp: %s", err) } } @@ -182,14 +171,9 @@ func TestProvider_IsInstalled_context_timeout(t *testing.T) { t.Fatalf("bad %#v", raw) } - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Millisecond) + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Millisecond) defer cancel() - n := make(chan struct{}) - go func() { - _, err = impl.IsInstalled(ctx, &vagrant.Machine{Name: "pause"}) - n <- struct{}{} - }() - <-n + _, err = impl.IsInstalled(ctx, &vagrant.Machine{Name: "pause"}) if err != context.DeadlineExceeded { t.Fatalf("bad resp: %s", err) } @@ -232,15 +216,13 @@ func TestProvider_IsUsable_context_cancel(t *testing.T) { t.Fatalf("bad %#v", raw) } ctx, cancel := context.WithCancel(context.Background()) - g, _ := errgroup.WithContext(ctx) defer cancel() - g.Go(func() (err error) { - _, err = impl.IsUsable(ctx, &vagrant.Machine{Name: "pause"}) - return - }) - time.Sleep(2 * time.Millisecond) - cancel() - if g.Wait() != context.Canceled { + go func() { + time.Sleep(2 * time.Millisecond) + cancel() + }() + _, err = impl.IsUsable(ctx, &vagrant.Machine{Name: "pause"}) + if err != context.Canceled { t.Fatalf("bad resp: %s", err) } } @@ -259,14 +241,9 @@ func TestProvider_IsUsable_context_timeout(t *testing.T) { if !ok { t.Fatalf("bad %#v", raw) } - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Millisecond) + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Millisecond) defer cancel() - n := make(chan struct{}) - go func() { - _, err = impl.IsUsable(ctx, &vagrant.Machine{Name: "pause"}) - n <- struct{}{} - }() - <-n + _, err = impl.IsUsable(ctx, &vagrant.Machine{Name: "pause"}) if err != context.DeadlineExceeded { t.Fatalf("bad resp: %s", err) } @@ -308,15 +285,13 @@ func TestProvider_MachineIdChanged_context_cancel(t *testing.T) { } ctx, cancel := context.WithCancel(context.Background()) - g, _ := errgroup.WithContext(ctx) defer cancel() - g.Go(func() (err error) { - err = impl.MachineIdChanged(ctx, &vagrant.Machine{Name: "pause"}) - return - }) - time.Sleep(2 * time.Millisecond) - cancel() - if g.Wait() != context.Canceled { + go func() { + time.Sleep(2 * time.Millisecond) + cancel() + }() + err = impl.MachineIdChanged(ctx, &vagrant.Machine{Name: "pause"}) + if err != context.Canceled { t.Fatalf("bad resp: %s", err) } } @@ -336,14 +311,9 @@ func TestProvider_MachineIdChanged_context_timeout(t *testing.T) { t.Fatalf("bad %#v", raw) } - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Millisecond) + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Millisecond) defer cancel() - n := make(chan struct{}) - go func() { - err = impl.MachineIdChanged(ctx, &vagrant.Machine{Name: "pause"}) - n <- struct{}{} - }() - <-n + err = impl.MachineIdChanged(ctx, &vagrant.Machine{Name: "pause"}) if err != context.DeadlineExceeded { t.Fatalf("bad resp: %s", err) } @@ -421,15 +391,13 @@ func TestProvider_RunAction_context_cancel(t *testing.T) { m := &vagrant.Machine{} ctx, cancel := context.WithCancel(context.Background()) - g, _ := errgroup.WithContext(ctx) defer cancel() - g.Go(func() (err error) { - _, err = impl.RunAction(ctx, "pause", args, m) - return - }) - time.Sleep(2 * time.Millisecond) - cancel() - if g.Wait() != context.Canceled { + go func() { + time.Sleep(2 * time.Millisecond) + cancel() + }() + _, err = impl.RunAction(ctx, "pause", args, m) + if err != context.Canceled { t.Fatalf("bad resp: %s", err) } } @@ -452,14 +420,9 @@ func TestProvider_RunAction_context_timeout(t *testing.T) { args := []string{"test_arg", "other_arg"} m := &vagrant.Machine{} - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Millisecond) + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Millisecond) defer cancel() - n := make(chan struct{}) - go func() { - _, err = impl.RunAction(ctx, "pause", args, m) - n <- struct{}{} - }() - <-n + _, err = impl.RunAction(ctx, "pause", args, m) if err != context.DeadlineExceeded { t.Fatalf("bad resp: %s", err) } @@ -533,15 +496,13 @@ func TestProvider_SshInfo_context_cancel(t *testing.T) { } ctx, cancel := context.WithCancel(context.Background()) - g, _ := errgroup.WithContext(ctx) defer cancel() - g.Go(func() (err error) { - _, err = impl.SshInfo(ctx, &vagrant.Machine{Name: "pause"}) - return - }) - time.Sleep(2 * time.Millisecond) - cancel() - if g.Wait() != context.Canceled { + go func() { + time.Sleep(2 * time.Millisecond) + cancel() + }() + _, err = impl.SshInfo(ctx, &vagrant.Machine{Name: "pause"}) + if err != context.Canceled { t.Fatalf("invalid resp: %s", err) } } @@ -561,14 +522,9 @@ func TestProvider_SshInfo_context_timeout(t *testing.T) { t.Fatalf("bad %#v", raw) } - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Millisecond) + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Millisecond) defer cancel() - n := make(chan struct{}) - go func() { - _, err = impl.SshInfo(ctx, &vagrant.Machine{Name: "pause"}) - n <- struct{}{} - }() - <-n + _, err = impl.SshInfo(ctx, &vagrant.Machine{Name: "pause"}) if err != context.DeadlineExceeded { t.Fatalf("invalid resp: %s", err) } @@ -618,15 +574,13 @@ func TestProvider_State_context_cancel(t *testing.T) { } ctx, cancel := context.WithCancel(context.Background()) - g, _ := errgroup.WithContext(ctx) defer cancel() - g.Go(func() (err error) { - _, err = impl.State(ctx, &vagrant.Machine{Name: "pause"}) - return - }) - time.Sleep(2 * time.Millisecond) - cancel() - if g.Wait() != context.Canceled { + go func() { + time.Sleep(2 * time.Millisecond) + cancel() + }() + _, err = impl.State(ctx, &vagrant.Machine{Name: "pause"}) + if err != context.Canceled { t.Fatalf("invalid resp: %s", err) } } @@ -646,14 +600,9 @@ func TestProvider_State_context_timeout(t *testing.T) { t.Fatalf("bad %#v", raw) } - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Millisecond) + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Millisecond) defer cancel() - n := make(chan struct{}) - go func() { - _, err = impl.State(ctx, &vagrant.Machine{Name: "pause"}) - n <- struct{}{} - }() - <-n + _, err = impl.State(ctx, &vagrant.Machine{Name: "pause"}) if err != context.DeadlineExceeded { t.Fatalf("invalid resp: %s", err) } diff --git a/ext/go-plugin/vagrant/plugin/synced_folder.go b/ext/go-plugin/vagrant/plugin/synced_folder.go index 9910acc33..d55ee4832 100644 --- a/ext/go-plugin/vagrant/plugin/synced_folder.go +++ b/ext/go-plugin/vagrant/plugin/synced_folder.go @@ -237,13 +237,13 @@ func (s *GRPCSyncedFolderServer) Info(ctx context.Context, req *vagrant_proto.Em func (s *GRPCSyncedFolderServer) IsUsable(ctx context.Context, req *vagrant_proto.Machine) (resp *vagrant_proto.Valid, err error) { resp = &vagrant_proto.Valid{} - g, _ := errgroup.WithContext(ctx) + g, gctx := errgroup.WithContext(ctx) g.Go(func() (err error) { machine, err := vagrant.LoadMachine(req.Machine, s.Impl) if err != nil { return } - r, err := s.Impl.IsUsable(ctx, machine) + r, err := s.Impl.IsUsable(gctx, machine) if err != nil { return } diff --git a/ext/go-plugin/vagrant/plugin/synced_folder_test.go b/ext/go-plugin/vagrant/plugin/synced_folder_test.go index 4b0f3e85d..856b15adf 100644 --- a/ext/go-plugin/vagrant/plugin/synced_folder_test.go +++ b/ext/go-plugin/vagrant/plugin/synced_folder_test.go @@ -6,8 +6,6 @@ import ( "testing" "time" - "golang.org/x/sync/errgroup" - "github.com/hashicorp/go-plugin" "github.com/hashicorp/vagrant/ext/go-plugin/vagrant" ) @@ -76,15 +74,13 @@ func TestSyncedFolder_Cleanup_context_cancel(t *testing.T) { } ctx, cancel := context.WithCancel(context.Background()) - g, _ := errgroup.WithContext(ctx) defer cancel() - g.Go(func() (err error) { - err = impl.Cleanup(ctx, &vagrant.Machine{Name: "pause"}, nil) - return - }) - time.Sleep(2 * time.Millisecond) - cancel() - if g.Wait() != context.Canceled { + go func() { + time.Sleep(2 * time.Millisecond) + cancel() + }() + err = impl.Cleanup(ctx, &vagrant.Machine{Name: "pause"}, nil) + if err != context.Canceled { t.Fatalf("bad resp: %s", err) } } @@ -104,14 +100,9 @@ func TestSyncedFolder_Cleanup_context_timeout(t *testing.T) { t.Fatalf("bad %#v", raw) } - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Millisecond) + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Millisecond) defer cancel() - n := make(chan struct{}) - go func() { - err = impl.Cleanup(ctx, &vagrant.Machine{Name: "pause"}, nil) - n <- struct{}{} - }() - <-n + err = impl.Cleanup(ctx, &vagrant.Machine{Name: "pause"}, nil) if err != context.DeadlineExceeded { t.Fatalf("bad resp: %s", err) } @@ -183,15 +174,13 @@ func TestSyncedFolder_Disable_context_cancel(t *testing.T) { } ctx, cancel := context.WithCancel(context.Background()) - g, _ := errgroup.WithContext(ctx) defer cancel() - g.Go(func() (err error) { - err = impl.Disable(ctx, &vagrant.Machine{Name: "pause"}, nil, nil) - return - }) - time.Sleep(2 * time.Millisecond) - cancel() - if g.Wait() != context.Canceled { + go func() { + time.Sleep(2 * time.Millisecond) + cancel() + }() + err = impl.Disable(ctx, &vagrant.Machine{Name: "pause"}, nil, nil) + if err != context.Canceled { t.Fatalf("bad resp: %s", err) } } @@ -211,14 +200,9 @@ func TestSyncedFolder_Disable_context_timeout(t *testing.T) { t.Fatalf("bad %#v", raw) } - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Millisecond) + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Millisecond) defer cancel() - n := make(chan struct{}) - go func() { - err = impl.Disable(ctx, &vagrant.Machine{Name: "pause"}, nil, nil) - n <- struct{}{} - }() - <-n + err = impl.Disable(ctx, &vagrant.Machine{Name: "pause"}, nil, nil) if err != context.DeadlineExceeded { t.Fatalf("bad resp: %s", err) } @@ -290,15 +274,13 @@ func TestSyncedFolder_Enable_context_cancel(t *testing.T) { } ctx, cancel := context.WithCancel(context.Background()) - g, _ := errgroup.WithContext(ctx) defer cancel() - g.Go(func() (err error) { - err = impl.Enable(ctx, &vagrant.Machine{Name: "pause"}, nil, nil) - return - }) - time.Sleep(2 * time.Millisecond) - cancel() - if g.Wait() != context.Canceled { + go func() { + time.Sleep(2 * time.Millisecond) + cancel() + }() + err = impl.Enable(ctx, &vagrant.Machine{Name: "pause"}, nil, nil) + if err != context.Canceled { t.Fatalf("bad resp: %s", err) } } @@ -318,14 +300,9 @@ func TestSyncedFolder_Enable_context_timeout(t *testing.T) { t.Fatalf("bad %#v", raw) } - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Millisecond) + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Millisecond) defer cancel() - n := make(chan struct{}) - go func() { - err = impl.Enable(ctx, &vagrant.Machine{Name: "pause"}, nil, nil) - n <- struct{}{} - }() - <-n + err = impl.Enable(ctx, &vagrant.Machine{Name: "pause"}, nil, nil) if err != context.DeadlineExceeded { t.Fatalf("bad resp: %s", err) } @@ -397,15 +374,13 @@ func TestSyncedFolder_Prepare_context_cancel(t *testing.T) { } ctx, cancel := context.WithCancel(context.Background()) - g, _ := errgroup.WithContext(ctx) defer cancel() - g.Go(func() (err error) { - err = impl.Prepare(ctx, &vagrant.Machine{Name: "pause"}, nil, nil) - return - }) - time.Sleep(2 * time.Millisecond) - cancel() - if g.Wait() != context.Canceled { + go func() { + time.Sleep(2 * time.Millisecond) + cancel() + }() + err = impl.Prepare(ctx, &vagrant.Machine{Name: "pause"}, nil, nil) + if err != context.Canceled { t.Fatalf("bad resp: %s", err) } } @@ -425,14 +400,9 @@ func TestSyncedFolder_Prepare_context_timeout(t *testing.T) { t.Fatalf("bad %#v", raw) } - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Millisecond) + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Millisecond) defer cancel() - n := make(chan struct{}) - go func() { - err = impl.Prepare(ctx, &vagrant.Machine{Name: "pause"}, nil, nil) - n <- struct{}{} - }() - <-n + err = impl.Prepare(ctx, &vagrant.Machine{Name: "pause"}, nil, nil) if err != context.DeadlineExceeded { t.Fatalf("bad resp: %s", err) } @@ -505,15 +475,13 @@ func TestSyncedFolder_IsUsable_context_cancel(t *testing.T) { } ctx, cancel := context.WithCancel(context.Background()) - g, _ := errgroup.WithContext(ctx) defer cancel() - g.Go(func() (err error) { - _, err = impl.IsUsable(ctx, &vagrant.Machine{Name: "pause"}) - return - }) - time.Sleep(2 * time.Millisecond) - cancel() - if g.Wait() != context.Canceled { + go func() { + time.Sleep(2 * time.Millisecond) + cancel() + }() + _, err = impl.IsUsable(ctx, &vagrant.Machine{Name: "pause"}) + if err != context.Canceled { t.Fatalf("bad resp: %s", err) } } @@ -533,14 +501,9 @@ func TestSyncedFolder_IsUsable_context_timeout(t *testing.T) { t.Fatalf("bad %#v", raw) } - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Millisecond) + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Millisecond) defer cancel() - n := make(chan struct{}) - go func() { - _, err = impl.IsUsable(ctx, &vagrant.Machine{Name: "pause"}) - n <- struct{}{} - }() - <-n + _, err = impl.IsUsable(ctx, &vagrant.Machine{Name: "pause"}) if err != context.DeadlineExceeded { t.Fatalf("bad resp: %s", err) }