@@ -3810,7 +3810,6 @@ func TestPlayerBatchMode(t *testing.T) {
38103810 require .LessOrEqual (t , len (stmt ), maxBatchSize , "expected output statement is longer than the max batch size (%d): %s" , maxBatchSize , stmt )
38113811 }
38123812 expectNontxQueries (t , output , recvTimeout )
3813- time .Sleep (1 * time .Second )
38143813 if tcase .table != "" {
38153814 expectData (t , tcase .table , tcase .data )
38163815 }
@@ -3822,15 +3821,35 @@ func TestPlayerBatchMode(t *testing.T) {
38223821 expectedBulkInserts += tcase .expectedBulkInserts
38233822 expectedTrxBatchCommits ++ // Should only ever be 1 per test case
38243823 expectedTrxBatchExecs += tcase .expectedNonCommitBatches
3825- if tcase .expectedInLastBatch != "" { // We expect the trx to be split
3826- require .Regexpf (t , regexp .MustCompile (fmt .Sprintf (trxLastBatchExpectRE , regexp .QuoteMeta (tcase .expectedInLastBatch ))), lastMultiExecQuery , "Unexpected batch statement: %s" , lastMultiExecQuery )
3824+
3825+ // Poll until the batch query and stats counters are updated.
3826+ // These are set asynchronously on the vplayer goroutine after
3827+ // the commit completes, so we poll rather than using a fixed sleep.
3828+ var batchRE * regexp.Regexp
3829+ if tcase .expectedInLastBatch != "" {
3830+ batchRE = regexp .MustCompile (fmt .Sprintf (trxLastBatchExpectRE , regexp .QuoteMeta (tcase .expectedInLastBatch )))
38273831 } else {
3828- require . Regexpf ( t , regexp .MustCompile (fmt .Sprintf (trxFullBatchExpectRE , regexp .QuoteMeta (strings .Join (tcase .output , ";" )))), lastMultiExecQuery , "Unexpected batch statement: %s" , lastMultiExecQuery )
3832+ batchRE = regexp .MustCompile (fmt .Sprintf (trxFullBatchExpectRE , regexp .QuoteMeta (strings .Join (tcase .output , ";" ))))
38293833 }
3830- require .Equal (t , expectedBulkInserts , stats .BulkQueryCount .Counts ()["insert" ], "expected %d bulk inserts but got %d" , expectedBulkInserts , stats .BulkQueryCount .Counts ()["insert" ])
3831- require .Equal (t , expectedBulkDeletes , stats .BulkQueryCount .Counts ()["delete" ], "expected %d bulk deletes but got %d" , expectedBulkDeletes , stats .BulkQueryCount .Counts ()["delete" ])
3832- require .Equal (t , expectedTrxBatchExecs , stats .TrxQueryBatchCount .Counts ()["without_commit" ], "expected %d trx batch execs but got %d" , expectedTrxBatchExecs , stats .TrxQueryBatchCount .Counts ()["without_commit" ])
3833- require .Equal (t , expectedTrxBatchCommits , stats .TrxQueryBatchCount .Counts ()["with_commit" ], "expected %d trx batch commits but got %d" , expectedTrxBatchCommits , stats .TrxQueryBatchCount .Counts ()["with_commit" ])
3834+ require .Eventually (t , func () bool {
3835+ got := getLastMultiExecQuery ()
3836+ if ! batchRE .MatchString (got ) {
3837+ return false
3838+ }
3839+ if stats .BulkQueryCount .Counts ()["insert" ] != expectedBulkInserts {
3840+ return false
3841+ }
3842+ if stats .BulkQueryCount .Counts ()["delete" ] != expectedBulkDeletes {
3843+ return false
3844+ }
3845+ if stats .TrxQueryBatchCount .Counts ()["without_commit" ] != expectedTrxBatchExecs {
3846+ return false
3847+ }
3848+ if stats .TrxQueryBatchCount .Counts ()["with_commit" ] != expectedTrxBatchCommits {
3849+ return false
3850+ }
3851+ return true
3852+ }, 10 * time .Second , 100 * time .Millisecond , "batch query or stats mismatch after timeout; lastMultiExecQuery: %s" , getLastMultiExecQuery ())
38343853 })
38353854 }
38363855}
0 commit comments