Skip to content

Commit bea9b3a

Browse files
committed
Fix session leak in PeersV2NodeRefreshIT test
PeersV2NodeRefreshIT#should_successfully_send_peers_v2_node_refresh_query integration test does not close its test session, leading to leaks when integration tests suite is executed in CI. This affects SessionLeakIT#should_warn_when_session_count_exceeds_threshold test, which sees the leaked session and fails due to an unexpected number of active sessions. The change wraps the test in try-with block so that the test session is autoclosed at the end, preventing it from affecting subsequent tests.
1 parent d62b851 commit bea9b3a

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

Diff for: integration-tests/src/test/java/com/datastax/oss/driver/core/PeersV2NodeRefreshIT.java

+12-11
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,18 @@ public static void tearDown() {
5656
@Test
5757
public void should_successfully_send_peers_v2_node_refresh_query()
5858
throws InterruptedException, ExecutionException {
59-
CqlSession session =
60-
CqlSession.builder().addContactPoint(cluster.node(1).inetSocketAddress()).build();
61-
Node node = findNonControlNode(session);
62-
((InternalDriverContext) session.getContext())
63-
.getMetadataManager()
64-
.refreshNode(node)
65-
.toCompletableFuture()
66-
.get();
67-
assertThat(hasNodeRefreshQuery())
68-
.describedAs("Expecting peers_v2 node refresh query to be present but it wasn't")
69-
.isTrue();
59+
try (CqlSession session =
60+
CqlSession.builder().addContactPoint(cluster.node(1).inetSocketAddress()).build()) {
61+
Node node = findNonControlNode(session);
62+
((InternalDriverContext) session.getContext())
63+
.getMetadataManager()
64+
.refreshNode(node)
65+
.toCompletableFuture()
66+
.get();
67+
assertThat(hasNodeRefreshQuery())
68+
.describedAs("Expecting peers_v2 node refresh query to be present but it wasn't")
69+
.isTrue();
70+
}
7071
}
7172

7273
private Node findNonControlNode(CqlSession session) {

0 commit comments

Comments
 (0)