|
|
@@ -81,33 +81,45 @@ func TestDialCancel(t *testing.T) {
|
|
|
func TestDialTimeout(t *testing.T) {
|
|
|
defer testutil.AfterTest(t)
|
|
|
|
|
|
- donec := make(chan error)
|
|
|
- go func() {
|
|
|
- // without timeout, dial continues forever on ipv4 blackhole
|
|
|
- cfg := Config{
|
|
|
+ testCfgs := []Config{
|
|
|
+ Config{
|
|
|
Endpoints: []string{"http://254.0.0.1:12345"},
|
|
|
- DialTimeout: 2 * time.Second}
|
|
|
- c, err := New(cfg)
|
|
|
- if c != nil || err == nil {
|
|
|
- t.Errorf("new client should fail")
|
|
|
- }
|
|
|
- donec <- err
|
|
|
- }()
|
|
|
-
|
|
|
- time.Sleep(10 * time.Millisecond)
|
|
|
-
|
|
|
- select {
|
|
|
- case err := <-donec:
|
|
|
- t.Errorf("dial didn't wait (%v)", err)
|
|
|
- default:
|
|
|
+ DialTimeout: 2 * time.Second,
|
|
|
+ },
|
|
|
+ Config{
|
|
|
+ Endpoints: []string{"http://254.0.0.1:12345"},
|
|
|
+ DialTimeout: time.Second,
|
|
|
+ Username: "abc",
|
|
|
+ Password: "def",
|
|
|
+ },
|
|
|
}
|
|
|
|
|
|
- select {
|
|
|
- case <-time.After(5 * time.Second):
|
|
|
- t.Errorf("failed to timeout dial on time")
|
|
|
- case err := <-donec:
|
|
|
- if err != grpc.ErrClientConnTimeout {
|
|
|
- t.Errorf("unexpected error %v, want %v", err, grpc.ErrClientConnTimeout)
|
|
|
+ for i, cfg := range testCfgs {
|
|
|
+ donec := make(chan error)
|
|
|
+ go func() {
|
|
|
+ // without timeout, dial continues forever on ipv4 blackhole
|
|
|
+ c, err := New(cfg)
|
|
|
+ if c != nil || err == nil {
|
|
|
+ t.Errorf("#%d: new client should fail", i)
|
|
|
+ }
|
|
|
+ donec <- err
|
|
|
+ }()
|
|
|
+
|
|
|
+ time.Sleep(10 * time.Millisecond)
|
|
|
+
|
|
|
+ select {
|
|
|
+ case err := <-donec:
|
|
|
+ t.Errorf("#%d: dial didn't wait (%v)", i, err)
|
|
|
+ default:
|
|
|
+ }
|
|
|
+
|
|
|
+ select {
|
|
|
+ case <-time.After(5 * time.Second):
|
|
|
+ t.Errorf("#%d: failed to timeout dial on time", i)
|
|
|
+ case err := <-donec:
|
|
|
+ if err != grpc.ErrClientConnTimeout {
|
|
|
+ t.Errorf("#%d: unexpected error %v, want %v", i, err, grpc.ErrClientConnTimeout)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|