rpc/server: start and shutdown Server in tests
It will be important for proper subscription testing and it doesn't hurt even though technically we've got two http servers listening after this change (one is a regular Server's http.Server and one is httptest's Server). Reusing rpc.Server would be nice, but it requires some changes to Start sequence to start Listener with net.Listen and then communicate back its resulting Addr. It's not very convenient especially given that no other code needs it, so doing these changes just for a bit cleaner testing seems like and overkill. Update config appropriately. Update Start comment along the way.
This commit is contained in:
parent
b7d2b659b4
commit
612500ed96
4 changed files with 11 additions and 6 deletions
|
@ -17,7 +17,7 @@ import (
|
|||
"go.uber.org/zap/zaptest"
|
||||
)
|
||||
|
||||
func initServerWithInMemoryChain(t *testing.T) (*core.Blockchain, *httptest.Server) {
|
||||
func initServerWithInMemoryChain(t *testing.T) (*core.Blockchain, *Server, *httptest.Server) {
|
||||
var nBlocks uint32
|
||||
|
||||
net := config.ModeUnitTestNet
|
||||
|
@ -55,11 +55,13 @@ func initServerWithInMemoryChain(t *testing.T) (*core.Blockchain, *httptest.Serv
|
|||
server, err := network.NewServer(serverConfig, chain, logger)
|
||||
require.NoError(t, err)
|
||||
rpcServer := New(chain, cfg.ApplicationConfiguration.RPC, server, logger)
|
||||
errCh := make(chan error, 2)
|
||||
go rpcServer.Start(errCh)
|
||||
|
||||
handler := http.HandlerFunc(rpcServer.handleHTTPRequest)
|
||||
srv := httptest.NewServer(handler)
|
||||
|
||||
return chain, srv
|
||||
return chain, &rpcServer, srv
|
||||
}
|
||||
|
||||
type FeerStub struct{}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue