Skip to content

Commit 18d4dd9

Browse files
authored
chore: flaky test (#2890)
1 parent 62319f0 commit 18d4dd9

File tree

4 files changed

+76
-96
lines changed

4 files changed

+76
-96
lines changed

google-cloud-spanner/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<properties>
1717
<site.installationModule>google-cloud-spanner</site.installationModule>
1818
<opencensus.version>0.31.1</opencensus.version>
19+
<opentelemetry.version>1.34.1</opentelemetry.version>
1920
<spanner.testenv.config.class>com.google.cloud.spanner.GceTestEnvConfig</spanner.testenv.config.class>
2021
<spanner.testenv.instance>projects/gcloud-devel/instances/spanner-testing-east1</spanner.testenv.instance>
2122
<spanner.gce.config.project_id>gcloud-devel</spanner.gce.config.project_id>
@@ -418,21 +419,25 @@
418419
<dependency>
419420
<groupId>io.opentelemetry</groupId>
420421
<artifactId>opentelemetry-sdk</artifactId>
422+
<version>${opentelemetry.version}</version>
421423
<scope>test</scope>
422424
</dependency>
423425
<dependency>
424426
<groupId>io.opentelemetry</groupId>
425427
<artifactId>opentelemetry-sdk-metrics</artifactId>
428+
<version>${opentelemetry.version}</version>
426429
<scope>test</scope>
427430
</dependency>
428431
<dependency>
429432
<groupId>io.opentelemetry</groupId>
430433
<artifactId>opentelemetry-sdk-trace</artifactId>
434+
<version>${opentelemetry.version}</version>
431435
<scope>test</scope>
432436
</dependency>
433437
<dependency>
434438
<groupId>io.opentelemetry</groupId>
435439
<artifactId>opentelemetry-sdk-testing</artifactId>
440+
<version>${opentelemetry.version}</version>
436441
<scope>test</scope>
437442
</dependency>
438443
</dependencies>

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

Lines changed: 26 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import org.junit.experimental.categories.Category;
5555
import org.junit.runner.RunWith;
5656
import org.junit.runners.JUnit4;
57+
import org.threeten.bp.Duration;
5758

5859
@Category(TracerTest.class)
5960
@RunWith(JUnit4.class)
@@ -103,11 +104,11 @@ public class OpenTelemetrySpanTest {
103104
Statement.of("UPDATE NON_EXISTENT_TABLE SET BAR=1 WHERE BAZ=2");
104105

105106
private List<String> expectedBatchCreateSessionsRequestEvents =
106-
ImmutableList.of("Requesting 25 sessions", "Request for 25 sessions returned 25 sessions");
107+
ImmutableList.of("Requesting 2 sessions", "Request for 2 sessions returned 2 sessions");
107108

108109
private int expectedBatchCreateSessionsRequestEventsCount = 2;
109110

110-
private List<String> expectedBatchCreateSessionsEvents = ImmutableList.of("Creating 25 sessions");
111+
private List<String> expectedBatchCreateSessionsEvents = ImmutableList.of("Creating 2 sessions");
111112

112113
private int expectedBatchCreateSessionsEventsCount = 1;
113114

@@ -117,58 +118,45 @@ public class OpenTelemetrySpanTest {
117118
private int expectedExecuteStreamingQueryEventsCount = 1;
118119

119120
private List<String> expectedReadOnlyTransactionSingleUseEvents =
120-
ImmutableList.of(
121-
"Acquiring session",
122-
"No session available",
123-
"Creating sessions",
124-
"Waiting for a session to come available",
125-
"Using Session");
121+
ImmutableList.of("Acquiring session", "Acquired session", "Using Session");
126122

127-
private int expectedReadOnlyTransactionSingleUseEventsCount = 5;
123+
private int expectedReadOnlyTransactionSingleUseEventsCount = 3;
128124

129125
private List<String> expectedReadOnlyTransactionMultiUseEvents =
130126
ImmutableList.of(
131127
"Acquiring session",
132-
"No session available",
133-
"Creating sessions",
134-
"Waiting for a session to come available",
128+
"Acquired session",
135129
"Using Session",
136130
"Creating Transaction",
137131
"Transaction Creation Done");
138132

139-
private int expectedReadOnlyTransactionMultiUseEventsCount = 7;
133+
private int expectedReadOnlyTransactionMultiUseEventsCount = 5;
140134

141135
private List<String> expectedReadWriteTransactionErrorEvents =
142136
ImmutableList.of(
143137
"Acquiring session",
144-
"No session available",
145-
"Creating sessions",
146-
"Waiting for a session to come available",
138+
"Acquired session",
147139
"Using Session",
148140
"Starting Transaction Attempt",
149141
"Transaction Attempt Failed in user operation",
150142
"exception");
151143

152-
private int expectedReadWriteTransactionErrorEventsCount = 8;
144+
private int expectedReadWriteTransactionErrorEventsCount = 6;
153145
private List<String> expectedReadWriteTransactionEvents =
154146
ImmutableList.of(
155147
"Acquiring session",
156-
"No session available",
157-
"Creating sessions",
158-
"Waiting for a session to come available",
148+
"Acquired session",
159149
"Using Session",
160150
"Starting Transaction Attempt",
161151
"Starting Commit",
162152
"Commit Done",
163153
"Transaction Attempt Succeeded");
164154

165-
private int expectedReadWriteTransactionCount = 9;
155+
private int expectedReadWriteTransactionCount = 7;
166156
private List<String> expectedReadWriteTransactionErrorWithBeginTransactionEvents =
167157
ImmutableList.of(
168158
"Acquiring session",
169-
"No session available",
170-
"Creating sessions",
171-
"Waiting for a session to come available",
159+
"Acquired session",
172160
"Using Session",
173161
"Starting Transaction Attempt",
174162
"Transaction Attempt Aborted in user operation. Retrying",
@@ -178,38 +166,34 @@ public class OpenTelemetrySpanTest {
178166
"Commit Done",
179167
"Transaction Attempt Succeeded");
180168

181-
private int expectedReadWriteTransactionErrorWithBeginTransactionEventsCount = 13;
169+
private int expectedReadWriteTransactionErrorWithBeginTransactionEventsCount = 11;
182170
private List<String> expectedReadOnlyTransactionSpans =
183171
ImmutableList.of(
184172
"CloudSpannerOperation.BatchCreateSessionsRequest",
185173
"CloudSpannerOperation.ExecuteStreamingQuery",
186174
"CloudSpannerOperation.BatchCreateSessions",
187-
"CloudSpanner.ReadOnlyTransaction",
188-
"SessionPool.WaitForSession");
175+
"CloudSpanner.ReadOnlyTransaction");
189176

190177
private List<String> expectedReadWriteTransactionWithCommitSpans =
191178
ImmutableList.of(
192179
"CloudSpannerOperation.BatchCreateSessionsRequest",
193180
"CloudSpannerOperation.Commit",
194181
"CloudSpannerOperation.BatchCreateSessions",
195-
"CloudSpanner.ReadWriteTransaction",
196-
"SessionPool.WaitForSession");
182+
"CloudSpanner.ReadWriteTransaction");
197183

198184
private List<String> expectedReadWriteTransactionSpans =
199185
ImmutableList.of(
200186
"CloudSpannerOperation.BatchCreateSessionsRequest",
201187
"CloudSpannerOperation.BatchCreateSessions",
202-
"CloudSpanner.ReadWriteTransaction",
203-
"SessionPool.WaitForSession");
188+
"CloudSpanner.ReadWriteTransaction");
204189

205190
private List<String> expectedReadWriteTransactionWithCommitAndBeginTransactionSpans =
206191
ImmutableList.of(
207192
"CloudSpannerOperation.BeginTransaction",
208193
"CloudSpannerOperation.BatchCreateSessionsRequest",
209194
"CloudSpannerOperation.Commit",
210195
"CloudSpannerOperation.BatchCreateSessions",
211-
"CloudSpanner.ReadWriteTransaction",
212-
"SessionPool.WaitForSession");
196+
"CloudSpanner.ReadWriteTransaction");
213197

214198
@BeforeClass
215199
public static void setupOpenTelemetry() {
@@ -282,7 +266,11 @@ public void setUp() throws Exception {
282266
.setChannelProvider(channelProvider)
283267
.setOpenTelemetry(openTelemetry)
284268
.setCredentials(NoCredentials.getInstance())
285-
.setSessionPoolOption(SessionPoolOptions.newBuilder().setMinSessions(0).build());
269+
.setSessionPoolOption(
270+
SessionPoolOptions.newBuilder()
271+
.setMinSessions(2)
272+
.setWaitForMinSessions(Duration.ofSeconds(5))
273+
.build());
286274

287275
spanner = builder.build().getService();
288276

@@ -339,9 +327,6 @@ public void singleUse() {
339327
expectedReadOnlyTransactionSingleUseEvents,
340328
expectedReadOnlyTransactionSingleUseEventsCount);
341329
break;
342-
case "SessionPool.WaitForSession":
343-
assertEquals(0, spanItem.getEvents().size());
344-
break;
345330
default:
346331
assert false;
347332
}
@@ -385,9 +370,6 @@ public void multiUse() {
385370
expectedExecuteStreamingQueryEvents,
386371
expectedExecuteStreamingQueryEventsCount);
387372
break;
388-
case "SessionPool.WaitForSession":
389-
assertEquals(0, spanItem.getEvents().size());
390-
break;
391373
case "CloudSpanner.ReadOnlyTransaction":
392374
verifyRequestEvents(
393375
spanItem,
@@ -406,7 +388,6 @@ public void multiUse() {
406388
public void transactionRunner() {
407389
TransactionRunner runner = client.readWriteTransaction();
408390
runner.run(transaction -> transaction.executeUpdate(UPDATE_STATEMENT));
409-
410391
List<String> actualSpanItems = new ArrayList<>();
411392
spanExporter
412393
.getFinishedSpanItems()
@@ -426,7 +407,6 @@ public void transactionRunner() {
426407
expectedBatchCreateSessionsEvents,
427408
expectedBatchCreateSessionsEventsCount);
428409
break;
429-
case "SessionPool.WaitForSession":
430410
case "CloudSpannerOperation.Commit":
431411
assertEquals(0, spanItem.getEvents().size());
432412
break;
@@ -472,9 +452,6 @@ public void transactionRunnerWithError() {
472452
expectedBatchCreateSessionsEvents,
473453
expectedBatchCreateSessionsEventsCount);
474454
break;
475-
case "SessionPool.WaitForSession":
476-
assertEquals(0, spanItem.getEvents().size());
477-
break;
478455
case "CloudSpanner.ReadWriteTransaction":
479456
verifyRequestEvents(
480457
spanItem,
@@ -527,7 +504,6 @@ public void transactionRunnerWithFailedAndBeginTransaction() {
527504
expectedBatchCreateSessionsEvents,
528505
expectedBatchCreateSessionsEventsCount);
529506
break;
530-
case "SessionPool.WaitForSession":
531507
case "CloudSpannerOperation.Commit":
532508
case "CloudSpannerOperation.BeginTransaction":
533509
assertEquals(0, spanItem.getEvents().size());
@@ -551,13 +527,13 @@ private void verifyRequestEvents(SpanData spanItem, List<String> expectedEvents,
551527
spanItem.getEvents().stream().map(EventData::getName).collect(Collectors.toList());
552528
assertEquals(eventCount, spanItem.getEvents().size());
553529
assertEquals(
554-
eventNames.stream().distinct().sorted().collect(Collectors.toList()),
555-
expectedEvents.stream().sorted().collect(Collectors.toList()));
530+
expectedEvents.stream().sorted().collect(Collectors.toList()),
531+
eventNames.stream().distinct().sorted().collect(Collectors.toList()));
556532
}
557533

558534
private static void verifySpans(List<String> actualSpanItems, List<String> expectedSpansItems) {
559535
assertEquals(
560-
actualSpanItems.stream().distinct().sorted().collect(Collectors.toList()),
561-
expectedSpansItems.stream().sorted().collect(Collectors.toList()));
536+
expectedSpansItems.stream().sorted().collect(Collectors.toList()),
537+
actualSpanItems.stream().distinct().sorted().collect(Collectors.toList()));
562538
}
563539
}

0 commit comments

Comments
 (0)