Skip to content

Commit

Permalink
Fix issue-7363 and add remaining tests from c-core
Browse files Browse the repository at this point in the history
  • Loading branch information
atollena committed Jun 28, 2024
1 parent 5bfc245 commit fd418d4
Show file tree
Hide file tree
Showing 5 changed files with 536 additions and 46 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 @@ -123,3 +123,13 @@ func (h *Hold) Fail(err error) {
h.err = err // synchronized via blockCh.
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
}
}
14 changes: 14 additions & 0 deletions internal/testutils/blocking_context_dialer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,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 @@ -64,6 +68,11 @@ func (s) TestBlockingDialer_HoldWaitResume(t *testing.T) {
if err != nil {
t.Errorf("BlockingDialer.DialContext() got error: %v, want success", err)
}

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

conn.Close()
done <- struct{}{}
}()
Expand All @@ -72,6 +81,11 @@ func (s) TestBlockingDialer_HoldWaitResume(t *testing.T) {
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.Errorf("Expected dialer to be blocked.")
Expand Down
Loading

0 comments on commit fd418d4

Please sign in to comment.