Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clientv3/integration: Reduce flakines of TestGetTokenWithoutAuth #12200

Merged
merged 1 commit into from
Aug 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions clientv3/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,13 @@ func (c *Client) dial(target string, creds grpccredentials.TransportCredentials,

err = c.getToken(ctx)
if err != nil {
// TODO: Consider retrying transient errors like:
// "error":"rpc error: code = Unavailable desc = etcdserver: leader changed"

// Ignore rpctypes.ErrAuthNotEnabled error.
if toErr(ctx, err) != rpctypes.ErrAuthNotEnabled {
// This logic originates from 62d7bae496 and is not clear why we cannot just return err
// without looking into parent's context.
if err == ctx.Err() && ctx.Err() != c.ctx.Err() {
err = context.DeadlineExceeded
}
Expand Down
10 changes: 4 additions & 6 deletions clientv3/integration/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@ func authSetupRoot(t *testing.T, auth clientv3.Auth) {
}
}

// Client can connect to etcd even if they supply credentials and the server is in AuthDisable mode.
func TestGetTokenWithoutAuth(t *testing.T) {
defer testutil.AfterTest(t)

clus := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 10})
clus := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 2})
defer clus.Terminate(t)

authapi := clus.RandClient()
Expand All @@ -130,7 +131,7 @@ func TestGetTokenWithoutAuth(t *testing.T) {
// "Username" and "Password" must be used
cfg := clientv3.Config{
Endpoints: authapi.Endpoints(),
DialTimeout: 1 * time.Second, // make sure all connection time of connect all endpoint must be more DialTimeout
DialTimeout: 5 * time.Second,
Username: "root",
Password: "123",
}
Expand All @@ -142,13 +143,10 @@ func TestGetTokenWithoutAuth(t *testing.T) {

switch err {
case nil:
t.Log("passes as expected, but may be connection time less than DialTimeout")
t.Log("passes as expected")
case context.DeadlineExceeded:
t.Errorf("not expected result:%v with endpoint:%s", err, authapi.Endpoints())
case rpctypes.ErrAuthNotEnabled:
t.Logf("passes as expected:%v", err)
default:
t.Errorf("other errors:%v", err)
}

}