Skip to content

Commit 7842dbc

Browse files
committed
test: fix TestTransactionTimeoutSecondStatement by increasing timeout
Problem: The test is flaky in CI because the local transaction_timeout(20ms) is too tight to complete the update operation, leading to a `context deadline exceeded` error or `spanner: code = "DeadlineExceeded"...` error. Solution: By running the test 10,000 times with the -race flag, I found that only setting transaction_timeout to at least 1s passees 10,000 times. I have experimented with 0.06s, 0.2s, and 0.5s. However, all of them (0.06s, 0.2s, and 0.5s) fail before passing 10,000 times. Signed-off-by: Yong-Han Chen <hank96015@gmail.com>
1 parent fc2fdd5 commit 7842dbc

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

transaction_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,14 +323,14 @@ func TestTransactionTimeoutSecondStatement(t *testing.T) {
323323
ctx := context.Background()
324324

325325
tx, _ := db.BeginTx(ctx, &sql.TxOptions{})
326-
if _, err := tx.ExecContext(ctx, "set local transaction_timeout=20ms"); err != nil {
326+
if _, err := tx.ExecContext(ctx, "set local transaction_timeout=1000ms"); err != nil {
327327
t.Fatal(err)
328328
}
329329
if _, err := tx.ExecContext(ctx, testutil.UpdateBarSetFoo); err != nil {
330330
t.Fatal(err)
331331
}
332332

333-
server.TestSpanner.PutExecutionTime(testutil.MethodExecuteStreamingSql, testutil.SimulatedExecutionTime{MinimumExecutionTime: 50 * time.Millisecond})
333+
server.TestSpanner.PutExecutionTime(testutil.MethodExecuteStreamingSql, testutil.SimulatedExecutionTime{MinimumExecutionTime: 1500 * time.Millisecond})
334334
rows, err := tx.QueryContext(ctx, testutil.SelectFooFromBar, ExecOptions{DirectExecuteQuery: true})
335335
if rows != nil {
336336
_ = rows.Close()

0 commit comments

Comments
 (0)