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

Fixes a flaky hedging test. #5389

Merged
merged 1 commit into from
Feb 15, 2022
Merged
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
18 changes: 11 additions & 7 deletions pkg/storage/chunk/azure/blob_storage_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package azure
import (
"bytes"
"context"
"errors"
"net/http"
"strings"
"testing"
"time"

Expand All @@ -14,14 +14,15 @@ import (
"github.com/grafana/loki/pkg/storage/chunk/hedging"
)

var metrics = NewBlobStorageMetrics()

type RoundTripperFunc func(*http.Request) (*http.Response, error)

func (fn RoundTripperFunc) RoundTrip(req *http.Request) (*http.Response, error) {
return fn(req)
}

func Test_Hedging(t *testing.T) {
metrics := NewBlobStorageMetrics()
for _, tc := range []struct {
name string
expectedCalls int32
Expand All @@ -31,7 +32,7 @@ func Test_Hedging(t *testing.T) {
}{
{
"delete/put/list are not hedged",
4, // Put makes an additional call to close the stream
3,
20 * time.Nanosecond,
10,
func(c *BlobStorage) {
Expand Down Expand Up @@ -66,9 +67,12 @@ func Test_Hedging(t *testing.T) {
defaultClientFactory = func() *http.Client {
return &http.Client{
Transport: RoundTripperFunc(func(req *http.Request) (*http.Response, error) {
count.Inc()
time.Sleep(200 * time.Millisecond)
return nil, errors.New("fo")
// blocklist is a call that can be fired by the SDK after PUT but is not guaranteed.
if !strings.Contains(req.URL.String(), "blocklist") {
count.Inc()
time.Sleep(50 * time.Millisecond)
}
return nil, http.ErrNotSupported
}),
}
}
Expand All @@ -88,7 +92,7 @@ func Test_Hedging(t *testing.T) {
require.NoError(t, err)

tc.do(c)
require.Eventually(t, func() bool { return tc.expectedCalls == count.Load() }, time.Second, time.Millisecond)
require.Eventually(t, func() bool { return tc.expectedCalls == count.Load() }, time.Second, time.Millisecond, "expected calls %d, got %d", tc.expectedCalls, count.Load())
})
}
}