Browse Source

rpc: fix test data races (#5363)

Fixes a couple of test data races. `testing.T` is not concurrency-safe and should not be used in goroutines at all.
pull/5364/head
Erik Grinaker 4 years ago
committed by GitHub
parent
commit
531fa07ad2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 7 deletions
  1. +9
    -7
      rpc/jsonrpc/server/http_server_test.go

+ 9
- 7
rpc/jsonrpc/server/http_server_test.go View File

@ -4,7 +4,6 @@ import (
"crypto/tls" "crypto/tls"
"errors" "errors"
"fmt" "fmt"
"io"
"io/ioutil" "io/ioutil"
"net" "net"
"net/http" "net/http"
@ -57,13 +56,10 @@ func TestMaxOpenConnections(t *testing.T) {
c := http.Client{Timeout: 3 * time.Second} c := http.Client{Timeout: 3 * time.Second}
r, err := c.Get("http://" + l.Addr().String()) r, err := c.Get("http://" + l.Addr().String())
if err != nil { if err != nil {
t.Log(err)
atomic.AddInt32(&failed, 1) atomic.AddInt32(&failed, 1)
return return
} }
defer r.Body.Close() defer r.Body.Close()
_, err = io.Copy(ioutil.Discard, r.Body)
require.NoError(t, err)
}() }()
} }
wg.Wait() wg.Wait()
@ -85,12 +81,18 @@ func TestServeTLS(t *testing.T) {
fmt.Fprint(w, "some body") fmt.Fprint(w, "some body")
}) })
chErr := make(chan error, 1)
go func() { go func() {
if err := ServeTLS(ln, mux, "test.crt", "test.key", log.TestingLogger(), DefaultConfig()); err != nil {
t.Log(err)
}
// FIXME This goroutine leaks
chErr <- ServeTLS(ln, mux, "test.crt", "test.key", log.TestingLogger(), DefaultConfig())
}() }()
select {
case err := <-chErr:
require.NoError(t, err)
case <-time.After(100 * time.Millisecond):
}
tr := &http.Transport{ tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
} }


Loading…
Cancel
Save