pass those tests

This commit is contained in:
whyrusleeping 2019-10-04 10:02:25 -06:00
parent 697bed27a6
commit 6dd8ed7d7a
3 changed files with 8 additions and 4 deletions

View File

@ -64,10 +64,11 @@ var runCmd = &cli.Command{
}, },
}, },
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
nodeApi, err := lcli.GetFullNodeAPI(cctx) nodeApi, closer, err := lcli.GetFullNodeAPI(cctx)
if err != nil { if err != nil {
return err return err
} }
defer closer()
ctx := lcli.ReqContext(cctx) ctx := lcli.ReqContext(cctx)
v, err := nodeApi.Version(ctx) v, err := nodeApi.Version(ctx)

View File

@ -444,6 +444,7 @@ func (c *wsConn) handleWsConn(ctx context.Context) {
} }
c.sendRequest(req.req) c.sendRequest(req.req)
case <-c.stop: case <-c.stop:
c.writeLk.Lock()
cmsg := websocket.FormatCloseMessage(websocket.CloseNormalClosure, "") cmsg := websocket.FormatCloseMessage(websocket.CloseNormalClosure, "")
if err := c.conn.WriteMessage(websocket.CloseMessage, cmsg); err != nil { if err := c.conn.WriteMessage(websocket.CloseMessage, cmsg); err != nil {
log.Warn("failed to write close message: ", err) 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 { if err := c.conn.Close(); err != nil {
log.Warnw("websocket close error", "error", err) log.Warnw("websocket close error", "error", err)
} }
c.writeLk.Unlock()
return return
} }
} }

View File

@ -4,12 +4,13 @@ import (
"bytes" "bytes"
"context" "context"
"crypto/rand" "crypto/rand"
"github.com/libp2p/go-libp2p-core/crypto"
"io/ioutil" "io/ioutil"
"net/http/httptest" "net/http/httptest"
"os" "os"
"testing" "testing"
"github.com/libp2p/go-libp2p-core/crypto"
"github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore"
"github.com/libp2p/go-libp2p-core/peer" "github.com/libp2p/go-libp2p-core/peer"
mocknet "github.com/libp2p/go-libp2p/p2p/net/mock" 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 testServ := httptest.NewServer(rpcServer) // todo: close
var err error 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 { if err != nil {
t.Fatal(err) 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 testServ := httptest.NewServer(rpcServer) // todo: close
var err error 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }