Skip to content

Commit

Permalink
test(spanner): fix flaky TestReadWriteTransaction_ContextTimeoutDurin…
Browse files Browse the repository at this point in the history
…gDuringCommit (#3915)

Co-authored-by: Hengfeng Li <hengfeng@google.com>
  • Loading branch information
yfuruyama and hengfengli committed Apr 15, 2021
1 parent 1f0787c commit d864346
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions spanner/client_test.go
Expand Up @@ -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,
Expand Down

0 comments on commit d864346

Please sign in to comment.