Skip to content

Commit

Permalink
chore(spanner): fix tests in SessionPoolLeakTest
Browse files Browse the repository at this point in the history
  • Loading branch information
harshachinta committed Dec 19, 2024
1 parent b8de686 commit fed3041
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public void onSessionReady(SessionImpl session) {
.getOptions()
.getSessionPoolOptions()
.getSkipVerifyBeginTransactionForMuxRW()) {

verifyBeginTransactionWithRWOnMultiplexedSessionAsync(session.getName());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ public void testIgnoreLeakedSession() {

@Test
public void testReadWriteTransactionExceptionOnCreateSession() {
assumeFalse(
"Session Leaks do not occur with Multiplexed Sessions",
isMultiplexedSessionsEnabledForRW());
readWriteTransactionTest(
() ->
mockSpanner.setBatchCreateSessionsExecutionTime(
Expand All @@ -180,6 +183,9 @@ public void testReadWriteTransactionExceptionOnCreateSession() {

@Test
public void testReadWriteTransactionExceptionOnBegin() {
assumeFalse(
"Session Leaks do not occur with Multiplexed Sessions",
isMultiplexedSessionsEnabledForRW());
readWriteTransactionTest(
() ->
mockSpanner.setBeginTransactionExecutionTime(
Expand All @@ -200,6 +206,9 @@ private void readWriteTransactionTest(

@Test
public void testTransactionManagerExceptionOnCreateSession() {
assumeFalse(
"Session Leaks do not occur with Multiplexed Sessions",
isMultiplexedSessionsEnabledForRW());
transactionManagerTest(
() ->
mockSpanner.setBatchCreateSessionsExecutionTime(
Expand All @@ -209,6 +218,9 @@ public void testTransactionManagerExceptionOnCreateSession() {

@Test
public void testTransactionManagerExceptionOnBegin() {
assumeFalse(
"Session Leaks do not occur with Multiplexed Sessions",
isMultiplexedSessionsEnabledForRW());
assertThat(pool.getNumberOfSessionsInPool(), is(equalTo(0)));
mockSpanner.setBeginTransactionExecutionTime(
SimulatedExecutionTime.ofException(FAILED_PRECONDITION));
Expand All @@ -229,4 +241,11 @@ private void transactionManagerTest(Runnable setup, int expectedNumberOfSessions
}
assertEquals(expectedNumberOfSessionsAfterExecution, pool.getNumberOfSessionsInPool());
}

private boolean isMultiplexedSessionsEnabledForRW() {
if (spanner.getOptions() == null || spanner.getOptions().getSessionPoolOptions() == null) {
return false;
}
return spanner.getOptions().getSessionPoolOptions().getUseMultiplexedSessionForRW();
}
}

0 comments on commit fed3041

Please sign in to comment.