Skip to content

chore: unflake AsyncTransactionManagerTests #3259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import com.google.common.collect.Range;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.protobuf.AbstractMessage;
import com.google.protobuf.GeneratedMessageV3;
import com.google.spanner.v1.BatchCreateSessionsRequest;
import com.google.spanner.v1.BeginTransactionRequest;
import com.google.spanner.v1.CommitRequest;
Expand Down Expand Up @@ -345,33 +346,22 @@ public void asyncTransactionManagerFireAndForgetInvalidUpdate() throws Exception
}
}
}
ImmutableList<Class<? extends GeneratedMessageV3>> expectedRequests =
ImmutableList.of(
BatchCreateSessionsRequest.class,
// The first update that fails. This will cause a transaction retry.
ExecuteSqlRequest.class,
// The retry will use an explicit BeginTransaction call.
BeginTransactionRequest.class,
// The first update will again fail, but now there is a transaction id, so the
// transaction can continue.
ExecuteSqlRequest.class,
ExecuteSqlRequest.class,
CommitRequest.class);
if (isMultiplexedSessionsEnabled()) {
assertThat(mockSpanner.getRequestTypes())
.containsExactly(
CreateSessionRequest.class,
BatchCreateSessionsRequest.class,
// The first update that fails. This will cause a transaction retry.
ExecuteSqlRequest.class,
// The retry will use an explicit BeginTransaction call.
BeginTransactionRequest.class,
// The first update will again fail, but now there is a transaction id, so the
// transaction can continue.
ExecuteSqlRequest.class,
ExecuteSqlRequest.class,
CommitRequest.class);
assertThat(mockSpanner.getRequestTypes()).containsAtLeastElementsIn(expectedRequests);
} else {
assertThat(mockSpanner.getRequestTypes())
.containsExactly(
BatchCreateSessionsRequest.class,
// The first update that fails. This will cause a transaction retry.
ExecuteSqlRequest.class,
// The retry will use an explicit BeginTransaction call.
BeginTransactionRequest.class,
// The first update will again fail, but now there is a transaction id, so the
// transaction can continue.
ExecuteSqlRequest.class,
ExecuteSqlRequest.class,
CommitRequest.class);
assertThat(mockSpanner.getRequestTypes()).containsExactlyElementsIn(expectedRequests);
}
}

Expand Down Expand Up @@ -681,21 +671,16 @@ public void asyncTransactionManagerFireAndForgetInvalidBatchUpdate() throws Exce
}
}
}
ImmutableList<Class<? extends GeneratedMessageV3>> expectedRequests =
ImmutableList.of(
BatchCreateSessionsRequest.class,
ExecuteBatchDmlRequest.class,
ExecuteBatchDmlRequest.class,
CommitRequest.class);
if (isMultiplexedSessionsEnabled()) {
assertThat(mockSpanner.getRequestTypes())
.containsExactly(
CreateSessionRequest.class,
BatchCreateSessionsRequest.class,
ExecuteBatchDmlRequest.class,
ExecuteBatchDmlRequest.class,
CommitRequest.class);
assertThat(mockSpanner.getRequestTypes()).containsAtLeastElementsIn(expectedRequests);
} else {
assertThat(mockSpanner.getRequestTypes())
.containsExactly(
BatchCreateSessionsRequest.class,
ExecuteBatchDmlRequest.class,
ExecuteBatchDmlRequest.class,
CommitRequest.class);
assertThat(mockSpanner.getRequestTypes()).containsExactlyElementsIn(expectedRequests);
}
}

Expand Down Expand Up @@ -729,23 +714,17 @@ public void asyncTransactionManagerBatchUpdateAborted() throws Exception {
assertThat(attempt.get()).isEqualTo(2);
// There should only be 1 CommitRequest, as the first attempt should abort already after the
// ExecuteBatchDmlRequest.
ImmutableList<Class<? extends GeneratedMessageV3>> expectedRequests =
ImmutableList.of(
BatchCreateSessionsRequest.class,
ExecuteBatchDmlRequest.class,
BeginTransactionRequest.class,
ExecuteBatchDmlRequest.class,
CommitRequest.class);
if (isMultiplexedSessionsEnabled()) {
assertThat(mockSpanner.getRequestTypes())
.containsExactly(
CreateSessionRequest.class,
BatchCreateSessionsRequest.class,
ExecuteBatchDmlRequest.class,
BeginTransactionRequest.class,
ExecuteBatchDmlRequest.class,
CommitRequest.class);
assertThat(mockSpanner.getRequestTypes()).containsAtLeastElementsIn(expectedRequests);
} else {
assertThat(mockSpanner.getRequestTypes())
.containsExactly(
BatchCreateSessionsRequest.class,
ExecuteBatchDmlRequest.class,
BeginTransactionRequest.class,
ExecuteBatchDmlRequest.class,
CommitRequest.class);
assertThat(mockSpanner.getRequestTypes()).containsExactlyElementsIn(expectedRequests);
}
}

Expand Down Expand Up @@ -777,23 +756,17 @@ public void asyncTransactionManagerBatchUpdateAbortedBeforeFirstStatement() thro
assertThat(attempt.get()).isEqualTo(2);
// There should only be 1 CommitRequest, as the first attempt should abort already after the
// ExecuteBatchDmlRequest.
ImmutableList<Class<? extends GeneratedMessageV3>> expectedRequests =
ImmutableList.of(
BatchCreateSessionsRequest.class,
ExecuteBatchDmlRequest.class,
BeginTransactionRequest.class,
ExecuteBatchDmlRequest.class,
CommitRequest.class);
if (isMultiplexedSessionsEnabled()) {
assertThat(mockSpanner.getRequestTypes())
.containsExactly(
CreateSessionRequest.class,
BatchCreateSessionsRequest.class,
ExecuteBatchDmlRequest.class,
BeginTransactionRequest.class,
ExecuteBatchDmlRequest.class,
CommitRequest.class);
assertThat(mockSpanner.getRequestTypes()).containsAtLeastElementsIn(expectedRequests);
} else {
assertThat(mockSpanner.getRequestTypes())
.containsExactly(
BatchCreateSessionsRequest.class,
ExecuteBatchDmlRequest.class,
BeginTransactionRequest.class,
ExecuteBatchDmlRequest.class,
CommitRequest.class);
assertThat(mockSpanner.getRequestTypes()).containsExactlyElementsIn(expectedRequests);
}
}

Expand Down Expand Up @@ -843,25 +816,18 @@ public void asyncTransactionManagerWithBatchUpdateCommitAborted() throws Excepti
} finally {
mockSpanner.putStatementResult(StatementResult.update(UPDATE_STATEMENT, UPDATE_COUNT));
}
ImmutableList<Class<? extends GeneratedMessageV3>> expectedRequests =
ImmutableList.of(
BatchCreateSessionsRequest.class,
ExecuteBatchDmlRequest.class,
CommitRequest.class,
BeginTransactionRequest.class,
ExecuteBatchDmlRequest.class,
CommitRequest.class);
if (isMultiplexedSessionsEnabled()) {
assertThat(mockSpanner.getRequestTypes())
.containsExactly(
CreateSessionRequest.class,
BatchCreateSessionsRequest.class,
ExecuteBatchDmlRequest.class,
CommitRequest.class,
BeginTransactionRequest.class,
ExecuteBatchDmlRequest.class,
CommitRequest.class);
assertThat(mockSpanner.getRequestTypes()).containsAtLeastElementsIn(expectedRequests);
} else {
assertThat(mockSpanner.getRequestTypes())
.containsExactly(
BatchCreateSessionsRequest.class,
ExecuteBatchDmlRequest.class,
CommitRequest.class,
BeginTransactionRequest.class,
ExecuteBatchDmlRequest.class,
CommitRequest.class);
assertThat(mockSpanner.getRequestTypes()).containsExactlyElementsIn(expectedRequests);
}
}

Expand Down Expand Up @@ -925,7 +891,7 @@ public void asyncTransactionManagerBatchUpdateAbortedWithoutGettingResult() thro
}

@Test
public void asyncTransactionManagerWithBatchUpdateCommitFails() throws Exception {
public void asyncTransactionManagerWithBatchUpdateCommitFails() {
mockSpanner.setCommitExecutionTime(
SimulatedExecutionTime.ofException(
Status.INVALID_ARGUMENT
Expand All @@ -948,17 +914,13 @@ public void asyncTransactionManagerWithBatchUpdateCommitFails() throws Exception
assertThat(e.getErrorCode()).isEqualTo(ErrorCode.INVALID_ARGUMENT);
assertThat(e.getMessage()).contains("mutation limit exceeded");
}
ImmutableList<Class<? extends GeneratedMessageV3>> expectedRequests =
ImmutableList.of(
BatchCreateSessionsRequest.class, ExecuteBatchDmlRequest.class, CommitRequest.class);
if (isMultiplexedSessionsEnabled()) {
assertThat(mockSpanner.getRequestTypes())
.containsExactly(
CreateSessionRequest.class,
BatchCreateSessionsRequest.class,
ExecuteBatchDmlRequest.class,
CommitRequest.class);
assertThat(mockSpanner.getRequestTypes()).containsAtLeastElementsIn(expectedRequests);
} else {
assertThat(mockSpanner.getRequestTypes())
.containsExactly(
BatchCreateSessionsRequest.class, ExecuteBatchDmlRequest.class, CommitRequest.class);
assertThat(mockSpanner.getRequestTypes()).containsExactlyElementsIn(expectedRequests);
}
}

Expand All @@ -983,17 +945,13 @@ public void asyncTransactionManagerWaitsUntilAsyncBatchUpdateHasFinished() throw
}
}
}
ImmutableList<Class<? extends GeneratedMessageV3>> expectedRequests =
ImmutableList.of(
BatchCreateSessionsRequest.class, ExecuteBatchDmlRequest.class, CommitRequest.class);
if (isMultiplexedSessionsEnabled()) {
assertThat(mockSpanner.getRequestTypes())
.containsExactly(
CreateSessionRequest.class,
BatchCreateSessionsRequest.class,
ExecuteBatchDmlRequest.class,
CommitRequest.class);
assertThat(mockSpanner.getRequestTypes()).containsAtLeastElementsIn(expectedRequests);
} else {
assertThat(mockSpanner.getRequestTypes())
.containsExactly(
BatchCreateSessionsRequest.class, ExecuteBatchDmlRequest.class, CommitRequest.class);
assertThat(mockSpanner.getRequestTypes()).containsExactlyElementsIn(expectedRequests);
}
}

Expand Down
Loading