mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
clientv3/integration: Fix flaky TestGetTokenWithoutAuth (#12200)
The test is vary flaky on Travis. Seems that since (https://github.com/etcd-io/etcd/issues/7724) the client is expected to simply ignore whether server is in AuthDisabled mode even if the user supplies credentials. The tests used to: * use very large cluster (10 nodes) * set very low timeout (1 sec) Such setup led to frequent deadlineExceed errors or following failures: === RUN TestGetTokenWithoutAuth {"level":"warn","ts":"2020-08-04T16:50:48.686+0200","caller":"clientv3/retry_interceptor.go:62","msg":"retrying of unary invoker failed","target":"endpoint://client-35573307-1ee5-441b-acc7-d073f0bd7de5/localhost:69820396562031027440","attempt":0,"error":"rpc error: code = Unavailable desc = etcdserver: leader changed"} user_test.go:151: other errors:etcdserver: leader changed --- FAIL: TestGetTokenWithoutAuth (10.91s)
This commit is contained in:
parent
f395f82a75
commit
9d182c2a70
@ -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
|
||||
}
|
||||
|
@ -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()
|
||||
@ -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",
|
||||
}
|
||||
@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user