Refine `TestSessionProcessActiveStandBy` unit test logic (#26980)

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
pull/26999/head
congqixia 2023-09-11 18:13:17 +08:00 committed by GitHub
parent 754500f1c8
commit adfb5298c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 7 deletions

View File

@ -603,8 +603,7 @@ func TestSessionProcessActiveStandBy(t *testing.T) {
defer etcdKV.RemoveWithPrefix("") defer etcdKV.RemoveWithPrefix("")
var wg sync.WaitGroup var wg sync.WaitGroup
ch := make(chan struct{}) signal := make(chan struct{})
signal := make(chan struct{}, 1)
flag := false flag := false
// register session 1, will be active // register session 1, will be active
@ -614,15 +613,15 @@ func TestSessionProcessActiveStandBy(t *testing.T) {
s1.SetEnableActiveStandBy(true) s1.SetEnableActiveStandBy(true)
s1.Register() s1.Register()
wg.Add(1) wg.Add(1)
s1.liveCh = ch
s1.ProcessActiveStandBy(func() error { s1.ProcessActiveStandBy(func() error {
log.Debug("Session 1 become active") log.Debug("Session 1 become active")
wg.Done() wg.Done()
return nil return nil
}) })
wg.Wait()
s1.LivenessCheck(ctx1, func() { s1.LivenessCheck(ctx1, func() {
flag = true flag = true
signal <- struct{}{} close(signal)
s1.cancelKeepAlive() s1.cancelKeepAlive()
}) })
assert.False(t, s1.isStandby.Load().(bool)) assert.False(t, s1.isStandby.Load().(bool))
@ -645,14 +644,14 @@ func TestSessionProcessActiveStandBy(t *testing.T) {
// stop session 1, session 2 will take over primary service // stop session 1, session 2 will take over primary service
log.Debug("Stop session 1, session 2 will take over primary service") log.Debug("Stop session 1, session 2 will take over primary service")
assert.False(t, flag) assert.False(t, flag)
ch <- struct{}{}
assert.False(t, flag) s1.Stop()
s1.safeCloseLiveCh()
<-signal <-signal
assert.True(t, flag) assert.True(t, flag)
wg.Wait() wg.Wait()
assert.False(t, s2.isStandby.Load().(bool)) assert.False(t, s2.isStandby.Load().(bool))
s2.Stop()
} }
func TestSessionEventType_String(t *testing.T) { func TestSessionEventType_String(t *testing.T) {