Skip to content

Commit

Permalink
Remove connsCount from Client, connsCount -> connCount for `S…
Browse files Browse the repository at this point in the history
…erver`
  • Loading branch information
Darkren committed Jun 15, 2019
1 parent 5f7a9ea commit e881d7f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
7 changes: 0 additions & 7 deletions pkg/dmsg/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,6 @@ func (c *Client) updateDiscEntry(ctx context.Context) error {
return c.dc.UpdateEntry(ctx, c.sk, entry)
}

func (c *Client) connsCount() int {
c.mx.RLock()
count := len(c.conns)
c.mx.RUnlock()
return count
}

func (c *Client) setConn(ctx context.Context, l *ClientConn) {
c.mx.Lock()
c.conns[l.remoteSrv] = l
Expand Down
6 changes: 3 additions & 3 deletions pkg/dmsg/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,11 @@ func (s *Server) getConn(pk cipher.PubKey) (*ServerConn, bool) {
return l, ok
}

func (s *Server) connsCount() int {
func (s *Server) connCount() int {
s.mx.RLock()
count := len(s.conns)
n := len(s.conns)
s.mx.RUnlock()
return count
return n
}

// Close closes the dms_server.
Expand Down
8 changes: 4 additions & 4 deletions pkg/dmsg/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func TestServer_Serve(t *testing.T) {
require.NoError(t, aErr)

// must be 2 ServerConn's
require.Equal(t, 2, s.connsCount())
require.Equal(t, 2, s.connCount())

// must have ServerConn for A
aServerConn, ok := s.getConn(aPK)
Expand Down Expand Up @@ -253,7 +253,7 @@ func TestServer_Serve(t *testing.T) {
require.NoError(t, err)

require.NoError(t, testWithTimeout(5*time.Second, func() error {
if s.connsCount() != 0 {
if s.connCount() != 0 {
return errors.New("s.conns is not empty")
}

Expand Down Expand Up @@ -404,7 +404,7 @@ func TestServer_Serve(t *testing.T) {
require.NoError(t, err)

// check ServerConn's count
require.Equal(t, len(usedRemotes)+initiatorsCount, s.connsCount())
require.Equal(t, len(usedRemotes)+initiatorsCount, s.connCount())

for i, initiator := range initiators {
// get and check initiator's ServerConn
Expand Down Expand Up @@ -478,7 +478,7 @@ func TestServer_Serve(t *testing.T) {
}

require.NoError(t, testWithTimeout(10*time.Second, func() error {
if s.connsCount() != 0 {
if s.connCount() != 0 {
return errors.New("s.conns is not empty")
}

Expand Down

0 comments on commit e881d7f

Please sign in to comment.