Browse Source

testing: use noop loger with leakteset in more places (#7604)

pull/7614/head
Sam Kleinman 3 years ago
committed by GitHub
parent
commit
b10c74647f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 59 additions and 27 deletions
  1. +10
    -10
      privval/signer_client_test.go
  2. +4
    -2
      privval/signer_listener_endpoint_test.go
  3. +4
    -1
      rpc/jsonrpc/client/ws_client_test.go
  4. +24
    -8
      rpc/jsonrpc/jsonrpc_test.go
  5. +13
    -5
      rpc/jsonrpc/server/http_server_test.go
  6. +4
    -1
      rpc/jsonrpc/server/ws_handler_test.go

+ 10
- 10
privval/signer_client_test.go View File

@ -69,7 +69,7 @@ func TestSignerClose(t *testing.T) {
bctx, bcancel := context.WithCancel(context.Background())
defer bcancel()
logger := log.NewTestingLogger(t)
logger := log.NewNopLogger()
for _, tc := range getSignerTestCases(bctx, t, logger) {
t.Run(tc.name, func(t *testing.T) {
@ -91,7 +91,7 @@ func TestSignerPing(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
logger := log.NewTestingLogger(t)
logger := log.NewNopLogger()
for _, tc := range getSignerTestCases(ctx, t, logger) {
err := tc.signerClient.Ping(ctx)
@ -105,7 +105,7 @@ func TestSignerGetPubKey(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
logger := log.NewTestingLogger(t)
logger := log.NewNopLogger()
for _, tc := range getSignerTestCases(ctx, t, logger) {
t.Run(tc.name, func(t *testing.T) {
@ -135,7 +135,7 @@ func TestSignerProposal(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
logger := log.NewTestingLogger(t)
logger := log.NewNopLogger()
for _, tc := range getSignerTestCases(ctx, t, logger) {
t.Run(tc.name, func(t *testing.T) {
@ -175,7 +175,7 @@ func TestSignerVote(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
logger := log.NewTestingLogger(t)
logger := log.NewNopLogger()
for _, tc := range getSignerTestCases(ctx, t, logger) {
t.Run(tc.name, func(t *testing.T) {
@ -218,7 +218,7 @@ func TestSignerVoteResetDeadline(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
logger := log.NewTestingLogger(t)
logger := log.NewNopLogger()
for _, tc := range getSignerTestCases(ctx, t, logger) {
t.Run(tc.name, func(t *testing.T) {
@ -269,7 +269,7 @@ func TestSignerVoteKeepAlive(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
logger := log.NewTestingLogger(t)
logger := log.NewNopLogger()
for _, tc := range getSignerTestCases(ctx, t, logger) {
t.Run(tc.name, func(t *testing.T) {
@ -319,7 +319,7 @@ func TestSignerSignProposalErrors(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
logger := log.NewTestingLogger(t)
logger := log.NewNopLogger()
for _, tc := range getSignerTestCases(ctx, t, logger) {
t.Run(tc.name, func(t *testing.T) {
@ -360,7 +360,7 @@ func TestSignerSignVoteErrors(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
logger := log.NewTestingLogger(t)
logger := log.NewNopLogger()
for _, tc := range getSignerTestCases(ctx, t, logger) {
t.Run(tc.name, func(t *testing.T) {
@ -426,7 +426,7 @@ func TestSignerUnexpectedResponse(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
logger := log.NewTestingLogger(t)
logger := log.NewNopLogger()
for _, tc := range getSignerTestCases(ctx, t, logger) {
t.Run(tc.name, func(t *testing.T) {


+ 4
- 2
privval/signer_listener_endpoint_test.go View File

@ -40,10 +40,12 @@ func TestSignerRemoteRetryTCPOnly(t *testing.T) {
retries = 10
)
t.Cleanup(leaktest.Check(t))
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
logger := log.NewTestingLogger(t)
logger := log.NewNopLogger()
ln, err := net.Listen("tcp", "127.0.0.1:0")
require.NoError(t, err)
@ -95,7 +97,7 @@ func TestRetryConnToRemoteSigner(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
logger := log.NewTestingLogger(t)
logger := log.NewNopLogger()
for _, tc := range getDialerTestCases(t) {
var (


+ 4
- 1
rpc/jsonrpc/client/ws_client_test.go View File

@ -220,6 +220,9 @@ func TestNotBlockingOnStop(t *testing.T) {
func startClient(ctx context.Context, t *testing.T, addr string) *WSClient {
t.Helper()
t.Cleanup(leaktest.Check(t))
opts := DefaultWSOptions()
opts.SkipMetrics = true
c, err := NewWSWithOptions(addr, "/websocket", opts)
@ -227,7 +230,7 @@ func startClient(ctx context.Context, t *testing.T, addr string) *WSClient {
require.NoError(t, err)
err = c.Start(ctx)
require.NoError(t, err)
c.Logger = log.NewTestingLogger(t)
c.Logger = log.NewNopLogger()
return c
}


+ 24
- 8
rpc/jsonrpc/jsonrpc_test.go View File

@ -14,6 +14,7 @@ import (
"testing"
"time"
"github.com/fortytw2/leaktest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -265,8 +266,13 @@ func testWithWSClient(ctx context.Context, t *testing.T, cl *client.WSClient) {
//-------------
func TestServersAndClientsBasic(t *testing.T) {
bctx, cancel := context.WithCancel(context.Background())
defer cancel()
// TODO: reenable the leak detector once the test fixture is
// managed in the context of this test.
//
// t.Cleanup(leaktest.Check(t))
bctx, bcancel := context.WithCancel(context.Background())
defer bcancel()
serverAddrs := [...]string{tcpAddr, unixAddr}
for _, addr := range serverAddrs {
@ -274,14 +280,16 @@ func TestServersAndClientsBasic(t *testing.T) {
ctx, cancel := context.WithCancel(bctx)
defer cancel()
logger := log.NewTestingLogger(t)
logger := log.NewNopLogger()
cl2, err := client.New(addr)
require.NoError(t, err)
fmt.Printf("=== testing server on %s using JSONRPC client", addr)
testWithHTTPClient(ctx, t, cl2)
cl3, err := client.NewWS(addr, websocketEndpoint)
opts := client.DefaultWSOptions()
opts.SkipMetrics = true
cl3, err := client.NewWSWithOptions(addr, websocketEndpoint, opts)
require.NoError(t, err)
cl3.Logger = logger
err = cl3.Start(ctx)
@ -294,12 +302,16 @@ func TestServersAndClientsBasic(t *testing.T) {
}
func TestWSNewWSRPCFunc(t *testing.T) {
t.Cleanup(leaktest.Check(t))
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cl, err := client.NewWS(tcpAddr, websocketEndpoint)
opts := client.DefaultWSOptions()
opts.SkipMetrics = true
cl, err := client.NewWSWithOptions(tcpAddr, websocketEndpoint, opts)
require.NoError(t, err)
cl.Logger = log.NewTestingLogger(t)
cl.Logger = log.NewNopLogger()
err = cl.Start(ctx)
require.NoError(t, err)
t.Cleanup(func() {
@ -329,12 +341,16 @@ func TestWSNewWSRPCFunc(t *testing.T) {
// TestWSClientPingPong checks that a client & server exchange pings
// & pongs so connection stays alive.
func TestWSClientPingPong(t *testing.T) {
t.Cleanup(leaktest.Check(t))
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cl, err := client.NewWS(tcpAddr, websocketEndpoint)
opts := client.DefaultWSOptions()
opts.SkipMetrics = true
cl, err := client.NewWSWithOptions(tcpAddr, websocketEndpoint, opts)
require.NoError(t, err)
cl.Logger = log.NewTestingLogger(t)
cl.Logger = log.NewNopLogger()
err = cl.Start(ctx)
require.NoError(t, err)
t.Cleanup(func() {


+ 13
- 5
rpc/jsonrpc/server/http_server_test.go View File

@ -14,6 +14,7 @@ import (
"testing"
"time"
"github.com/fortytw2/leaktest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -28,10 +29,12 @@ type sampleResult struct {
func TestMaxOpenConnections(t *testing.T) {
const max = 5 // max simultaneous connections
t.Cleanup(leaktest.Check(t))
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
logger := log.NewTestingLogger(t)
logger := log.NewNopLogger()
// Start the server.
var open int32
@ -78,6 +81,8 @@ func TestMaxOpenConnections(t *testing.T) {
}
func TestServeTLS(t *testing.T) {
t.Cleanup(leaktest.Check(t))
ln, err := net.Listen("tcp", "localhost:0")
require.NoError(t, err)
defer ln.Close()
@ -90,11 +95,14 @@ func TestServeTLS(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
logger := log.NewTestingLogger(t)
logger := log.NewNopLogger()
chErr := make(chan error, 1)
go func() {
chErr <- ServeTLS(ctx, ln, mux, "test.crt", "test.key", logger, DefaultConfig())
select {
case chErr <- ServeTLS(ctx, ln, mux, "test.crt", "test.key", logger, DefaultConfig()):
case <-ctx.Done():
}
}()
select {
@ -122,7 +130,7 @@ func TestWriteRPCResponse(t *testing.T) {
// one argument
w := httptest.NewRecorder()
logger := log.NewTestingLogger(t)
logger := log.NewNopLogger()
writeRPCResponse(w, logger,
rpctypes.NewRPCSuccessResponse(id, &sampleResult{"hello"}))
resp := w.Result()
@ -153,7 +161,7 @@ func TestWriteRPCResponse(t *testing.T) {
func TestWriteHTTPResponse(t *testing.T) {
w := httptest.NewRecorder()
logger := log.NewTestingLogger(t)
logger := log.NewNopLogger()
writeHTTPResponse(w, logger,
rpctypes.RPCInternalError(rpctypes.JSONRPCIntID(-1), errors.New("foo")))
resp := w.Result()


+ 4
- 1
rpc/jsonrpc/server/ws_handler_test.go View File

@ -6,6 +6,7 @@ import (
"net/http/httptest"
"testing"
"github.com/fortytw2/leaktest"
"github.com/gorilla/websocket"
"github.com/stretchr/testify/require"
@ -14,11 +15,13 @@ import (
)
func TestWebsocketManagerHandler(t *testing.T) {
logger := log.NewTestingLogger(t)
logger := log.NewNopLogger()
s := newWSServer(t, logger)
defer s.Close()
t.Cleanup(leaktest.Check(t))
// check upgrader works
d := websocket.Dialer{}
c, dialResp, err := d.Dial("ws://"+s.Listener.Addr().String()+"/websocket", nil)


Loading…
Cancel
Save