Repository navigation
test(spanner): unflake BuiltInMetricsCustomOpenTelemetryTest and BuiltInMetricsBothSinksTest - #14282
Conversation
…tInMetricsBothSinksTest
In `executeSelect1()`, `resultSet.next()` was called only once for `SELECT 1`.
Closing the `ResultSet` before consuming the stream to EOF invokes
`iterator.close()`, which sends `call.cancel("ResultSet closed", null)` to
the underlying gRPC stream.
If client cancellation races ahead of the mock server's `onCompleted()`, the
stream terminates with `Status.CANCELLED`. As a result,
`SpannerTracer.operationSucceeded()` is never invoked, omitting
`Spanner.ExecuteStreamingSql` (status `OK`) from
`spanner.googleapis.com/internal/client/operation_count` and causing the
test assertion to fail.
Consume the `ResultSet` to EOF (`assertFalse(resultSet.next())`) in both
`BuiltInMetricsCustomOpenTelemetryTest` and `BuiltInMetricsBothSinksTest`
to guarantee that the stream finishes normally before closing.
There was a problem hiding this comment.
Code Review
This pull request adds assertions to verify that the result set has no more elements after reading the first row in Spanner test files. The feedback suggests using Google Truth assertions instead of JUnit assertions in BuiltInMetricsCustomOpenTelemetryTest to maintain consistency with the rest of the codebase.
| assertTrue(resultSet.next()); | ||
| assertThat(resultSet.getLong(0)).isEqualTo(1L); | ||
| assertFalse(resultSet.next()); |
There was a problem hiding this comment.
To maintain consistency with the rest of the assertions in this codebase and avoid mixing different assertion frameworks within the same block, please use Google Truth assertions (assertThat(...).isTrue() and assertThat(...).isFalse()) instead of JUnit's assertTrue and assertFalse. If you apply this change, you can also remove the unused import of org.junit.Assert.assertFalse at line 20.
| assertTrue(resultSet.next()); | |
| assertThat(resultSet.getLong(0)).isEqualTo(1L); | |
| assertFalse(resultSet.next()); | |
| assertThat(resultSet.next()).isTrue(); | |
| assertThat(resultSet.getLong(0)).isEqualTo(1L); | |
| assertThat(resultSet.next()).isFalse(); |
In
executeSelect1(),resultSet.next()was called only once forSELECT 1. Closing theResultSetbefore consuming the stream to EOF invokesiterator.close(), which sendscall.cancel("ResultSet closed", null)to the underlying gRPC stream.If client cancellation races ahead of the mock server's
onCompleted(), the stream terminates withStatus.CANCELLED. As a result,SpannerTracer.operationSucceeded()is never invoked, omittingSpanner.ExecuteStreamingSql(statusOK) fromspanner.googleapis.com/internal/client/operation_countand causing the test assertion to fail.Consume the
ResultSetto EOF (assertFalse(resultSet.next())) in bothBuiltInMetricsCustomOpenTelemetryTestandBuiltInMetricsBothSinksTestto guarantee that the stream finishes normally before closing.