Skip to content

Commit

Permalink
Fix app tests, make them independent of dmsg implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkren committed Jan 16, 2020
1 parent 5a35a31 commit 8c44344
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 73 deletions.
9 changes: 5 additions & 4 deletions pkg/app/appserver/rpc_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import (
"github.com/SkycoinProject/skywire-mainnet/pkg/routing"
)

// TODO (Darkren): fix test
/*func TestRPCGateway_Dial(t *testing.T) {
func TestRPCGateway_Dial(t *testing.T) {
l := logging.MustGetLogger("rpc_gateway")
nType := appnet.TypeDMSG

Expand Down Expand Up @@ -53,7 +52,9 @@ func testRPCGatewayDialOK(t *testing.T, l *logging.Logger, nType appnet.Type, di
localPort := routing.Port(100)

dialCtx := context.Background()
dialConn := dmsg.NewStream(nil, nil, dmsg.Addr{Port: uint16(localPort)}, dmsg.Addr{}, 0, 10, func() {})
dialConn := &appcommon.MockConn{}
dialConn.On("LocalAddr").Return(dmsg.Addr{Port: uint16(localPort)})
dialConn.On("RemoteAddr").Return(dmsg.Addr{})

var dialErr error

Expand Down Expand Up @@ -137,7 +138,7 @@ func testRPCGatewayDialErrorWrappingConn(t *testing.T, l *logging.Logger, nType
var resp DialResp
err = rpc.Dial(&dialAddr, &resp)
require.Equal(t, err, appnet.ErrUnknownAddrType)
}*/
}

func TestRPCGateway_Listen(t *testing.T) {
l := logging.MustGetLogger("rpc_gateway")
Expand Down
57 changes: 6 additions & 51 deletions pkg/app/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,12 @@ func TestConn_TestConn(t *testing.T) {
fmt.Printf("C2 Local: %s\n", keys[1].PK)
p1, p2 := net.Pipe()
a1 := appnet.Addr{
Net: appnet.Type(netType),
Net: netType,
PubKey: keys[0].PK,
Port: 0,
}
a2 := appnet.Addr{
Net: appnet.Type(netType),
Net: netType,
PubKey: keys[1].PK,
Port: 0,
}
Expand All @@ -207,17 +207,15 @@ func TestConn_TestConn(t *testing.T) {
n.On("DialContext", mock.Anything, a2).Return(wc2, testhelpers.NoErr)

appnet.ClearNetworkers()
err := appnet.AddNetworker(appnet.Type(netType), n)
err := appnet.AddNetworker(netType, n)
if err != nil {
return nil, nil, nil, err
}
//require.NoError(t, err)

rpcL, err := nettest.NewLocalListener("tcp")
if err != nil {
return nil, nil, nil, err
}
//require.NoError(t, err)

rpcS := rpc.NewServer()

Expand All @@ -229,20 +227,17 @@ func TestConn_TestConn(t *testing.T) {
if err != nil {
return nil, nil, nil, err
}
//require.NoError(t, err)
err = rpcS.RegisterName(appKeys[1].PK.Hex(), gateway2)
if err != nil {
return nil, nil, nil, err
}
//require.NoError(t, err)

go rpcS.Accept(rpcL)

rpcCl1, err := rpc.Dial(rpcL.Addr().Network(), rpcL.Addr().String())
if err != nil {
return nil, nil, nil, err
}
//require.NoError(t, err)

cl1 := Client{
log: logging.MustGetLogger("test_client_1"),
Expand All @@ -256,7 +251,6 @@ func TestConn_TestConn(t *testing.T) {
if err != nil {
return nil, nil, nil, err
}
//require.NoError(t, err)

cl2 := Client{
log: logging.MustGetLogger("test_client_2"),
Expand All @@ -270,59 +264,20 @@ func TestConn_TestConn(t *testing.T) {
if err != nil {
return nil, nil, nil, err
}
//require.NoError(t, err)

c2, err := cl2.Dial(a1)
if err != nil {
return nil, nil, nil, err
}
//require.NoError(t, err)

stop := func() {
/*err := c1.Close()
require.NoError(t, err)
err = c2.Close()
require.NoError(t, err)
err = rpcL.Close()
require.NoError(t, err)*/
_ = c1.Close() //nolint:errcheck
_ = c2.Close() //nolint:errcheck
_ = rpcL.Close() //nolint:errcheck
}

return c1, c2, stop, nil
}

/*payload := []byte("hello")
errC := make(chan error)
nC := make(chan int)
bufC := make(chan []byte)
go func() {
buf := make([]byte, 10)
n, err := c2.Read(buf)
fmt.Printf("Err is %v\n", err)
errC <- err
if err != nil {
return
}
nC <- n
bufC <- buf[:n]
}()
written, err := c1.Write(payload)
require.NoError(t, err)
require.Equal(t, len(payload), written)
require.NoError(t, <-errC)
close(errC)
require.Equal(t, len(payload), <-nC)
close(nC)
require.Equal(t, payload, <-bufC)
close(bufC)
err = c1.Close()
require.NoError(t, err)
err = c2.Close()
require.NoError(t, err)*/

nettest.TestConn(t, mp)
}
26 changes: 12 additions & 14 deletions pkg/app/rpc_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ import (
"github.com/SkycoinProject/skywire-mainnet/pkg/app/appserver"
)

// TODO (Darkren): fix test
/*func TestRPCClient_Dial(t *testing.T) {
func TestRPCClient_Dial(t *testing.T) {
t.Run("ok", func(t *testing.T) {
s := prepRPCServer(t, prepGateway())
rpcL, lisCleanup := prepListener(t)
Expand All @@ -38,12 +37,12 @@ import (
dmsgLocal, dmsgRemote, _, remote := prepAddrs()

dialCtx := context.Background()
dialConn := dmsg.NewStream(&appcommon.MockConn{}, logging.MustGetLogger("dmsg_tp"),
dmsgLocal, dmsgRemote, 0, 1024, func() {})
var noErr error
dialConn := &appcommon.MockConn{}
dialConn.On("LocalAddr").Return(dmsgLocal)
dialConn.On("RemoteAddr").Return(dmsgRemote)

n := &appnet.MockNetworker{}
n.On("DialContext", dialCtx, remote).Return(dialConn, noErr)
n.On("DialContext", dialCtx, remote).Return(dialConn, testhelpers.NoErr)

appnet.ClearNetworkers()
err := appnet.AddNetworker(appnet.TypeDMSG, n)
Expand Down Expand Up @@ -82,7 +81,7 @@ import (
require.Equal(t, connID, uint16(0))
require.Equal(t, localPort, routing.Port(0))
})
}*/
}

func TestRPCClient_Listen(t *testing.T) {
t.Run("ok", func(t *testing.T) {
Expand Down Expand Up @@ -139,19 +138,18 @@ func TestRPCClient_Listen(t *testing.T) {
})
}

// TODO (Darkren): fix test
/*func TestRPCClient_Accept(t *testing.T) {
func TestRPCClient_Accept(t *testing.T) {
dmsgLocal, dmsgRemote, local, _ := prepAddrs()

t.Run("ok", func(t *testing.T) {
gateway := prepGateway()

lisConn := dmsg.NewStream(&appcommon.MockConn{}, logging.MustGetLogger("dmsg_tp"),
dmsgLocal, dmsgRemote, 0, 1024, func() {})
var noErr error
lisConn := &appcommon.MockConn{}
lisConn.On("LocalAddr").Return(dmsgLocal)
lisConn.On("RemoteAddr").Return(dmsgRemote)

lis := &appcommon.MockListener{}
lis.On("Accept").Return(lisConn, noErr)
lis.On("Accept").Return(lisConn, testhelpers.NoErr)

prepNetworkerWithListener(t, lis, local)

Expand Down Expand Up @@ -206,7 +204,7 @@ func TestRPCClient_Listen(t *testing.T) {
require.Equal(t, connID, uint16(0))
require.Equal(t, remote, appnet.Addr{})
})
}*/
}

func TestRPCClient_Write(t *testing.T) {
dmsgLocal, dmsgRemote, _, remote := prepAddrs()
Expand Down
1 change: 0 additions & 1 deletion pkg/visor/visor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ func TestMain(m *testing.M) {
// assert.NotNil(t, node.startedApps)
//}

// TODO (Darkren): fix tests
func TestNodeStartClose(t *testing.T) {
r := &router.MockRouter{}
r.On("Serve", mock.Anything /* context */).Return(testhelpers.NoErr)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions vendor/golang.org/x/net/nettest/conntest.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8c44344

Please sign in to comment.