Skip to content

Commit fbe980a

Browse files
committed
test(buckets): Remove potentially flaky timeout test
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.
1 parent 1bbb90c commit fbe980a

File tree

1 file changed

+0
-45
lines changed

1 file changed

+0
-45
lines changed

api/clients/buckets/bucket_test.go

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package buckets_test
1616

1717
import (
18-
"context"
1918
"encoding/json"
2019
"fmt"
2120
"github.com/dynatrace/dynatrace-configuration-as-code-core/api"
@@ -27,7 +26,6 @@ import (
2726
"net/http"
2827
"net/http/httptest"
2928
"net/url"
30-
"strings"
3129
"testing"
3230
"time"
3331
)
@@ -896,49 +894,6 @@ func TestUpdate(t *testing.T) {
896894
assert.Equal(t, "bucket name", m["bucketName"])
897895
})
898896

899-
t.Run("Update honors context timeout", func(t *testing.T) {
900-
var firstTry = true
901-
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
902-
switch req.Method {
903-
case http.MethodPost:
904-
rw.WriteHeader(http.StatusForbidden)
905-
rw.Write([]byte("no, this is an error"))
906-
case http.MethodGet:
907-
rw.Write([]byte(someBucketResponse))
908-
case http.MethodPut:
909-
if firstTry {
910-
rw.WriteHeader(http.StatusConflict)
911-
rw.Write([]byte("conflict"))
912-
firstTry = false
913-
} else {
914-
rw.WriteHeader(http.StatusOK)
915-
rw.Write([]byte(someBucketResponse))
916-
}
917-
default:
918-
assert.Failf(t, "unexpected method %q", req.Method)
919-
}
920-
}))
921-
defer server.Close()
922-
923-
u, _ := url.Parse(server.URL)
924-
client := buckets.NewClient(rest.NewClient(u, &http.Client{}),
925-
buckets.WithRetrySettings(5, 0, time.Minute)) // maxWaitDuration would allow 1 min
926-
data := []byte("{}")
927-
928-
ctx := testutils.ContextWithLogger(t)
929-
ctx, cancel := context.WithTimeout(ctx, 800*time.Microsecond) // context "should" time out after initial GET
930-
defer cancel()
931-
_, err := client.Update(ctx, "bucket name", data)
932-
assert.Error(t, err)
933-
934-
// 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.
935-
if strings.Contains(err.Error(), "deadline exceeded") {
936-
t.Log("context timed out before our logic and http request returned error")
937-
return
938-
}
939-
assert.ErrorContains(t, err, "cancelled")
940-
})
941-
942897
t.Run("Update honors retrySettings maxWaitDuration", func(t *testing.T) {
943898
var firstTry = true
944899
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {

0 commit comments

Comments
 (0)