Skip to content

Commit

Permalink
Fix flakiness in TestReadTransactionStatus (#17277)
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <[email protected]>
  • Loading branch information
GuptaManan100 authored Nov 28, 2024
1 parent a1830b3 commit 2f281de
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ go.sum @ajm188 @deepthi @harshit-gangal @mattlord @rohit-nayak-ps @systay @froui
/go/test/endtoend/onlineddl @rohit-nayak-ps @shlomi-noach
/go/test/endtoend/messaging @mattlord @rohit-nayak-ps @derekperkins
/go/test/endtoend/schemadiff @shlomi-noach @mattlord
/go/test/endtoend/transaction @harshit-gangal @systay @frouioui @GuptaManan100
/go/test/endtoend/*throttler* @shlomi-noach @mattlord @timvaillancourt
/go/test/endtoend/vtgate @harshit-gangal @systay @frouioui
/go/test/endtoend/vtorc @deepthi @shlomi-noach @GuptaManan100 @timvaillancourt
Expand Down
24 changes: 17 additions & 7 deletions go/test/endtoend/transaction/twopc/twopc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1395,8 +1395,6 @@ func TestReadTransactionStatus(t *testing.T) {
"insert into twopc_t1(id, col) values(6, 4)",
"insert into twopc_t1(id, col) values(9, 4)",
})
// Allow enough time for the commit to have started.
time.Sleep(1 * time.Second)

// Create a tablet manager client and use it to read the transaction state.
tmc := grpctmclient.NewClient()
Expand All @@ -1405,12 +1403,24 @@ func TestReadTransactionStatus(t *testing.T) {
defer cancel()

primaryTablet := getTablet(clusterInstance.Keyspaces[0].Shards[2].FindPrimaryTablet().GrpcPort)
// Wait for the transaction to show up in the unresolved list.
var unresTransaction *querypb.TransactionMetadata
for _, shard := range clusterInstance.Keyspaces[0].Shards {
urtRes, err := tmc.GetUnresolvedTransactions(ctx, getTablet(shard.FindPrimaryTablet().GrpcPort), 1)
require.NoError(t, err)
if len(urtRes) > 0 {
unresTransaction = urtRes[0]
timeout := time.After(10 * time.Second)
for {
for _, shard := range clusterInstance.Keyspaces[0].Shards {
urtRes, err := tmc.GetUnresolvedTransactions(ctx, getTablet(shard.FindPrimaryTablet().GrpcPort), 1)
require.NoError(t, err)
if len(urtRes) > 0 {
unresTransaction = urtRes[0]
}
}
if unresTransaction != nil {
break
}
select {
case <-timeout:
require.Fail(t, "timed out waiting for unresolved transaction")
default:
}
}
require.NotNil(t, unresTransaction)
Expand Down

0 comments on commit 2f281de

Please sign in to comment.