clientv3: test dial timeout is respected when using auth
@@ -81,15 +81,26 @@ func TestDialCancel(t *testing.T) {
func TestDialTimeout(t *testing.T) {
defer testutil.AfterTest(t)
+ testCfgs := []Config{
+ Config{
+ Endpoints: []string{"http://254.0.0.1:12345"},
+ DialTimeout: 2 * time.Second,
+ },
+ Config{
+ Endpoints: []string{"http://254.0.0.1:12345"},
+ DialTimeout: time.Second,
+ Username: "abc",
+ Password: "def",
+ },
+ }
+
+ for i, cfg := range testCfgs {
donec := make(chan error)
go func() {
// without timeout, dial continues forever on ipv4 blackhole
- cfg := 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")
+ t.Errorf("#%d: new client should fail", i)
}
donec <- err
}()
@@ -98,16 +109,17 @@ func TestDialTimeout(t *testing.T) {
select {
case err := <-donec:
- t.Errorf("dial didn't wait (%v)", err)
+ t.Errorf("#%d: dial didn't wait (%v)", i, err)
default:
}
select {
case <-time.After(5 * time.Second):
- t.Errorf("failed to timeout dial on time")
+ t.Errorf("#%d: failed to timeout dial on time", i)
case err := <-donec:
if err != grpc.ErrClientConnTimeout {
- t.Errorf("unexpected error %v, want %v", err, grpc.ErrClientConnTimeout)
+ t.Errorf("#%d: unexpected error %v, want %v", i, err, grpc.ErrClientConnTimeout)
+ }
}
}
}
