Fix `TestSessionSuite/TestKeepAliveRetryActiveCancel` unit test logic (#27231)

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
pull/27275/head
congqixia 2023-09-20 18:59:23 +08:00 committed by GitHub
parent 773080df24
commit 16b35e07b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 6 deletions

View File

@ -800,6 +800,7 @@ func (s *Session) LivenessCheck(ctx context.Context, callback func()) {
go func() {
defer s.wg.Done()
for {
defer s.SetDisconnected(true)
select {
case _, ok := <-s.liveCh:
// ok, still alive
@ -808,7 +809,6 @@ func (s *Session) LivenessCheck(ctx context.Context, callback func()) {
}
// not ok, connection lost
log.Warn("connection lost detected, shuting down")
s.SetDisconnected(true)
if callback != nil {
go callback()
}

View File

@ -919,17 +919,15 @@ func (s *SessionSuite) TestKeepAliveRetryActiveCancel() {
// Register
ch, err := session.registerService()
if err != nil {
panic(err)
}
s.Require().NoError(err)
session.liveCh = make(chan struct{})
session.processKeepAliveResponse(ch)
session.LivenessCheck(ctx, nil)
// active cancel, should not retry connect
session.cancelKeepAlive()
// sleep a while wait goroutine process
time.Sleep(time.Millisecond * 100)
// wait workers exit
session.wg.Wait()
// expected Disconnected = true, means session is closed
assert.Equal(s.T(), true, session.Disconnected())
}