Skip to content

Commit

Permalink
ringhash: fix bug where ring hash can be stuck in transient failure d…
Browse files Browse the repository at this point in the history
…espite having available endpoints (#7364)
  • Loading branch information
atollena authored Aug 20, 2024
1 parent 1e2bb71 commit ee5cbce
Show file tree
Hide file tree
Showing 5 changed files with 490 additions and 42 deletions.
10 changes: 10 additions & 0 deletions internal/testutils/blocking_context_dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,13 @@ func (h *Hold) Fail(err error) {
h.blockCh <- err
close(h.blockCh)
}

// IsStarted returns true if this hold has received a connection attempt.
func (h *Hold) IsStarted() bool {
select {
case <-h.waitCh:
return true
default:
return false
}
}
13 changes: 13 additions & 0 deletions internal/testutils/blocking_context_dialer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ func (s) TestBlockingDialer_HoldWaitResume(t *testing.T) {
d := NewBlockingDialer()
h := d.Hold(lis.Addr().String())

if h.IsStarted() {
t.Fatalf("hold.IsStarted() = true, want false")
}

done := make(chan struct{})
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
defer cancel()
Expand All @@ -69,13 +73,22 @@ func (s) TestBlockingDialer_HoldWaitResume(t *testing.T) {
t.Errorf("BlockingDialer.DialContext() got error: %v, want success", err)
return
}

if !h.IsStarted() {
t.Errorf("hold.IsStarted() = false, want true")
}
conn.Close()
}()

// This should block until the goroutine above is scheduled.
if !h.Wait(ctx) {
t.Fatalf("Timeout while waiting for a connection attempt to %q", h.addr)
}

if !h.IsStarted() {
t.Errorf("hold.IsStarted() = false, want true")
}

select {
case <-done:
t.Fatalf("Expected dialer to be blocked.")
Expand Down
Loading

0 comments on commit ee5cbce

Please sign in to comment.