From e4e8a1c0b333a226ff60a4bbb1dc563d04b518d7 Mon Sep 17 00:00:00 2001 From: Renan DelValle Date: Tue, 18 Dec 2018 17:14:48 -0800 Subject: [PATCH] Adding a check for 401. This reduces the retries on the end to end test and fails fast when a wrong/unathorized username and password are provided to interact with Aurora. --- realis_e2e_test.go | 7 ++++--- retry.go | 9 +++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/realis_e2e_test.go b/realis_e2e_test.go index e4047b4..2cc79b8 100644 --- a/realis_e2e_test.go +++ b/realis_e2e_test.go @@ -87,7 +87,8 @@ func TestNonExistentEndpoint(t *testing.T) { func TestBadCredentials(t *testing.T) { r, err := realis.NewClient(realis.SchedulerUrl("http://192.168.33.7:8081"), - realis.BasicAuth("incorrect", "password")) + realis.BasicAuth("incorrect", "password"), + realis.Debug()) defer r.Close() assert.NoError(t, err) @@ -246,13 +247,13 @@ func TestRealisClient_CreateJob_Thermos(t *testing.T) { assert.True(t, success) assert.NoError(t, err) - //Fetch all Jobs + // Fetch all Jobs result, err := r.GetJobs(role) fmt.Printf("GetJobs length: %+v \n", len(result.Configs)) assert.Len(t, result.Configs, 1) assert.NoError(t, err) - // Test asking the scheduler to perform a Snpshot + // Test asking the scheduler to perform a Snapshot t.Run("TestRealisClient_Snapshot", func(t *testing.T) { err := r.Snapshot() assert.NoError(t, err) diff --git a/retry.go b/retry.go index 26291cd..59d0aa0 100644 --- a/retry.go +++ b/retry.go @@ -17,7 +17,10 @@ package realis import ( "io" "math/rand" + "net/http" "net/url" + "strconv" + "strings" "time" "git.apache.org/thrift.git/lib/go/thrift" @@ -163,6 +166,12 @@ func (c *Client) thriftCallWithRetries(thriftCall auroraThriftCall) (*aurora.Res if ok { c.logger.DebugPrint("Encountered a transport exception") + // TODO(rdelvalle): Figure out a better way to obtain the error code as this is a very brittle solution + // 401 Unauthorized means the wrong username and password were provided + if strings.Contains(e.Error(), strconv.Itoa(http.StatusUnauthorized)) { + return nil, errors.Wrap(clientErr, "wrong username or password provided") + } + e, ok := e.Err().(*url.Error) if ok { // EOF error occurs when the server closes the read buffer of the client. This is common