Skip to content

Commit

Permalink
Fix RPCClient tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkren committed Oct 28, 2019
1 parent 5bb9ecc commit f4127c2
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 161 deletions.
4 changes: 2 additions & 2 deletions pkg/app2/appserver/rpc_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ type RPCGateway struct {
log *logging.Logger
}

// newRPCGateway constructs new server RPC interface.
func newRPCGateway(log *logging.Logger) *RPCGateway {
// NewRPCGateway constructs new server RPC interface.
func NewRPCGateway(log *logging.Logger) *RPCGateway {
return &RPCGateway{
lm: idmanager.New(),
cm: idmanager.New(),
Expand Down
58 changes: 29 additions & 29 deletions pkg/app2/appserver/rpc_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestRPCGateway_Dial(t *testing.T) {
err := appnet.AddNetworker(nType, n)
require.NoError(t, err)

rpc := newRPCGateway(l)
rpc := NewRPCGateway(l)

var resp DialResp
err = rpc.Dial(&dialAddr, &resp)
Expand All @@ -51,7 +51,7 @@ func TestRPCGateway_Dial(t *testing.T) {
})

t.Run("no more slots for a new conn", func(t *testing.T) {
rpc := newRPCGateway(l)
rpc := NewRPCGateway(l)
for i, _, err := rpc.cm.ReserveNextID(); i == nil || *i != 0; i, _, err = rpc.cm.ReserveNextID() {
require.NoError(t, err)
}
Expand Down Expand Up @@ -80,7 +80,7 @@ func TestRPCGateway_Dial(t *testing.T) {
err := appnet.AddNetworker(nType, n)
require.NoError(t, err)

rpc := newRPCGateway(l)
rpc := NewRPCGateway(l)

var resp DialResp
err = rpc.Dial(&dialAddr, &resp)
Expand All @@ -104,7 +104,7 @@ func TestRPCGateway_Dial(t *testing.T) {
err := appnet.AddNetworker(nType, n)
require.NoError(t, err)

rpc := newRPCGateway(l)
rpc := NewRPCGateway(l)

var resp DialResp
err = rpc.Dial(&dialAddr, &resp)
Expand All @@ -131,7 +131,7 @@ func TestRPCGateway_Listen(t *testing.T) {
err := appnet.AddNetworker(nType, n)
require.Equal(t, err, listenErr)

rpc := newRPCGateway(l)
rpc := NewRPCGateway(l)

var lisID uint16

Expand All @@ -141,7 +141,7 @@ func TestRPCGateway_Listen(t *testing.T) {
})

t.Run("no more slots for a new listener", func(t *testing.T) {
rpc := newRPCGateway(l)
rpc := NewRPCGateway(l)
for i, _, err := rpc.lm.ReserveNextID(); i == nil || *i != 0; i, _, err = rpc.lm.ReserveNextID() {
require.NoError(t, err)
}
Expand Down Expand Up @@ -172,7 +172,7 @@ func TestRPCGateway_Listen(t *testing.T) {
err := appnet.AddNetworker(nType, n)
require.NoError(t, err)

rpc := newRPCGateway(l)
rpc := NewRPCGateway(l)

var lisID uint16

Expand All @@ -185,7 +185,7 @@ func TestRPCGateway_Accept(t *testing.T) {
l := logging.MustGetLogger("rpc_gateway")

t.Run("ok", func(t *testing.T) {
rpc := newRPCGateway(l)
rpc := NewRPCGateway(l)

acceptConn := &dmsg.Transport{}
var acceptErr error
Expand All @@ -202,7 +202,7 @@ func TestRPCGateway_Accept(t *testing.T) {
})

t.Run("no such listener", func(t *testing.T) {
rpc := newRPCGateway(l)
rpc := NewRPCGateway(l)

lisID := uint16(1)

Expand All @@ -213,7 +213,7 @@ func TestRPCGateway_Accept(t *testing.T) {
})

t.Run("listener is not set", func(t *testing.T) {
rpc := newRPCGateway(l)
rpc := NewRPCGateway(l)

lisID := addListener(t, rpc, nil)

Expand All @@ -224,7 +224,7 @@ func TestRPCGateway_Accept(t *testing.T) {
})

t.Run("no more slots for a new conn", func(t *testing.T) {
rpc := newRPCGateway(l)
rpc := NewRPCGateway(l)

for i, _, err := rpc.cm.ReserveNextID(); i == nil || *i != 0; i, _, err = rpc.cm.ReserveNextID() {
require.NoError(t, err)
Expand All @@ -245,7 +245,7 @@ func TestRPCGateway_Accept(t *testing.T) {
})

t.Run("error wrapping conn", func(t *testing.T) {
rpc := newRPCGateway(l)
rpc := NewRPCGateway(l)

remoteAddr, localAddr := &appcommon.MockAddr{}, &appcommon.MockAddr{}

Expand All @@ -265,7 +265,7 @@ func TestRPCGateway_Accept(t *testing.T) {
})

t.Run("accept error", func(t *testing.T) {
rpc := newRPCGateway(l)
rpc := NewRPCGateway(l)

var acceptConn net.Conn
acceptErr := errors.New("accept error")
Expand All @@ -288,7 +288,7 @@ func TestRPCGateway_Write(t *testing.T) {
writeN := 10

t.Run("ok", func(t *testing.T) {
rpc := newRPCGateway(l)
rpc := NewRPCGateway(l)

var writeErr error

Expand All @@ -309,7 +309,7 @@ func TestRPCGateway_Write(t *testing.T) {
})

t.Run("no such conn", func(t *testing.T) {
rpc := newRPCGateway(l)
rpc := NewRPCGateway(l)

connID := uint16(1)

Expand All @@ -325,7 +325,7 @@ func TestRPCGateway_Write(t *testing.T) {
})

t.Run("conn is not set", func(t *testing.T) {
rpc := newRPCGateway(l)
rpc := NewRPCGateway(l)

connID := addConn(t, rpc, nil)

Expand All @@ -341,7 +341,7 @@ func TestRPCGateway_Write(t *testing.T) {
})

t.Run("write error", func(t *testing.T) {
rpc := newRPCGateway(l)
rpc := NewRPCGateway(l)

writeErr := errors.New("write error")

Expand Down Expand Up @@ -369,7 +369,7 @@ func TestRPCGateway_Read(t *testing.T) {
readBuf := make([]byte, readBufLen)

t.Run("ok", func(t *testing.T) {
rpc := newRPCGateway(l)
rpc := NewRPCGateway(l)

readN := 10
var readErr error
Expand All @@ -396,7 +396,7 @@ func TestRPCGateway_Read(t *testing.T) {
})

t.Run("no such conn", func(t *testing.T) {
rpc := newRPCGateway(l)
rpc := NewRPCGateway(l)

connID := uint16(1)

Expand All @@ -412,7 +412,7 @@ func TestRPCGateway_Read(t *testing.T) {
})

t.Run("conn is not set", func(t *testing.T) {
rpc := newRPCGateway(l)
rpc := NewRPCGateway(l)

connID := addConn(t, rpc, nil)

Expand All @@ -428,7 +428,7 @@ func TestRPCGateway_Read(t *testing.T) {
})

t.Run("read error", func(t *testing.T) {
rpc := newRPCGateway(l)
rpc := NewRPCGateway(l)

readN := 0
readErr := errors.New("read error")
Expand All @@ -453,7 +453,7 @@ func TestRPCGateway_CloseConn(t *testing.T) {
l := logging.MustGetLogger("rpc_gateway")

t.Run("ok", func(t *testing.T) {
rpc := newRPCGateway(l)
rpc := NewRPCGateway(l)

var closeErr error

Expand All @@ -469,7 +469,7 @@ func TestRPCGateway_CloseConn(t *testing.T) {
})

t.Run("no such conn", func(t *testing.T) {
rpc := newRPCGateway(l)
rpc := NewRPCGateway(l)

connID := uint16(1)

Expand All @@ -479,7 +479,7 @@ func TestRPCGateway_CloseConn(t *testing.T) {
})

t.Run("conn is not set", func(t *testing.T) {
rpc := newRPCGateway(l)
rpc := NewRPCGateway(l)

connID := addConn(t, rpc, nil)

Expand All @@ -489,7 +489,7 @@ func TestRPCGateway_CloseConn(t *testing.T) {
})

t.Run("close error", func(t *testing.T) {
rpc := newRPCGateway(l)
rpc := NewRPCGateway(l)

closeErr := errors.New("close error")

Expand All @@ -507,7 +507,7 @@ func TestRPCGateway_CloseListener(t *testing.T) {
l := logging.MustGetLogger("rpc_gateway")

t.Run("ok", func(t *testing.T) {
rpc := newRPCGateway(l)
rpc := NewRPCGateway(l)

var closeErr error

Expand All @@ -523,7 +523,7 @@ func TestRPCGateway_CloseListener(t *testing.T) {
})

t.Run("no such listener", func(t *testing.T) {
rpc := newRPCGateway(l)
rpc := NewRPCGateway(l)

lisID := uint16(1)

Expand All @@ -533,7 +533,7 @@ func TestRPCGateway_CloseListener(t *testing.T) {
})

t.Run("listener is not set", func(t *testing.T) {
rpc := newRPCGateway(l)
rpc := NewRPCGateway(l)

lisID := addListener(t, rpc, nil)

Expand All @@ -543,7 +543,7 @@ func TestRPCGateway_CloseListener(t *testing.T) {
})

t.Run("close error", func(t *testing.T) {
rpc := newRPCGateway(l)
rpc := NewRPCGateway(l)

closeErr := errors.New("close error")

Expand Down
5 changes: 3 additions & 2 deletions pkg/app2/appserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package appserver

import (
"fmt"
"github.com/skycoin/skywire/pkg/app2/appcommon"
"net"
"net/rpc"
"sync"

"github.com/skycoin/skywire/pkg/app2/appcommon"

"github.com/pkg/errors"
"github.com/skycoin/skycoin/src/util/logging"
)
Expand All @@ -24,7 +25,7 @@ type Server struct {
// NewServer constructs server.
func New(log *logging.Logger, sockFile string, appKey appcommon.Key) (*Server, error) {
rpcS := rpc.NewServer()
gateway := newRPCGateway(logging.MustGetLogger(fmt.Sprintf("rpc_server_%s", appKey)))
gateway := NewRPCGateway(logging.MustGetLogger(fmt.Sprintf("rpc_server_%s", appKey)))
if err := rpcS.RegisterName(string(appKey), gateway); err != nil {
return nil, errors.Wrap(err, "error registering RPC server for app")
}
Expand Down
Loading

0 comments on commit f4127c2

Please sign in to comment.