test(handler/router): fix pipe-based tests data race and pipe blocking issues

This commit is contained in:
ginuerzh
2026-06-04 09:04:57 +08:00
parent a4d45fa278
commit 1a1851fe03
2 changed files with 36 additions and 29 deletions
+5 -4
View File
@@ -364,10 +364,10 @@ func TestSdRenew_Cancel(t *testing.T) {
func TestSdRenew_NormalTick(t *testing.T) {
h := newInitdHandler(t)
var tickCount int
tickCh := make(chan struct{}, 10)
h.md.sd = &mockSD{
renewFn: func(ctx context.Context, svc *sd.Service) error {
tickCount++
tickCh <- struct{}{}
return nil
},
}
@@ -378,8 +378,9 @@ func TestSdRenew_NormalTick(t *testing.T) {
go h.sdRenew(ctx, "client-id", "connector-id")
time.Sleep(120 * time.Millisecond)
if tickCount == 0 {
select {
case <-tickCh:
case <-time.After(time.Second):
t.Error("Renew was never called")
}
}