Skip to content

Commit 5e7db39

Browse files
committed
test/channelz: Don't try to dial non-dialable addresses
On some platforms, dialing 127.0.0.1:0 doesn't fail immediately but rather blocks until it times out. This leads to test failures because the leak detector identifies stray goroutines. In this case, there's no need to actually dial and rely on OS-specific behavior. It's easier to err out directly. Signed-off-by: Tom Wieczorek <[email protected]>
1 parent 2d51986 commit 5e7db39

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

test/channelz_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package test
2121
import (
2222
"context"
2323
"crypto/tls"
24+
"errors"
2425
"fmt"
2526
"net"
2627
"regexp"
@@ -319,6 +320,11 @@ func (s) TestCZNestedChannelRegistrationAndDeletion(t *testing.T) {
319320
e := tcpClearRREnv
320321
// avoid calling API to set balancer type, which will void service config's change of balancer.
321322
e.balancer = ""
323+
e.customDialer = func(network, addr string, timeout time.Duration) (net.Conn, error) {
324+
// Short-circuit the intentional 127.0.0.1:0 placeholder to avoid
325+
// leakcheck flakes on platforms where dialing :0 blocks until timeout.
326+
return nil, errors.New("intentionally failing to dial")
327+
}
322328
te := newTest(t, e)
323329
r := manual.NewBuilderWithScheme("whatever")
324330
te.resolverScheme = r.Scheme()
@@ -1500,6 +1506,11 @@ func (s) TestCZChannelTraceCreationDeletion(t *testing.T) {
15001506
e := tcpClearRREnv
15011507
// avoid calling API to set balancer type, which will void service config's change of balancer.
15021508
e.balancer = ""
1509+
e.customDialer = func(network, addr string, timeout time.Duration) (net.Conn, error) {
1510+
// Short-circuit the intentional 127.0.0.1:0 placeholder to avoid
1511+
// leakcheck flakes on platforms where dialing :0 blocks until timeout.
1512+
return nil, errors.New("intentionally failing to dial")
1513+
}
15031514
te := newTest(t, e)
15041515
r := manual.NewBuilderWithScheme("whatever")
15051516
te.resolverScheme = r.Scheme()
@@ -2008,6 +2019,11 @@ func (s) TestCZChannelConnectivityState(t *testing.T) {
20082019
func (s) TestCZTraceOverwriteChannelDeletion(t *testing.T) {
20092020
e := tcpClearRREnv
20102021
e.balancer = ""
2022+
e.customDialer = func(network, addr string, timeout time.Duration) (net.Conn, error) {
2023+
// Short-circuit the intentional 127.0.0.1:0 placeholder to avoid
2024+
// leakcheck flakes on platforms where dialing :0 blocks until timeout.
2025+
return nil, errors.New("intentionally failing to dial")
2026+
}
20112027
te := newTest(t, e)
20122028
channelz.SetMaxTraceEntry(1)
20132029
defer channelz.ResetMaxTraceEntryToDefault()

0 commit comments

Comments
 (0)