Skip to content
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

chore: flaky test #2890

Merged
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions google-cloud-spanner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<properties>
<site.installationModule>google-cloud-spanner</site.installationModule>
<opencensus.version>0.31.1</opencensus.version>
<opentelemetry.version>1.34.1</opentelemetry.version>
<spanner.testenv.config.class>com.google.cloud.spanner.GceTestEnvConfig</spanner.testenv.config.class>
<spanner.testenv.instance>projects/gcloud-devel/instances/spanner-testing-east1</spanner.testenv.instance>
<spanner.gce.config.project_id>gcloud-devel</spanner.gce.config.project_id>
Expand Down Expand Up @@ -418,21 +419,25 @@
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk</artifactId>
<version>${opentelemetry.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk-metrics</artifactId>
<version>${opentelemetry.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk-trace</artifactId>
<version>${opentelemetry.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk-testing</artifactId>
<version>${opentelemetry.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.threeten.bp.Duration;

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

private List<String> expectedBatchCreateSessionsRequestEvents =
ImmutableList.of("Requesting 25 sessions", "Request for 25 sessions returned 25 sessions");
ImmutableList.of("Requesting 2 sessions", "Request for 2 sessions returned 2 sessions");

private int expectedBatchCreateSessionsRequestEventsCount = 2;

private List<String> expectedBatchCreateSessionsEvents = ImmutableList.of("Creating 25 sessions");
private List<String> expectedBatchCreateSessionsEvents = ImmutableList.of("Creating 2 sessions");

private int expectedBatchCreateSessionsEventsCount = 1;

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

private List<String> expectedReadOnlyTransactionSingleUseEvents =
ImmutableList.of(
"Acquiring session",
"No session available",
"Creating sessions",
"Waiting for a session to come available",
"Using Session");
ImmutableList.of("Acquiring session", "Acquired session", "Using Session");

private int expectedReadOnlyTransactionSingleUseEventsCount = 5;
private int expectedReadOnlyTransactionSingleUseEventsCount = 3;

private List<String> expectedReadOnlyTransactionMultiUseEvents =
ImmutableList.of(
"Acquiring session",
"No session available",
"Creating sessions",
"Waiting for a session to come available",
"Acquired session",
"Using Session",
"Creating Transaction",
"Transaction Creation Done");

private int expectedReadOnlyTransactionMultiUseEventsCount = 7;
private int expectedReadOnlyTransactionMultiUseEventsCount = 5;

private List<String> expectedReadWriteTransactionErrorEvents =
ImmutableList.of(
"Acquiring session",
"No session available",
"Creating sessions",
"Waiting for a session to come available",
"Acquired session",
"Using Session",
"Starting Transaction Attempt",
"Transaction Attempt Failed in user operation",
"exception");

private int expectedReadWriteTransactionErrorEventsCount = 8;
private int expectedReadWriteTransactionErrorEventsCount = 6;
private List<String> expectedReadWriteTransactionEvents =
ImmutableList.of(
"Acquiring session",
"No session available",
"Creating sessions",
"Waiting for a session to come available",
"Acquired session",
"Using Session",
"Starting Transaction Attempt",
"Starting Commit",
"Commit Done",
"Transaction Attempt Succeeded");

private int expectedReadWriteTransactionCount = 9;
private int expectedReadWriteTransactionCount = 7;
private List<String> expectedReadWriteTransactionErrorWithBeginTransactionEvents =
ImmutableList.of(
"Acquiring session",
"No session available",
"Creating sessions",
"Waiting for a session to come available",
"Acquired session",
"Using Session",
"Starting Transaction Attempt",
"Transaction Attempt Aborted in user operation. Retrying",
Expand All @@ -178,38 +166,34 @@ public class OpenTelemetrySpanTest {
"Commit Done",
"Transaction Attempt Succeeded");

private int expectedReadWriteTransactionErrorWithBeginTransactionEventsCount = 13;
private int expectedReadWriteTransactionErrorWithBeginTransactionEventsCount = 11;
private List<String> expectedReadOnlyTransactionSpans =
ImmutableList.of(
"CloudSpannerOperation.BatchCreateSessionsRequest",
"CloudSpannerOperation.ExecuteStreamingQuery",
"CloudSpannerOperation.BatchCreateSessions",
"CloudSpanner.ReadOnlyTransaction",
"SessionPool.WaitForSession");
"CloudSpanner.ReadOnlyTransaction");

private List<String> expectedReadWriteTransactionWithCommitSpans =
ImmutableList.of(
"CloudSpannerOperation.BatchCreateSessionsRequest",
"CloudSpannerOperation.Commit",
"CloudSpannerOperation.BatchCreateSessions",
"CloudSpanner.ReadWriteTransaction",
"SessionPool.WaitForSession");
"CloudSpanner.ReadWriteTransaction");

private List<String> expectedReadWriteTransactionSpans =
ImmutableList.of(
"CloudSpannerOperation.BatchCreateSessionsRequest",
"CloudSpannerOperation.BatchCreateSessions",
"CloudSpanner.ReadWriteTransaction",
"SessionPool.WaitForSession");
"CloudSpanner.ReadWriteTransaction");

private List<String> expectedReadWriteTransactionWithCommitAndBeginTransactionSpans =
ImmutableList.of(
"CloudSpannerOperation.BeginTransaction",
"CloudSpannerOperation.BatchCreateSessionsRequest",
"CloudSpannerOperation.Commit",
"CloudSpannerOperation.BatchCreateSessions",
"CloudSpanner.ReadWriteTransaction",
"SessionPool.WaitForSession");
"CloudSpanner.ReadWriteTransaction");

@BeforeClass
public static void setupOpenTelemetry() {
Expand Down Expand Up @@ -282,7 +266,11 @@ public void setUp() throws Exception {
.setChannelProvider(channelProvider)
.setOpenTelemetry(openTelemetry)
.setCredentials(NoCredentials.getInstance())
.setSessionPoolOption(SessionPoolOptions.newBuilder().setMinSessions(0).build());
.setSessionPoolOption(
SessionPoolOptions.newBuilder()
.setMinSessions(2)
surbhigarg92 marked this conversation as resolved.
Show resolved Hide resolved
.setWaitForMinSessions(Duration.ofSeconds(5))
.build());

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

Expand Down Expand Up @@ -339,9 +327,6 @@ public void singleUse() {
expectedReadOnlyTransactionSingleUseEvents,
expectedReadOnlyTransactionSingleUseEventsCount);
break;
case "SessionPool.WaitForSession":
assertEquals(0, spanItem.getEvents().size());
break;
default:
assert false;
}
Expand Down Expand Up @@ -385,9 +370,6 @@ public void multiUse() {
expectedExecuteStreamingQueryEvents,
expectedExecuteStreamingQueryEventsCount);
break;
case "SessionPool.WaitForSession":
assertEquals(0, spanItem.getEvents().size());
break;
case "CloudSpanner.ReadOnlyTransaction":
verifyRequestEvents(
spanItem,
Expand All @@ -406,7 +388,6 @@ public void multiUse() {
public void transactionRunner() {
TransactionRunner runner = client.readWriteTransaction();
runner.run(transaction -> transaction.executeUpdate(UPDATE_STATEMENT));

List<String> actualSpanItems = new ArrayList<>();
spanExporter
.getFinishedSpanItems()
Expand All @@ -426,7 +407,6 @@ public void transactionRunner() {
expectedBatchCreateSessionsEvents,
expectedBatchCreateSessionsEventsCount);
break;
case "SessionPool.WaitForSession":
case "CloudSpannerOperation.Commit":
assertEquals(0, spanItem.getEvents().size());
break;
Expand Down Expand Up @@ -472,9 +452,6 @@ public void transactionRunnerWithError() {
expectedBatchCreateSessionsEvents,
expectedBatchCreateSessionsEventsCount);
break;
case "SessionPool.WaitForSession":
assertEquals(0, spanItem.getEvents().size());
break;
case "CloudSpanner.ReadWriteTransaction":
verifyRequestEvents(
spanItem,
Expand Down Expand Up @@ -527,7 +504,6 @@ public void transactionRunnerWithFailedAndBeginTransaction() {
expectedBatchCreateSessionsEvents,
expectedBatchCreateSessionsEventsCount);
break;
case "SessionPool.WaitForSession":
case "CloudSpannerOperation.Commit":
case "CloudSpannerOperation.BeginTransaction":
assertEquals(0, spanItem.getEvents().size());
Expand All @@ -551,13 +527,13 @@ private void verifyRequestEvents(SpanData spanItem, List<String> expectedEvents,
spanItem.getEvents().stream().map(EventData::getName).collect(Collectors.toList());
assertEquals(eventCount, spanItem.getEvents().size());
assertEquals(
eventNames.stream().distinct().sorted().collect(Collectors.toList()),
expectedEvents.stream().sorted().collect(Collectors.toList()));
expectedEvents.stream().sorted().collect(Collectors.toList()),
eventNames.stream().distinct().sorted().collect(Collectors.toList()));
}

private static void verifySpans(List<String> actualSpanItems, List<String> expectedSpansItems) {
assertEquals(
actualSpanItems.stream().distinct().sorted().collect(Collectors.toList()),
expectedSpansItems.stream().sorted().collect(Collectors.toList()));
expectedSpansItems.stream().sorted().collect(Collectors.toList()),
actualSpanItems.stream().distinct().sorted().collect(Collectors.toList()));
}
}
Loading
Loading