Skip to content

Commit

Permalink
rpcsrv: add close of blockchain in tests
Browse files Browse the repository at this point in the history
The logs race issue is a result of improper shutdown during testing.

Close #3217

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
  • Loading branch information
AliceInHunterland committed Mar 4, 2024
1 parent 8d67f17 commit de5cb18
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 3 additions & 1 deletion pkg/services/rpcsrv/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ import (
)

func TestLocalClient(t *testing.T) {
_, rpcSrv, _ := initClearServerWithCustomConfig(t, func(cfg *config.Config) {
chain, rpcSrv, _ := initClearServerWithCustomConfig(t, func(cfg *config.Config) {
// No addresses configured -> RPC server listens nothing (but it
// has MaxGasInvoke, sessions and other stuff).
cfg.ApplicationConfiguration.RPC.BasicService.Enabled = true
cfg.ApplicationConfiguration.RPC.BasicService.Addresses = nil
cfg.ApplicationConfiguration.RPC.TLSConfig.Addresses = nil
})
defer chain.Close()
defer rpcSrv.Shutdown()
// RPC server listens nothing (not exposed in any way), but it works for internal clients.
c, err := rpcclient.NewInternal(context.TODO(), rpcSrv.RegisterLocal)
require.NoError(t, err)
Expand Down
12 changes: 8 additions & 4 deletions pkg/services/rpcsrv/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3054,9 +3054,11 @@ func testRPCProtocol(t *testing.T, doRPCCall func(string, string, *testing.T) []
}
t.Run("traverseiterator", func(t *testing.T) {
t.Run("sessions disabled", func(t *testing.T) {
_, _, httpSrv2 := initClearServerWithCustomConfig(t, func(c *config.Config) {
chain, rpcSrv, httpSrv2 := initClearServerWithCustomConfig(t, func(c *config.Config) {
c.ApplicationConfiguration.RPC.SessionEnabled = false
})
defer chain.Close()
defer rpcSrv.Shutdown()
body := doRPCCall(`{"jsonrpc": "2.0", "id": 1, "method": "traverseiterator", "params": []}"`, httpSrv2.URL, t)
checkErrGetResult(t, body, true, neorpc.ErrSessionsDisabledCode)
})
Expand Down Expand Up @@ -3116,9 +3118,11 @@ func testRPCProtocol(t *testing.T, doRPCCall func(string, string, *testing.T) []
t.Run("terminatesession", func(t *testing.T) {
rpc := `{"jsonrpc": "2.0", "id": 1, "method": "terminatesession", "params": ["%s"]}"`
t.Run("sessions disabled", func(t *testing.T) {
_, _, httpSrv2 := initClearServerWithCustomConfig(t, func(c *config.Config) {
chain, rpcSrv, httpSrv2 := initClearServerWithCustomConfig(t, func(c *config.Config) {
c.ApplicationConfiguration.RPC.SessionEnabled = false
})
defer chain.Close()
defer rpcSrv.Shutdown()
body := doRPCCall(fmt.Sprintf(rpc, uuid.NewString()), httpSrv2.URL, t)
checkErrGetResult(t, body, true, neorpc.ErrSessionsDisabledCode)
})
Expand Down Expand Up @@ -4135,10 +4139,10 @@ func BenchmarkHandleIn(b *testing.B) {
}

func TestFailedPreconditionShutdown(t *testing.T) {
_, srv, _ := initClearServerWithCustomConfig(t, func(c *config.Config) {
chain, srv, _ := initClearServerWithCustomConfig(t, func(c *config.Config) {
c.ApplicationConfiguration.RPC.Addresses = []string{"not an address"}
})

defer chain.Close()
srv.Start()
require.Positive(t, len(srv.errChan)) // this is how Start reports internal failures

Expand Down

0 comments on commit de5cb18

Please sign in to comment.