Skip to content
This repository was archived by the owner on Apr 7, 2026. It is now read-only.

Commit b2b7bb2

Browse files
authored
test: removes flaky close result set test (#888)
This test was introduced in order to debug stuck transactions. The cause was unrelated though. The test here is flaky, because there is a race condition between setting the stream field in the AbstractResultSet and checking it in the close method. Since the result set is not intended to be thread safe, we will not be synchronizing this variable.
1 parent 864f2a2 commit b2b7bb2

1 file changed

Lines changed: 0 additions & 73 deletions

File tree

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

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import com.google.cloud.spanner.MockSpannerServiceImpl.StatementResult;
3737
import com.google.cloud.spanner.TransactionRunner.TransactionCallable;
3838
import com.google.cloud.spanner.TransactionRunnerImpl.TransactionContextImpl;
39-
import com.google.common.base.Predicate;
4039
import com.google.common.collect.ImmutableList;
4140
import com.google.common.util.concurrent.MoreExecutors;
4241
import com.google.protobuf.AbstractMessage;
@@ -61,15 +60,13 @@
6160
import java.util.Collection;
6261
import java.util.List;
6362
import java.util.concurrent.Callable;
64-
import java.util.concurrent.CountDownLatch;
6563
import java.util.concurrent.ExecutionException;
6664
import java.util.concurrent.Executor;
6765
import java.util.concurrent.ExecutorService;
6866
import java.util.concurrent.Executors;
6967
import java.util.concurrent.Future;
7068
import java.util.concurrent.ScheduledExecutorService;
7169
import java.util.concurrent.ScheduledThreadPoolExecutor;
72-
import java.util.concurrent.TimeUnit;
7370
import java.util.concurrent.TimeoutException;
7471
import java.util.concurrent.atomic.AtomicBoolean;
7572
import org.junit.After;
@@ -1501,76 +1498,6 @@ public Void run(TransactionContext transaction) throws Exception {
15011498
assertThat(countRequests(CommitRequest.class)).isEqualTo(1);
15021499
}
15031500

1504-
@Test
1505-
public void testCloseResultSetWhileRequestInFlight() throws Exception {
1506-
DatabaseClient client = spanner.getDatabaseClient(DatabaseId.of("p", "i", "d"));
1507-
final ExecutorService service = Executors.newSingleThreadExecutor();
1508-
try {
1509-
client
1510-
.readWriteTransaction()
1511-
.run(
1512-
new TransactionCallable<Void>() {
1513-
@Override
1514-
public Void run(TransactionContext transaction) throws Exception {
1515-
final ResultSet rs = transaction.executeQuery(SELECT1);
1516-
// Prevent the server from executing the query.
1517-
final CountDownLatch latch = new CountDownLatch(1);
1518-
mockSpanner.freeze();
1519-
service.submit(
1520-
new Runnable() {
1521-
@Override
1522-
public void run() {
1523-
try {
1524-
// This call will be stuck on the server until the mock server is
1525-
// unfrozen.
1526-
rs.next();
1527-
} finally {
1528-
latch.countDown();
1529-
}
1530-
}
1531-
});
1532-
1533-
// First wait for the request to be on the server and then close the result set
1534-
// while the request is in flight.
1535-
mockSpanner.waitForRequestsToContain(
1536-
new Predicate<AbstractMessage>() {
1537-
@Override
1538-
public boolean apply(AbstractMessage input) {
1539-
return input instanceof ExecuteSqlRequest
1540-
&& ((ExecuteSqlRequest) input).getTransaction().hasBegin();
1541-
}
1542-
},
1543-
1000L);
1544-
rs.close();
1545-
// The next statement should now fail before it is sent to the server because
1546-
// the first statement failed to return a transaction while the result set was
1547-
// still open.
1548-
mockSpanner.unfreeze();
1549-
latch.await(1L, TimeUnit.SECONDS);
1550-
try {
1551-
transaction.executeUpdate(UPDATE_STATEMENT);
1552-
fail("missing expected exception");
1553-
} catch (SpannerException e) {
1554-
assertThat(e.getErrorCode()).isEqualTo(ErrorCode.FAILED_PRECONDITION);
1555-
assertThat(e.getMessage())
1556-
.contains("ResultSet was closed before a transaction id was returned");
1557-
}
1558-
return null;
1559-
}
1560-
});
1561-
fail("missing expected exception");
1562-
} catch (SpannerException e) {
1563-
// The commit request will also fail, which means that the entire transaction will fail.
1564-
assertThat(e.getErrorCode()).isEqualTo(ErrorCode.FAILED_PRECONDITION);
1565-
assertThat(e.getMessage())
1566-
.contains("ResultSet was closed before a transaction id was returned");
1567-
}
1568-
service.shutdown();
1569-
assertThat(countRequests(BeginTransactionRequest.class)).isEqualTo(0);
1570-
assertThat(countRequests(ExecuteSqlRequest.class)).isEqualTo(1);
1571-
assertThat(countRequests(CommitRequest.class)).isEqualTo(0);
1572-
}
1573-
15741501
@Test
15751502
public void testQueryWithInlineBeginDidNotReturnTransaction() {
15761503
DatabaseClient client = spanner.getDatabaseClient(DatabaseId.of("p", "i", "d"));

0 commit comments

Comments
 (0)