Skip to content

Commit

Permalink
Ensure getConns is being used instead of direct access for Client
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkren committed Jun 15, 2019
1 parent e881d7f commit 0815e6b
Showing 1 changed file with 8 additions and 22 deletions.
30 changes: 8 additions & 22 deletions pkg/dmsg/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,13 @@ func TestServerConn_AddNext(t *testing.T) {
wg.Wait()

for i := uint16(1); i < uint16(connsCount*2); i += 2 {
require.NotNil(t, serverConn.nextConns[i])
_, ok := serverConn.getNext(i)
require.Equal(t, true, ok)
}

for i := uint16(connsCount*2 + 1); i != 1; i += 2 {
require.Nil(t, serverConn.nextConns[i])
_, ok := serverConn.getNext(i)
require.Equal(t, false, ok)
}
}

Expand Down Expand Up @@ -261,23 +263,15 @@ func TestServer_Serve(t *testing.T) {
}))

require.NoError(t, testWithTimeout(5*time.Second, func() error {
a.mx.Lock()
l := len(a.conns)
a.mx.Unlock()

if l != 0 {
if a.connCount() != 0 {
return errors.New("a.conns is not empty")
}

return nil
}))

require.NoError(t, testWithTimeout(5*time.Second, func() error {
b.mx.Lock()
l := len(b.conns)
b.mx.Unlock()

if l != 0 {
if b.connCount() != 0 {
return errors.New("b.conns is not empty")
}

Expand Down Expand Up @@ -487,11 +481,7 @@ func TestServer_Serve(t *testing.T) {

for i, remote := range remotes {
require.NoError(t, testWithTimeout(10*time.Second, func() error {
remote.mx.Lock()
l := len(remote.conns)
remote.mx.Unlock()

if l != 0 {
if remote.connCount() != 0 {
return errors.New(fmt.Sprintf("remotes[%v].conns is not empty", i))
}

Expand All @@ -501,11 +491,7 @@ func TestServer_Serve(t *testing.T) {

for i, initiator := range initiators {
require.NoError(t, testWithTimeout(10*time.Second, func() error {
initiator.mx.Lock()
l := len(initiator.conns)
initiator.mx.Unlock()

if l != 0 {
if initiator.connCount() != 0 {
return errors.New(fmt.Sprintf("initiators[%v].conns is not empty", i))
}

Expand Down

0 comments on commit 0815e6b

Please sign in to comment.