From 6dd8ed7d7a71e62938c2ee473cc4e017035f3cd5 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Fri, 4 Oct 2019 10:02:25 -0600 Subject: [PATCH] pass those tests --- cmd/lotus-fountain/main.go | 3 ++- lib/jsonrpc/websocket.go | 2 ++ node/node_test.go | 7 ++++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cmd/lotus-fountain/main.go b/cmd/lotus-fountain/main.go index 1a9017b31..8b8a457fd 100644 --- a/cmd/lotus-fountain/main.go +++ b/cmd/lotus-fountain/main.go @@ -64,10 +64,11 @@ var runCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - nodeApi, err := lcli.GetFullNodeAPI(cctx) + nodeApi, closer, err := lcli.GetFullNodeAPI(cctx) if err != nil { return err } + defer closer() ctx := lcli.ReqContext(cctx) v, err := nodeApi.Version(ctx) diff --git a/lib/jsonrpc/websocket.go b/lib/jsonrpc/websocket.go index 8994b223f..9e82c4f7f 100644 --- a/lib/jsonrpc/websocket.go +++ b/lib/jsonrpc/websocket.go @@ -444,6 +444,7 @@ func (c *wsConn) handleWsConn(ctx context.Context) { } c.sendRequest(req.req) case <-c.stop: + c.writeLk.Lock() cmsg := websocket.FormatCloseMessage(websocket.CloseNormalClosure, "") if err := c.conn.WriteMessage(websocket.CloseMessage, cmsg); err != nil { log.Warn("failed to write close message: ", err) @@ -451,6 +452,7 @@ func (c *wsConn) handleWsConn(ctx context.Context) { if err := c.conn.Close(); err != nil { log.Warnw("websocket close error", "error", err) } + c.writeLk.Unlock() return } } diff --git a/node/node_test.go b/node/node_test.go index 7466cfd02..2dbd38485 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -4,12 +4,13 @@ import ( "bytes" "context" "crypto/rand" - "github.com/libp2p/go-libp2p-core/crypto" "io/ioutil" "net/http/httptest" "os" "testing" + "github.com/libp2p/go-libp2p-core/crypto" + "github.com/ipfs/go-datastore" "github.com/libp2p/go-libp2p-core/peer" mocknet "github.com/libp2p/go-libp2p/p2p/net/mock" @@ -193,7 +194,7 @@ func rpcBuilder(t *testing.T, nFull int, storage []int) ([]test.TestNode, []test testServ := httptest.NewServer(rpcServer) // todo: close var err error - fulls[i].FullNode, err = client.NewFullNodeRPC("ws://"+testServ.Listener.Addr().String(), nil) + fulls[i].FullNode, _, err = client.NewFullNodeRPC("ws://"+testServ.Listener.Addr().String(), nil) if err != nil { t.Fatal(err) } @@ -206,7 +207,7 @@ func rpcBuilder(t *testing.T, nFull int, storage []int) ([]test.TestNode, []test testServ := httptest.NewServer(rpcServer) // todo: close var err error - storers[i].StorageMiner, err = client.NewStorageMinerRPC("ws://"+testServ.Listener.Addr().String(), nil) + storers[i].StorageMiner, _, err = client.NewStorageMinerRPC("ws://"+testServ.Listener.Addr().String(), nil) if err != nil { t.Fatal(err) }