From 59110a2ca548d058326278e85f9fc48602f86a73 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 30 Sep 2020 14:28:02 -0400 Subject: [PATCH] e2etest server was unsynchronized --- command/e2etest/unmanaged_test.go | 42 ++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/command/e2etest/unmanaged_test.go b/command/e2etest/unmanaged_test.go index a4e67a471..ab8e19aa1 100644 --- a/command/e2etest/unmanaged_test.go +++ b/command/e2etest/unmanaged_test.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "path/filepath" "strings" + "sync" "testing" "github.com/hashicorp/go-hclog" @@ -40,21 +41,54 @@ type reattachConfigAddr struct { } type providerServer struct { + sync.Mutex *grpcplugin.GRPCProviderServer planResourceChangeCalled bool applyResourceChangeCalled bool } func (p *providerServer) PlanResourceChange(ctx context.Context, req *proto.PlanResourceChange_Request) (*proto.PlanResourceChange_Response, error) { + p.Lock() + defer p.Unlock() + p.planResourceChangeCalled = true return p.GRPCProviderServer.PlanResourceChange(ctx, req) } func (p *providerServer) ApplyResourceChange(ctx context.Context, req *proto.ApplyResourceChange_Request) (*proto.ApplyResourceChange_Response, error) { + p.Lock() + defer p.Unlock() + p.applyResourceChangeCalled = true return p.GRPCProviderServer.ApplyResourceChange(ctx, req) } +func (p *providerServer) PlanResourceChangeCalled() bool { + p.Lock() + defer p.Unlock() + + return p.planResourceChangeCalled +} +func (p *providerServer) ResetPlanResourceChangeCalled() { + p.Lock() + defer p.Unlock() + + p.planResourceChangeCalled = false +} + +func (p *providerServer) ApplyResourceChangeCalled() bool { + p.Lock() + defer p.Unlock() + + return p.applyResourceChangeCalled +} +func (p *providerServer) ResetApplyResourceChangeCalled() { + p.Lock() + defer p.Unlock() + + p.applyResourceChangeCalled = false +} + func TestUnmanagedSeparatePlan(t *testing.T) { t.Parallel() @@ -129,7 +163,7 @@ func TestUnmanagedSeparatePlan(t *testing.T) { t.Fatalf("unexpected plan error: %s\nstderr:\n%s", err, stderr) } - if !provider.planResourceChangeCalled { + if !provider.PlanResourceChangeCalled() { t.Error("PlanResourceChange not called on in-process provider") } @@ -139,10 +173,10 @@ func TestUnmanagedSeparatePlan(t *testing.T) { t.Fatalf("unexpected apply error: %s\nstderr:\n%s", err, stderr) } - if !provider.applyResourceChangeCalled { + if !provider.ApplyResourceChangeCalled() { t.Error("ApplyResourceChange not called on in-process provider") } - provider.applyResourceChangeCalled = false + provider.ResetApplyResourceChangeCalled() //// DESTROY _, stderr, err = tf.Run("destroy", "-auto-approve") @@ -150,7 +184,7 @@ func TestUnmanagedSeparatePlan(t *testing.T) { t.Fatalf("unexpected destroy error: %s\nstderr:\n%s", err, stderr) } - if !provider.applyResourceChangeCalled { + if !provider.ApplyResourceChangeCalled() { t.Error("ApplyResourceChange (destroy) not called on in-process provider") } cancel()