diff --git a/acceleration/internal/store/budget_test.go b/acceleration/internal/store/budget_test.go index a2989f1bc1..19d93a64b0 100644 --- a/acceleration/internal/store/budget_test.go +++ b/acceleration/internal/store/budget_test.go @@ -57,6 +57,18 @@ func (s *StoreSuite) countQueries(run func()) int { return int(s.queries.sent.Load() - before) } +// countSettledReads is countQueries for a read one shard's answer settles (answeringShards). +// The reads that answer cut off are not waited for and finish after run returns, so it waits, +// up to a deadline, until every shard's statement is in before it counts. +func (s *StoreSuite) countSettledReads(run func()) int { + before := s.queries.sent.Load() + run() + shards := int64(len(s.store.shards())) + s.Eventually(func() bool { return s.queries.sent.Load()-before >= shards }, 5*time.Second, time.Millisecond, + "a statement from every shard") + return int(s.queries.sent.Load() - before) +} + // countEveryQuery hooks the suite's counter into every database the store holds. func (s *StoreSuite) countEveryQuery() { databases := append([]*bun.DB{s.store.global}, s.store.peers...) diff --git a/acceleration/internal/store/call_bridge_test.go b/acceleration/internal/store/call_bridge_test.go index fa786725a3..c7bac8b3fd 100644 --- a/acceleration/internal/store/call_bridge_test.go +++ b/acceleration/internal/store/call_bridge_test.go @@ -12,7 +12,7 @@ func (s *StoreSuite) TestABridgeIsClaimedOnceFromAnyShardAndSweptOnceExpired() { var claimed CallBridge var err error - s.Equal(len(s.store.shards()), s.countQueries(func() { + s.Equal(len(s.store.shards()), s.countSettledReads(func() { claimed, err = s.store.CallBridges.Claim(s.ctx, waiting.Token) }), "Claim asks every shard once") s.Require().NoError(err) diff --git a/acceleration/internal/store/call_resource_test.go b/acceleration/internal/store/call_resource_test.go index 2be9291cec..73d8b83b86 100644 --- a/acceleration/internal/store/call_resource_test.go +++ b/acceleration/internal/store/call_resource_test.go @@ -94,7 +94,7 @@ func (s *StoreSuite) TestCallResourceQueryBudgets() { first = resource } } - s.Equal(shards, s.countQueries(func() { + s.Equal(shards, s.countSettledReads(func() { resources, err := s.store.CallResources.Select(s.ctx, AppScope{Unpinned: true}, "default", "call-1") s.Require().NoError(err) s.Len(resources, 3)