From ee39b5ca18c651ef8ea2c6ed94ab1c0266e3669e Mon Sep 17 00:00:00 2001 From: Ekaterina Pavlova Date: Tue, 5 Mar 2024 17:43:03 +0300 Subject: [PATCH] rpcsrv: add close of http server in tests The HTTP server should be closed at the end of the test. Signed-off-by: Ekaterina Pavlova --- pkg/rpcclient/wsclient_test.go | 3 +++ pkg/services/rpcsrv/client_test.go | 1 + pkg/services/rpcsrv/server_helper_test.go | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/rpcclient/wsclient_test.go b/pkg/rpcclient/wsclient_test.go index 693783e79..1c2eabebb 100644 --- a/pkg/rpcclient/wsclient_test.go +++ b/pkg/rpcclient/wsclient_test.go @@ -172,6 +172,7 @@ func TestWSClientEvents(t *testing.T) { return } })) + t.Cleanup(srv.Close) wsc, err := NewWS(context.TODO(), httpURLtoWS(srv.URL), WSOptions{}) require.NoError(t, err) wsc.getNextRequestID = getTestRequestID @@ -314,6 +315,7 @@ func TestWSClientNonBlockingEvents(t *testing.T) { return } })) + t.Cleanup(srv.Close) wsc, err := NewWS(context.TODO(), httpURLtoWS(srv.URL), WSOptions{CloseNotificationChannelIfFull: true}) require.NoError(t, err) wsc.getNextRequestID = getTestRequestID @@ -744,6 +746,7 @@ func TestWSFilteredSubscriptions(t *testing.T) { ws.Close() } })) + t.Cleanup(srv.Close) wsc, err := NewWS(context.TODO(), httpURLtoWS(srv.URL), WSOptions{}) require.NoError(t, err) wsc.getNextRequestID = getTestRequestID diff --git a/pkg/services/rpcsrv/client_test.go b/pkg/services/rpcsrv/client_test.go index f4273a885..cdc2f80da 100644 --- a/pkg/services/rpcsrv/client_test.go +++ b/pkg/services/rpcsrv/client_test.go @@ -1701,6 +1701,7 @@ func TestClient_Iterator_SessionConfigVariations(t *testing.T) { rpcSrv.Start() handler := http.HandlerFunc(rpcSrv.handleHTTPRequest) httpSrv := httptest.NewServer(handler) + t.Cleanup(httpSrv.Close) defer rpcSrv.Shutdown() for _, b := range getTestBlocks(t) { require.NoError(t, chain.AddBlock(b)) diff --git a/pkg/services/rpcsrv/server_helper_test.go b/pkg/services/rpcsrv/server_helper_test.go index 46de624a5..3595bacd6 100644 --- a/pkg/services/rpcsrv/server_helper_test.go +++ b/pkg/services/rpcsrv/server_helper_test.go @@ -130,7 +130,7 @@ func wrapUnitTestChain(t testing.TB, chain *core.Blockchain, orc OracleHandler, handler := http.HandlerFunc(rpcServer.handleHTTPRequest) srv := httptest.NewServer(handler) - + t.Cleanup(srv.Close) return chain, &rpcServer, srv }