Skip to content

Commit 2312aae

Browse files
test(spanner): deflake multiplexed session mock tests and skip ITInstanceAdminTest in staging/devel (#13020)
1 parent 5fe55cc commit 2312aae

2 files changed

Lines changed: 31 additions & 67 deletions

File tree

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

Lines changed: 13 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public void createSpannerInstance() {
102102
}
103103

104104
@Test
105-
public void testCreateSessionDeadlineExceeded() throws Exception {
105+
public void testCreateSessionDeadlineExceededWithNoSessionCreateWaitTime() throws Exception {
106106
// Simulate a problem with the CreateSession RPC making it slow.
107107
mockSpanner.setCreateSessionExecutionTime(
108108
SimulatedExecutionTime.ofException(Status.DEADLINE_EXCEEDED.asRuntimeException()));
@@ -113,9 +113,11 @@ public void testCreateSessionDeadlineExceeded() throws Exception {
113113
.setProjectId("test-project")
114114
.setChannelProvider(channelProvider)
115115
.setCredentials(NoCredentials.getInstance())
116+
.setSessionPoolOption(SessionPoolOptions.newBuilder().setFailOnSessionLeak().build())
116117
.build()
117118
.getService();
118-
DatabaseClient client = testSpanner.getDatabaseClient(DatabaseId.of("p", "i", "d"));
119+
DatabaseClientImpl client =
120+
(DatabaseClientImpl) testSpanner.getDatabaseClient(DatabaseId.of("p", "i", "d"));
119121

120122
// The first attempt should lead to a DEADLINE_EXCEEDED error being propagated from the
121123
// CreateSession attempt.
@@ -126,13 +128,20 @@ public void testCreateSessionDeadlineExceeded() throws Exception {
126128

127129
// The next attempt should then succeed.
128130
mockSpanner.unfreeze();
129-
DatabaseClientImpl clientImpl = (DatabaseClientImpl) client;
130-
assertNotNull(clientImpl.multiplexedSessionDatabaseClient.getCurrentSessionReference());
131+
assertNotNull(client.multiplexedSessionDatabaseClient.getCurrentSessionReference());
131132

132133
try (ResultSet resultSet = client.singleUse().executeQuery(STATEMENT)) {
133134
//noinspection StatementWithEmptyBody
134135
while (resultSet.next()) {}
135136
}
137+
138+
List<CreateSessionRequest> createSessionRequests =
139+
mockSpanner.getRequestsOfType(CreateSessionRequest.class);
140+
assertEquals(2, createSessionRequests.size());
141+
142+
List<ExecuteSqlRequest> requests = mockSpanner.getRequestsOfType(ExecuteSqlRequest.class);
143+
assertEquals(1, requests.size());
144+
136145
testSpanner.close();
137146
}
138147

@@ -338,68 +347,6 @@ public void testRetryWithTheDatabaseNotFoundExceptionWithSessionCreationWaitTime
338347
testSpanner.close();
339348
}
340349

341-
@Test
342-
public void testRetryWithNoSessionCreationWaitTime() {
343-
mockSpanner.setCreateSessionExecutionTime(
344-
SimulatedExecutionTime.ofExceptions(
345-
Collections.singletonList(
346-
Status.DEADLINE_EXCEEDED
347-
.withDescription(
348-
"CallOptions deadline exceeded after 22.986872393s. "
349-
+ "Name resolution delay 6.911918521 seconds. [closed=[], "
350-
+ "open=[[connecting_and_lb_delay=32445014148ns, was_still_waiting]]]")
351-
.asRuntimeException())));
352-
353-
Spanner testSpanner =
354-
SpannerOptions.newBuilder()
355-
.setProjectId("test-project")
356-
.setChannelProvider(channelProvider)
357-
.setCredentials(NoCredentials.getInstance())
358-
.setSessionPoolOption(
359-
SessionPoolOptions.newBuilder()
360-
.setUseMultiplexedSession(true)
361-
.setUseMultiplexedSessionForRW(true)
362-
.setUseMultiplexedSessionPartitionedOps(true)
363-
.setFailOnSessionLeak()
364-
.build())
365-
.build()
366-
.getService();
367-
368-
DatabaseClientImpl client =
369-
(DatabaseClientImpl) testSpanner.getDatabaseClient(DatabaseId.of("p", "i", "d"));
370-
371-
SpannerException spannerException =
372-
assertThrows(
373-
SpannerException.class,
374-
() -> {
375-
try (ResultSet resultSet = client.singleUse().executeQuery(STATEMENT)) {
376-
//noinspection StatementWithEmptyBody
377-
while (resultSet.next()) {
378-
// ignore
379-
}
380-
}
381-
});
382-
assertEquals(ErrorCode.DEADLINE_EXCEEDED, spannerException.getErrorCode());
383-
384-
// The CreateSession RPC will be retried, and as the exception is removed by the first call,
385-
// the second attempt will succeed.
386-
try (ResultSet resultSet = client.singleUse().executeQuery(STATEMENT)) {
387-
//noinspection StatementWithEmptyBody
388-
while (resultSet.next()) {
389-
// ignore
390-
}
391-
}
392-
393-
List<CreateSessionRequest> createSessionRequests =
394-
mockSpanner.getRequestsOfType(CreateSessionRequest.class);
395-
assertEquals(2, createSessionRequests.size());
396-
397-
List<ExecuteSqlRequest> requests = mockSpanner.getRequestsOfType(ExecuteSqlRequest.class);
398-
assertEquals(1, requests.size());
399-
400-
testSpanner.close();
401-
}
402-
403350
@Test
404351
public void testRetryWithDelayedInResponseExceedsSessionCreationWaitTime() {
405352
mockSpanner.setCreateSessionExecutionTime(

java-spanner/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITInstanceAdminTest.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,18 @@
4848
@RunWith(JUnit4.class)
4949
public class ITInstanceAdminTest {
5050

51-
@ClassRule public static IntegrationTestEnv env = new IntegrationTestEnv(true);
51+
@ClassRule
52+
public static IntegrationTestEnv env =
53+
new IntegrationTestEnv(true) {
54+
@Override
55+
protected void before() throws Throwable {
56+
assumeFalse(
57+
"ITInstanceAdminTest is disabled when running against cloud-devel or cloud-staging",
58+
isRunningOnCloudDevelOrStaging());
59+
super.before();
60+
}
61+
};
62+
5263
static InstanceAdminClient instanceClient;
5364

5465
@BeforeClass
@@ -59,6 +70,12 @@ public static void setUp() {
5970
instanceClient = env.getTestHelper().getClient().getInstanceAdminClient();
6071
}
6172

73+
private static boolean isRunningOnCloudDevelOrStaging() {
74+
String jobType = System.getenv("JOB_TYPE");
75+
return jobType != null
76+
&& (jobType.contains("cloud-devel") || jobType.contains("cloud-staging"));
77+
}
78+
6279
@Test
6380
public void instanceConfigOperations() {
6481
List<InstanceConfig> configs = new ArrayList<>();

0 commit comments

Comments
 (0)