backend/atlas: fix use of T.Fatal() inside goroutine

This commit is contained in:
Lars Lehtonen 2019-10-29 12:55:26 -07:00 committed by Martin Atkins
parent ba7679b679
commit 1219acf467
1 changed files with 9 additions and 5 deletions

View File

@ -7,6 +7,7 @@ import (
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"encoding/json" "encoding/json"
"errors"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"net/url" "net/url"
@ -216,17 +217,20 @@ func TestStateClient_UnresolvableConflict(t *testing.T) {
if err := terraform.WriteState(state, &stateJson); err != nil { if err := terraform.WriteState(state, &stateJson); err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
doneCh := make(chan struct{}) errCh := make(chan error)
go func() { go func() {
defer close(doneCh) defer close(errCh)
if err := client.Put(stateJson.Bytes()); err == nil { 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 { select {
case <-doneCh: case err := <-errCh:
// OK if err != nil {
t.Fatalf("error from anonymous test goroutine: %s", err)
}
case <-time.After(500 * time.Millisecond): case <-time.After(500 * time.Millisecond):
t.Fatalf("Timed out after 500ms, probably because retrying infinitely.") t.Fatalf("Timed out after 500ms, probably because retrying infinitely.")
} }