Skip to content

Commit 794cbd8

Browse files
committed
test: fix flaky tests
Fixes #3050 Fixes #3081 Fixes #3080
1 parent d18b834 commit 794cbd8

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

google-cloud-spanner/src/test/java/com/google/cloud/spanner/AsyncRunnerTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,11 @@ public void asyncRunnerWaitsUntilAsyncUpdateHasFinished() throws Exception {
261261
executor);
262262
res.get();
263263
if (isMultiplexedSessionsEnabled()) {
264+
// The mock server could have received a CreateSession request for a multiplexed session, but
265+
// it could also be that that request has not yet reached the server.
264266
assertThat(mockSpanner.getRequestTypes())
265-
.containsExactly(
266-
CreateSessionRequest.class,
267-
BatchCreateSessionsRequest.class,
268-
ExecuteSqlRequest.class,
269-
CommitRequest.class);
267+
.containsAtLeast(
268+
BatchCreateSessionsRequest.class, ExecuteSqlRequest.class, CommitRequest.class);
270269
} else {
271270
assertThat(mockSpanner.getRequestTypes())
272271
.containsExactly(

google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenTelemetrySpanTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public void setUp() throws Exception {
231231
.setSessionPoolOption(
232232
SessionPoolOptions.newBuilder()
233233
.setMinSessions(2)
234-
.setWaitForMinSessions(Duration.ofSeconds(5))
234+
.setWaitForMinSessions(Duration.ofSeconds(10))
235235
.build());
236236

237237
spanner = builder.build().getService();

google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/ConnectionTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,10 @@ public void testMaxSessions()
290290
assertThat(count1.isDone()).isTrue();
291291
assertThat(count2.isDone()).isTrue();
292292
if (isMultiplexedSessionsEnabled(connection1.getSpanner())) {
293-
assertThat(mockSpanner.numSessionsCreated()).isEqualTo(2);
293+
// We don't use the multiplexed session, so we don't know whether the server had time to
294+
// create it or not. That means that we have between 1 and 2 sessions on the server.
295+
assertThat(mockSpanner.numSessionsCreated()).isAtLeast(1);
296+
assertThat(mockSpanner.numSessionsCreated()).isAtMost(2);
294297
} else {
295298
assertThat(mockSpanner.numSessionsCreated()).isEqualTo(1);
296299
}

0 commit comments

Comments
 (0)