Skip to content

Commit ec2bf88

Browse files
committed
Fix issue-7363 and add remaining tests from c-core
1 parent 5bfc245 commit ec2bf88

File tree

5 files changed

+541
-46
lines changed

5 files changed

+541
-46
lines changed

internal/testutils/blocking_context_dialer.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,13 @@ func (h *Hold) Fail(err error) {
123123
h.err = err // synchronized via blockCh.
124124
close(h.blockCh)
125125
}
126+
127+
// IsStarted returns true if this hold has received a connection attempt.
128+
func (h *Hold) IsStarted() bool {
129+
select {
130+
case <-h.waitCh:
131+
return true
132+
default:
133+
return false
134+
}
135+
}

internal/testutils/blocking_context_dialer_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ func (s) TestBlockingDialer_HoldWaitResume(t *testing.T) {
5656
d := NewBlockingDialer()
5757
h := d.Hold(lis.Addr().String())
5858

59+
if h.IsStarted() {
60+
t.Fatalf("hold.IsStarted() = true, want false")
61+
}
62+
5963
done := make(chan struct{})
6064
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
6165
defer cancel()
@@ -64,6 +68,11 @@ func (s) TestBlockingDialer_HoldWaitResume(t *testing.T) {
6468
if err != nil {
6569
t.Errorf("BlockingDialer.DialContext() got error: %v, want success", err)
6670
}
71+
72+
if !h.IsStarted() {
73+
t.Errorf("hold.IsStarted() = false, want true")
74+
}
75+
6776
conn.Close()
6877
done <- struct{}{}
6978
}()
@@ -72,6 +81,11 @@ func (s) TestBlockingDialer_HoldWaitResume(t *testing.T) {
7281
if !h.Wait(ctx) {
7382
t.Fatalf("Timeout while waiting for a connection attempt to %q", h.addr)
7483
}
84+
85+
if !h.IsStarted() {
86+
t.Errorf("hold.IsStarted() = false, want true")
87+
}
88+
7589
select {
7690
case <-done:
7791
t.Errorf("Expected dialer to be blocked.")

0 commit comments

Comments
 (0)