From d864346067f8bff9dd7c9b094628548f648cbee5 Mon Sep 17 00:00:00 2001 From: Yuki Furuyama Date: Thu, 15 Apr 2021 14:24:57 +0900 Subject: [PATCH] test(spanner): fix flaky TestReadWriteTransaction_ContextTimeoutDuringDuringCommit (#3915) Co-authored-by: Hengfeng Li --- spanner/client_test.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/spanner/client_test.go b/spanner/client_test.go index 6493cf3cc52..309b51d18e6 100644 --- a/spanner/client_test.go +++ b/spanner/client_test.go @@ -1749,10 +1749,28 @@ func TestClient_WriteStructWithCustomTypes(t *testing.T) { } } -func TestReadWriteTransaction_ContextTimeoutDuringDuringCommit(t *testing.T) { +func TestReadWriteTransaction_ContextTimeoutDuringCommit(t *testing.T) { t.Parallel() - server, client, teardown := setupMockedTestServer(t) + server, client, teardown := setupMockedTestServerWithConfig(t, ClientConfig{ + SessionPoolConfig: SessionPoolConfig{ + MinOpened: 1, + WriteSessions: 0, + }, + }) defer teardown() + + // Wait until session creation has seized so that + // context timeout won't happen while a session is being created. + waitFor(t, func() error { + sp := client.idleSessions + sp.mu.Lock() + defer sp.mu.Unlock() + if sp.createReqs != 0 { + return fmt.Errorf("%d sessions are still in creation", sp.createReqs) + } + return nil + }) + server.TestSpanner.PutExecutionTime(MethodCommitTransaction, SimulatedExecutionTime{ MinimumExecutionTime: time.Minute,