Skip to content

Commit

Permalink
tests: fix disconnect handling
Browse files Browse the repository at this point in the history
Signed-off-by: Jaime Caamaño Ruiz <jcaamano@redhat.com>
  • Loading branch information
jcaamano committed Jun 6, 2022
1 parent bd57ef7 commit 5f6ce60
Showing 1 changed file with 39 additions and 36 deletions.
75 changes: 39 additions & 36 deletions test/ovs/ovs_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,25 +156,27 @@ func (suite *OVSIntegrationSuite) TestConnectReconnect() {
err = suite.client.Connect(ctx)
require.NoError(suite.T(), err)

// set up a disconnect notification
disconnectNotification := suite.client.DisconnectNotify()
notified := make(chan struct{})
ready := make(chan struct{})

go func() {
ready <- struct{}{}
<-disconnectNotification
notified <- struct{}{}
<-ready
suite.client.Close()
}()

<-ready
suite.client.Disconnect()

select {
case <-notified:
// got notification
case <-time.After(5 * time.Second):
suite.T().Fatal("expected a disconnect notification but didn't receive one")
}
func() {
for {
select {
case ready <- struct{}{}:
case <-disconnectNotification:
// got notification
return
case <-time.After(5 * time.Second):
suite.T().Fatal("expected a disconnect notification but didn't receive one")
}
}
}()

assert.Equal(suite.T(), false, suite.client.Connected())

Expand Down Expand Up @@ -293,39 +295,40 @@ func (suite *OVSIntegrationSuite) TestWithReconnect() {
_, err = suite.createBridge(bridgeName)
require.NoError(suite.T(), err)

LOOP:
for {
select {
case <-time.After(5 * time.Second):
suite.T().Fatal("timed out waiting for bridge")
case b := <-brChan:
if b.Name == bridgeName {
break LOOP
func() {
for {
select {
case <-time.After(5 * time.Second):
suite.T().Fatal("timed out waiting for bridge")
case b := <-brChan:
if b.Name == bridgeName {
return
}
}
}
}
}()

// set up a disconnect notification
disconnectNotification := suite.client.DisconnectNotify()
notified := make(chan struct{})
ready := make(chan struct{})

go func() {
ready <- struct{}{}
<-disconnectNotification
notified <- struct{}{}
<-ready
suite.client.Close()
}()

<-ready
// close the connection
suite.client.Close()

select {
case <-notified:
// got notification
case <-time.After(5 * time.Second):
suite.T().Fatal("expected a disconnect notification but didn't receive one")
}
func() {
for {
select {
case ready <- struct{}{}:
case <-disconnectNotification:
// got notification
return
case <-time.After(5 * time.Second):
suite.T().Fatal("expected a disconnect notification but didn't receive one")
}
}
}()

assert.Equal(suite.T(), false, suite.client.Connected())

Expand Down

0 comments on commit 5f6ce60

Please sign in to comment.