Skip to content

Commit 72dc163

Browse files
authored
test(datastore): Take current read time and add retries to fix AggregationQueries (#13558)
Fixes flaky datastore integration test by using dynamic ReadTime in retries. Fixes: #11491 After fix: ```go $ go test -count=25 -timeout 45m -run ^TestIntegration_AggregationQueries$ 2026/01/08 16:15:44 Setting up tests to run on databaseID: "" PASS ok cloud.google.com/go/datastore 44.841s $ ```
1 parent 4907315 commit 72dc163

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

datastore/integration_test.go

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,13 +1349,14 @@ func TestIntegration_AggregationQueries(t *testing.T) {
13491349
}()
13501350

13511351
testCases := []struct {
1352-
desc string
1353-
aggQuery *AggregationQuery
1354-
transactionOpts []TransactionOption
1355-
clientReadOptions []ReadOption
1356-
wantFailure bool
1357-
wantErrMsg string
1358-
wantAggResult AggregationResult
1352+
desc string
1353+
aggQuery *AggregationQuery
1354+
transactionOpts []TransactionOption
1355+
clientReadOptions []ReadOption
1356+
useCurrentReadTime bool
1357+
wantFailure bool
1358+
wantErrMsg string
1359+
wantAggResult AggregationResult
13591360
}{
13601361

13611362
{
@@ -1390,7 +1391,7 @@ func TestIntegration_AggregationQueries(t *testing.T) {
13901391
aggQuery: NewQuery("SQChild").Ancestor(parent).Filter("T=", now).Filter("I>=", 3).
13911392
NewAggregationQuery().
13921393
WithCount("count"),
1393-
clientReadOptions: []ReadOption{ReadTime(time.Now().Truncate(time.Millisecond))},
1394+
useCurrentReadTime: true,
13941395
wantAggResult: map[string]interface{}{
13951396
"count": &pb.Value{ValueType: &pb.Value_IntegerValue{IntegerValue: 5}},
13961397
},
@@ -1467,15 +1468,21 @@ func TestIntegration_AggregationQueries(t *testing.T) {
14671468
}
14681469

14691470
for _, testCase := range testCases {
1470-
testClient := client
1471-
if testCase.clientReadOptions != nil {
1472-
clientWithReadTime := newTestClient(ctx, t)
1473-
clientWithReadTime.WithReadOptions(testCase.clientReadOptions...)
1474-
defer clientWithReadTime.Close()
1475-
1476-
testClient = clientWithReadTime
1477-
}
14781471
testutil.Retry(t, 10, time.Second, func(r *testutil.R) {
1472+
testClient := client
1473+
clientReadOptions := testCase.clientReadOptions
1474+
if testCase.useCurrentReadTime {
1475+
clientReadOptions = append(clientReadOptions, ReadTime(time.Now().Truncate(time.Millisecond)))
1476+
}
1477+
1478+
if len(clientReadOptions) > 0 {
1479+
clientWithReadTime := newTestClient(ctx, t)
1480+
clientWithReadTime.WithReadOptions(clientReadOptions...)
1481+
defer clientWithReadTime.Close()
1482+
1483+
testClient = clientWithReadTime
1484+
}
1485+
14791486
gotAggResult, gotErr := testClient.RunAggregationQuery(ctx, testCase.aggQuery)
14801487
gotFailure := gotErr != nil
14811488

0 commit comments

Comments
 (0)