From 1219acf467436ed8d4593a8c720aeab479c464ad Mon Sep 17 00:00:00 2001 From: Lars Lehtonen Date: Tue, 29 Oct 2019 12:55:26 -0700 Subject: [PATCH] backend/atlas: fix use of T.Fatal() inside goroutine --- backend/atlas/state_client_test.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/backend/atlas/state_client_test.go b/backend/atlas/state_client_test.go index 6c370941a..0e4795c70 100644 --- a/backend/atlas/state_client_test.go +++ b/backend/atlas/state_client_test.go @@ -7,6 +7,7 @@ import ( "crypto/tls" "crypto/x509" "encoding/json" + "errors" "net/http" "net/http/httptest" "net/url" @@ -216,17 +217,20 @@ func TestStateClient_UnresolvableConflict(t *testing.T) { if err := terraform.WriteState(state, &stateJson); err != nil { t.Fatalf("err: %s", err) } - doneCh := make(chan struct{}) + errCh := make(chan error) go func() { - defer close(doneCh) + defer close(errCh) if err := client.Put(stateJson.Bytes()); err == nil { - t.Fatal("Expected error from state conflict, got none.") + errCh <- errors.New("expected error from state conflict, got none.") + return } }() select { - case <-doneCh: - // OK + case err := <-errCh: + if err != nil { + t.Fatalf("error from anonymous test goroutine: %s", err) + } case <-time.After(500 * time.Millisecond): t.Fatalf("Timed out after 500ms, probably because retrying infinitely.") }