Skip to content

Commit 0263544

Browse files
committed
test: fix flakey test for FlightStream overhead.
1 parent 4a151d7 commit 0263544

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/main/java/com/influxdb/v3/client/internal/FlightSqlClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
final class FlightSqlClient implements AutoCloseable {
7575

7676
private static final Logger LOG = LoggerFactory.getLogger(FlightSqlClient.class);
77-
private static final int AUTOCLOSEABLE_CHECK_LIMIT = 10;
77+
static final int AUTOCLOSEABLE_CHECK_LIMIT = 10;
7878
static final Map<AutoCloseable, Boolean> CLOSEABLE_CLOSED_LEDGER = new ConcurrentHashMap<>();
7979

8080
private final FlightClient client;

src/test/java/com/influxdb/v3/client/internal/FlightSqlClientTest.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323

2424
import java.net.InetSocketAddress;
2525
import java.net.URISyntaxException;
26+
import java.util.ArrayList;
2627
import java.util.HashMap;
28+
import java.util.List;
2729
import java.util.Map;
2830
import java.util.stream.IntStream;
2931
import java.util.stream.Stream;
@@ -380,6 +382,7 @@ public void multipleFlightStreamsFreed() throws Exception {
380382

381383
try (FlightSqlClient flightSqlClient = new FlightSqlClient(clientConfig)) {
382384

385+
List<AutoCloseable> autoCloseables = new ArrayList<>();
383386
for (int i = 0; i < 20; i++) {
384387
Stream<VectorSchemaRoot> stream = flightSqlClient.execute(
385388
"select * from cpu",
@@ -389,14 +392,19 @@ public void multipleFlightStreamsFreed() throws Exception {
389392
Map.of());
390393

391394
stream.forEach(VectorSchemaRoot::contentToTSVString);
395+
autoCloseables.add(flightSqlClient.autoCloseables.get(flightSqlClient.autoCloseables.size() - 1));
396+
392397
}
393398
Assertions.assertThat(flightSqlClient.autoCloseables.size()).isEqualTo(9);
394-
// N.B. can pick up references from other tests...
395-
Assertions.assertThat(FlightSqlClient.CLOSEABLE_CLOSED_LEDGER.size()).isLessThan(20);
396-
for (AutoCloseable closeable : FlightSqlClient.CLOSEABLE_CLOSED_LEDGER.keySet()) {
397-
Assertions.assertThat(FlightSqlClient.CLOSEABLE_CLOSED_LEDGER.get(closeable)).isTrue(); // Is closed
399+
for (int i = 0; i < autoCloseables.size(); i++) {
400+
if (i < FlightSqlClient.AUTOCLOSEABLE_CHECK_LIMIT + 1) {
401+
Assertions.assertThat(flightSqlClient.autoCloseables.contains(autoCloseables.get(i))).isFalse();
402+
Assertions.assertThat(FlightSqlClient.CLOSEABLE_CLOSED_LEDGER.get(autoCloseables.get(i))).isNull();
403+
} else {
404+
Assertions.assertThat(flightSqlClient.autoCloseables.contains(autoCloseables.get(i))).isTrue();
405+
Assertions.assertThat(flightSqlClient.autoCloseables.contains(autoCloseables.get(i))).isTrue();
406+
}
398407
}
399-
400408
}
401409
}
402410

0 commit comments

Comments
 (0)