Skip to content

test(spanner): unflake closeWhileStreamIsStartingInvokesOnDoneSynchronously - #14920

Closed
sakthivelmanii wants to merge 1 commit into
mainfrom
unflake-close-while-stream-is-starting
Closed

sakthivelmanii wants to merge 1 commit into
mainfrom
unflake-close-while-stream-is-starting

Conversation

@sakthivelmanii

Copy link
Copy Markdown
Contributor

Problem

  • The test closeWhileStreamIsStartingInvokesOnDoneSynchronously in GrpcResultSetTest throws a ClassCastException: com.google.cloud.spanner.OpenCensusSpan cannot be cast to com.google.cloud.spanner.OpenTelemetrySpan.
  • This flaky failure is deterministic when tests are run sequentially in the same JVM fork (e.g. SessionImplTest followed by GrpcResultSetTest).
  • The static activeTracingFramework state in SpannerOptions is set to OPEN_TELEMETRY by other tests calling SpannerOptions.enableOpenTelemetryTraces() without proper cleanup.
  • As a result, when GrpcResultSetTest passes a hardcoded OpenCensusSpan to TraceWrapper, the wrapper attempts to cast it to OpenTelemetrySpan, leading to the ClassCastException.

Solution

  • Added @BeforeClass in GrpcResultSetTest to explicitly call SpannerOptions.resetActiveTracingFramework().
  • This ensures the static tracing state is reset to OPEN_CENSUS before the tests in this class run, preventing state pollution.

…nously

## Problem

- The test `closeWhileStreamIsStartingInvokesOnDoneSynchronously` in `GrpcResultSetTest` throws a `ClassCastException`: `com.google.cloud.spanner.OpenCensusSpan cannot be cast to com.google.cloud.spanner.OpenTelemetrySpan`.
- This flaky failure is deterministic when tests are run sequentially in the same JVM fork (e.g. `SessionImplTest` followed by `GrpcResultSetTest`).
- The static `activeTracingFramework` state in `SpannerOptions` is set to `OPEN_TELEMETRY` by other tests calling `SpannerOptions.enableOpenTelemetryTraces()` without proper cleanup.
- As a result, when `GrpcResultSetTest` passes a hardcoded `OpenCensusSpan` to `TraceWrapper`, the wrapper attempts to cast it to `OpenTelemetrySpan`, leading to the `ClassCastException`.

## Solution

- Added `@BeforeClass` in `GrpcResultSetTest` to explicitly call `SpannerOptions.resetActiveTracingFramework()`.
- This ensures the static tracing state is reset to `OPEN_CENSUS` before the tests in this class run, preventing state pollution.
@sakthivelmanii
sakthivelmanii requested review from a team as code owners November 4, 2026 06:22
@sakthivelmanii
sakthivelmanii enabled auto-merge (squash) November 4, 2026 06:22
@sakthivelmanii

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds comprehensive unit tests to GrpcResultSetTest.java covering data availability, streaming delegation, and various concurrency and race conditions during stream closure and error handling. However, there is a critical issue where the @BeforeClass method beforeClass() is declared twice with the exact same signature, which will cause a compilation error and needs to be resolved.

Comment on lines +89 to +97
@org.junit.BeforeClass
public static void beforeClass() {
SpannerOptions.resetActiveTracingFramework();
}

@org.junit.BeforeClass
public static void beforeClass() {
SpannerOptions.resetActiveTracingFramework();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The @BeforeClass method beforeClass() is declared twice with the exact same signature. This will cause a compilation error. Please remove the duplicate method declaration.

Suggested change
@org.junit.BeforeClass
public static void beforeClass() {
SpannerOptions.resetActiveTracingFramework();
}
@org.junit.BeforeClass
public static void beforeClass() {
SpannerOptions.resetActiveTracingFramework();
}
@BeforeClass
public static void beforeClass() {
SpannerOptions.resetActiveTracingFramework();
}
References
  1. Do not use fully qualified class names if there is no class name conflict in the file and the class is already imported, as it unnecessarily reduces code readability.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces several unit tests to GrpcResultSetTest.java to verify data availability, stream closing behaviors, race conditions, and error handling in GrpcResultSet. The feedback highlights a critical compilation error caused by a duplicated @BeforeClass method beforeClass(), which must be removed.

Comment on lines +89 to +97
@org.junit.BeforeClass
public static void beforeClass() {
SpannerOptions.resetActiveTracingFramework();
}

@org.junit.BeforeClass
public static void beforeClass() {
SpannerOptions.resetActiveTracingFramework();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The @BeforeClass method beforeClass() is duplicated. This will cause a compilation error in Java because two methods with the same name and signature cannot coexist in the same class. Please remove the duplicate method.

Suggested change
@org.junit.BeforeClass
public static void beforeClass() {
SpannerOptions.resetActiveTracingFramework();
}
@org.junit.BeforeClass
public static void beforeClass() {
SpannerOptions.resetActiveTracingFramework();
}
@BeforeClass
public static void beforeClass() {
SpannerOptions.resetActiveTracingFramework();
}
References
  1. Do not use fully qualified class names if there is no class name conflict in the file and the class is already imported, as it unnecessarily reduces code readability.

@sakthivelmanii

Copy link
Copy Markdown
Contributor Author

Closing in favour of #14901 which already fixed this issue.

auto-merge was automatically disabled November 4, 2026 06:24

Pull request was closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant