Unified storage search: Introduce min index update interval (#111978)
* Don't update index more often than specified index_min_update_interval. * Add artificial sleep at the end of write operations. * Improve test: check for number of update calls, make diff check less flaky. * Make test less flaky by allowing for higher diff variance. * Make test less flaky by allowing for expected update calls variance.
This commit is contained in:
@@ -3,6 +3,7 @@ package resource
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
@@ -21,6 +22,7 @@ import (
|
||||
|
||||
authlib "github.com/grafana/authlib/types"
|
||||
"github.com/grafana/dskit/services"
|
||||
|
||||
"github.com/grafana/grafana/pkg/apimachinery/identity"
|
||||
"github.com/grafana/grafana/pkg/apimachinery/utils"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
@@ -587,3 +589,30 @@ func newTestServerWithQueue(t *testing.T, maxSizePerTenant int, numWorkers int)
|
||||
}
|
||||
return s, q
|
||||
}
|
||||
|
||||
func TestArtificialDelayAfterSuccessfulOperation(t *testing.T) {
|
||||
s := &server{artificialSuccessfulWriteDelay: 1 * time.Millisecond}
|
||||
|
||||
check := func(t *testing.T, expectedSleep bool, res responseWithErrorResult, err error) {
|
||||
slept := s.sleepAfterSuccessfulWriteOperation(res, err)
|
||||
require.Equal(t, expectedSleep, slept)
|
||||
}
|
||||
|
||||
// Successful responses should sleep
|
||||
check(t, true, nil, nil)
|
||||
|
||||
check(t, true, (responseWithErrorResult)((*resourcepb.CreateResponse)(nil)), nil)
|
||||
check(t, true, &resourcepb.CreateResponse{}, nil)
|
||||
|
||||
check(t, true, (responseWithErrorResult)((*resourcepb.UpdateResponse)(nil)), nil)
|
||||
check(t, true, &resourcepb.UpdateResponse{}, nil)
|
||||
|
||||
check(t, true, (responseWithErrorResult)((*resourcepb.DeleteResponse)(nil)), nil)
|
||||
check(t, true, &resourcepb.DeleteResponse{}, nil)
|
||||
|
||||
// Failed responses should return without sleeping
|
||||
check(t, false, nil, errors.New("some error"))
|
||||
check(t, false, &resourcepb.CreateResponse{Error: AsErrorResult(errors.New("some error"))}, nil)
|
||||
check(t, false, &resourcepb.UpdateResponse{Error: AsErrorResult(errors.New("some error"))}, nil)
|
||||
check(t, false, &resourcepb.DeleteResponse{Error: AsErrorResult(errors.New("some error"))}, nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user