Skip to content

Commit

Permalink
test(buckets): Remove potentially flaky timeout test
Browse files Browse the repository at this point in the history
Testing whether the Update methods' retries honor timeout passed
via the context is timing based and potentially flaky - we have
already seen it fail in CI when running on windows, but work on
other OSs.

The test is removed, as there is no real value in testing with an assured immediate
timeout, as that would trigger a failure in the initial http
GET call (as http requests of course honor context timeouts)
instead of testing our retry logic.

In the worst case, the http requsts we make would honor the context timeout anyway.
  • Loading branch information
UnseenWizzard committed Sep 7, 2023
1 parent 1bbb90c commit fbe980a
Showing 1 changed file with 0 additions and 45 deletions.
45 changes: 0 additions & 45 deletions api/clients/buckets/bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package buckets_test

import (
"context"
"encoding/json"
"fmt"
"github.com/dynatrace/dynatrace-configuration-as-code-core/api"
Expand All @@ -27,7 +26,6 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"strings"
"testing"
"time"
)
Expand Down Expand Up @@ -896,49 +894,6 @@ func TestUpdate(t *testing.T) {
assert.Equal(t, "bucket name", m["bucketName"])
})

t.Run("Update honors context timeout", func(t *testing.T) {
var firstTry = true
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
switch req.Method {
case http.MethodPost:
rw.WriteHeader(http.StatusForbidden)
rw.Write([]byte("no, this is an error"))
case http.MethodGet:
rw.Write([]byte(someBucketResponse))
case http.MethodPut:
if firstTry {
rw.WriteHeader(http.StatusConflict)
rw.Write([]byte("conflict"))
firstTry = false
} else {
rw.WriteHeader(http.StatusOK)
rw.Write([]byte(someBucketResponse))
}
default:
assert.Failf(t, "unexpected method %q", req.Method)
}
}))
defer server.Close()

u, _ := url.Parse(server.URL)
client := buckets.NewClient(rest.NewClient(u, &http.Client{}),
buckets.WithRetrySettings(5, 0, time.Minute)) // maxWaitDuration would allow 1 min
data := []byte("{}")

ctx := testutils.ContextWithLogger(t)
ctx, cancel := context.WithTimeout(ctx, 800*time.Microsecond) // context "should" time out after initial GET
defer cancel()
_, err := client.Update(ctx, "bucket name", data)
assert.Error(t, err)

// if GET happens to be cancelled already we'll get a 'deadline exceeded' from the http client. That's ok too, no need to fail the test.
if strings.Contains(err.Error(), "deadline exceeded") {
t.Log("context timed out before our logic and http request returned error")
return
}
assert.ErrorContains(t, err, "cancelled")
})

t.Run("Update honors retrySettings maxWaitDuration", func(t *testing.T) {
var firstTry = true
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
Expand Down

0 comments on commit fbe980a

Please sign in to comment.