Skip to content

Commit 80b3228

Browse files
test: reduce flakiness of RegisterRelationshipCountersInParallelTest (#2820)
Co-authored-by: Maria Ines Parnisari <maria.ines.parnisari@authzed.com>
1 parent b7f9dd7 commit 80b3228

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

internal/datastore/memdb/memdb.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
const (
2525
Engine = "memory"
2626
defaultWatchBufferLength = 128
27-
numAttempts = 10
27+
maxRetries = 10
2828
)
2929

3030
var (
@@ -159,7 +159,7 @@ func (mdb *memdbDatastore) ReadWriteTx(
159159
opts ...options.RWTOptionsOption,
160160
) (datastore.Revision, error) {
161161
config := options.NewRWTOptionsWithOptions(opts...)
162-
txNumAttempts := numAttempts
162+
txNumAttempts := maxRetries // TODO every other datastore has a configurable MaxRetries. why not this one?
163163
if config.DisableRetries {
164164
txNumAttempts = 1
165165
}

pkg/datastore/test/counters.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,15 @@ func RegisterRelationshipCountersInParallelTest(t *testing.T, tester DatastoreTe
7777
// Run multiple registrations of the counter in parallel and ensure only
7878
// one succeeds.
7979
var numSucceeded, numFailed atomic.Int32
80-
failures := make(chan error, 10)
80+
81+
// we retry (memdb.MaxRetries - 1)
82+
// ideally, we don't have to hardcode this number here and we can do
83+
// numRetries = ds.MaxRetriesConfigured()
84+
const numRetries = 9
85+
86+
failures := make(chan error, numRetries)
8187
var wg sync.WaitGroup
82-
for range 10 {
88+
for range numRetries {
8389
wg.Go(func() {
8490
_, err := ds.ReadWriteTx(t.Context(), func(ctx context.Context, tx datastore.ReadWriteTransaction) error {
8591
return tx.RegisterCounter(ctx, "document", &core.RelationshipFilter{
@@ -99,7 +105,7 @@ func RegisterRelationshipCountersInParallelTest(t *testing.T, tester DatastoreTe
99105
wg.Wait()
100106
close(failures)
101107
require.Equal(t, int32(1), numSucceeded.Load())
102-
require.Equal(t, int32(9), numFailed.Load())
108+
require.Equal(t, int32(numRetries-1), numFailed.Load())
103109
for m := range failures {
104110
require.Contains(t, m.Error(), "counter with name `document` already registered")
105111
}

0 commit comments

Comments
 (0)