Skip to content

Git designed for AI agents.

tests: two load-dependent failures, made independent of the load

Federico Eliad00e2556d7d9
diff --git a/internal/graft/corestore/syncer/syncer_rounds_test.go b/internal/graft/corestore/syncer/syncer_rounds_test.go
index 9c07bb0..7efa458 100644
--- a/internal/graft/corestore/syncer/syncer_rounds_test.go
+++ b/internal/graft/corestore/syncer/syncer_rounds_test.go
@@ -52,6 +52,12 @@ func TestSyncerSeedsInTheBackground(t *testing.T) {
<-seeding
require.Equal(t, float64(3), syncCount(t, b.sy, "seeding"))
+ // The short budget is for the rounds while the seed runs. The catch-up after it applies the
+ // changesets since the checkpoint, and a round that cannot finish that within its budget, as
+ // a heavily loaded node may not in 400ms, answers Unavailable every time (the sync_timeout
+ // contract): the catch-up gets the default budget. The seed goroutine reads it only after
+ // close(release).
+ b.core.SyncTimeout = 10 * time.Second
close(release)
require.Eventually(t, func() bool {
return b.sy.EnsureFresh(b.ctx, b.pbRepo(localRelPath)) == nil
diff --git a/sdk/land_retry_test.go b/sdk/land_retry_test.go
index 3be407f..5d35e48 100644
--- a/sdk/land_retry_test.go
+++ b/sdk/land_retry_test.go
@@ -7,6 +7,7 @@ import (
"time"
"github.com/stretchr/testify/require"
+ "google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
@@ -173,18 +174,25 @@ func TestRepo_Land_ContextStopsTheRetries(t *testing.T) {
fakes := newFakeServices()
fakes.operations.landErr = status.Error(codes.Unavailable, "still syncing")
- repo := dialFake(t, fakes.register).Repo("repo")
- // The backoff is longer than the context, which ends during the first wait.
- ctx, cancel := context.WithTimeout(t.Context(), 50*time.Millisecond)
+ // The context ends once the client has the first Unavailable, so during the wait before the
+ // first retry, whatever the time the call took.
+ ctx, cancel := context.WithCancel(t.Context())
defer cancel()
+ cancelAfterUnavailable := func(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
+ err := invoker(ctx, method, req, reply, cc, opts...)
+ if status.Code(err) == codes.Unavailable {
+ cancel()
+ }
+ return err
+ }
+ repo := dialFake(t, fakes.register, sdk.WithGRPCOptions(grpc.WithUnaryInterceptor(cancelAfterUnavailable))).Repo("repo")
+
opts := mergeLand()
opts.RetryUnavailable = sdk.UnavailableRetry{Base: time.Hour, Cap: time.Hour}
- // Each wait is drawn from [0, 1h]: the context ends during one of them unless five draws in
- // a row fall below 50ms.
_, err := repo.Land(ctx, opts)
- require.Equal(t, codes.DeadlineExceeded, sdk.Code(err))
- require.Less(t, len(fakes.operations.landRequests), 6)
+ require.Equal(t, codes.Canceled, sdk.Code(err))
+ require.Len(t, fakes.operations.landRequests, 1)
// The error keeps what the server answered last.
var retriesErr *sdk.UnavailableRetriesError