MCPcopy
hub / github.com/etcd-io/etcd / TestDialCancel

Function TestDialCancel

client/v3/client_test.go:47–94  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

45}
46
47func TestDialCancel(t *testing.T) {
48 testutil.RegisterLeakDetection(t)
49
50 // accept first connection so client is created with dial timeout
51 ln, err := net.Listen("unix", "dialcancel:12345")
52 require.NoError(t, err)
53 defer ln.Close()
54
55 ep := "unix://dialcancel:12345"
56 cfg := Config{
57 Endpoints: []string{ep},
58 DialTimeout: 30 * time.Second,
59 }
60 c, err := NewClient(t, cfg)
61 require.NoError(t, err)
62
63 // connect to ipv4 black hole so dial blocks
64 c.SetEndpoints("http://254.0.0.1:12345")
65
66 // issue Get to force redial attempts
67 getc := make(chan struct{})
68 go func() {
69 defer close(getc)
70 // Get may hang forever on grpc's Stream.Header() if its
71 // context is never canceled.
72 c.Get(c.Ctx(), "abc")
73 }()
74
75 // wait a little bit so client close is after dial starts
76 time.Sleep(100 * time.Millisecond)
77
78 donec := make(chan struct{})
79 go func() {
80 defer close(donec)
81 c.Close()
82 }()
83
84 select {
85 case <-time.After(5 * time.Second):
86 t.Fatalf("failed to close")
87 case <-donec:
88 }
89 select {
90 case <-time.After(5 * time.Second):
91 t.Fatalf("get failed to exit")
92 case <-getc:
93 }
94}
95
96func TestDialTimeout(t *testing.T) {
97 testutil.RegisterLeakDetection(t)

Callers

nothing calls this directly

Calls 7

SetEndpointsMethod · 0.95
GetMethod · 0.95
CtxMethod · 0.95
CloseMethod · 0.95
NewClientFunction · 0.70
CloseMethod · 0.65
FatalfMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…