Skip to content

Commit a05d6f1

Browse files
committed
try to fix flaky test case
1 parent c0ebe47 commit a05d6f1

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

  • google-cloud-clients/google-cloud-spanner/src/test/java/com/google/cloud/spanner

google-cloud-clients/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionPoolTest.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,14 @@ public void testSessionNotFoundReadWriteTransaction() {
688688
when(client.createSession(db)).thenReturn(closedSession, openSession);
689689
FakeClock clock = new FakeClock();
690690
clock.currentTimeMillis = System.currentTimeMillis();
691-
pool = createPool(clock);
691+
SessionPoolOptions options =
692+
SessionPoolOptions.newBuilder()
693+
.setMinSessions(0) // The pool should not auto-create any sessions
694+
.setMaxSessions(2)
695+
.setBlockIfPoolExhausted()
696+
.build();
697+
SessionPool pool =
698+
SessionPool.createPool(options, new TestExecutorFactory(), db, client, clock);
692699
TransactionRunner runner = pool.getReadWriteSession().readWriteTransaction();
693700
try {
694701
runner.run(
@@ -700,21 +707,19 @@ public Integer run(TransactionContext transaction) throws Exception {
700707
callNumber++;
701708
if (hasPreparedTransaction) {
702709
// If the session had a prepared read/write transaction, that transaction will
703-
// be
704-
// given to the runner in the first place and the SessionNotFoundException will
705-
// occur on the first query / update statement.
710+
// be given to the runner in the first place and the SessionNotFoundException
711+
// will occur on the first query / update statement.
706712
if (callNumber == 1) {
707713
assertThat(transaction).isEqualTo(closedTransactionContext);
708714
} else {
709715
assertThat(transaction).isEqualTo(openTransactionContext);
710716
}
711717
} else {
712-
// If the session did not have a prepared read/write transaction, a the library
718+
// If the session did not have a prepared read/write transaction, the library
713719
// tried to create a new transaction before handing it to the transaction
714720
// runner.
715721
// The creation of the new transaction failed with a SessionNotFoundException,
716-
// and
717-
// the session was re-created before the run method was called.
722+
// and the session was re-created before the run method was called.
718723
assertThat(transaction).isEqualTo(openTransactionContext);
719724
}
720725
switch (executeStatementType) {

0 commit comments

Comments
 (0)