Skip to content

Commit

Permalink
Finish RPC gateway tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkren committed Sep 23, 2019
1 parent b2dcbbb commit e243192
Show file tree
Hide file tree
Showing 8 changed files with 397 additions and 21 deletions.
3 changes: 3 additions & 0 deletions pkg/app2/manager.go → pkg/app2/id_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,8 @@ func (m *idManager) get(key uint16) (interface{}, bool) {
m.mx.RLock()
lis, ok := m.values[key]
m.mx.RUnlock()
if lis == nil {
return nil, false
}
return lis, ok
}
File renamed without changes.
4 changes: 4 additions & 0 deletions pkg/app2/network/dmsg_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ type DMSGConn struct {
tp *dmsg.Transport
}

func NewDMSGConn(tp *dmsg.Transport) *DMSGConn {
return &DMSGConn{tp: tp}
}

func (c *DMSGConn) Read(b []byte) (n int, err error) {
return c.tp.Read(b)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/app2/network/dmsg_networker.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (n *DMSGNetworker) DialContext(ctx context.Context, addr Addr) (net.Conn, e
return nil, err
}

return &DMSGConn{tp: tp}, nil
return NewDMSGConn(tp), nil
}

// Listen starts listening on local `addr` in the dmsg network.
Expand Down
10 changes: 4 additions & 6 deletions pkg/app2/rpc_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,8 @@ func (r *RPCGateway) Accept(lisID *uint16, resp *AcceptResp) error {
return errors.New("wrong type for remote addr")
}

resp = &AcceptResp{
Remote: remote,
ConnID: *connID,
}
resp.Remote = remote
resp.ConnID = *connID

return nil
}
Expand Down Expand Up @@ -197,7 +195,7 @@ func (r *RPCGateway) CloseListener(lisID *uint16, _ *struct{}) error {
func (r *RPCGateway) popListener(lisID uint16) (net.Listener, error) {
lisIfc, err := r.lm.pop(lisID)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "no listener")
}

return r.assertListener(lisIfc)
Expand All @@ -208,7 +206,7 @@ func (r *RPCGateway) popListener(lisID uint16) (net.Listener, error) {
func (r *RPCGateway) popConn(connID uint16) (net.Conn, error) {
connIfc, err := r.cm.pop(connID)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "no conn")
}

return r.assertConn(connIfc)
Expand Down
Loading

0 comments on commit e243192

Please sign in to comment.