Skip to content

Commit

Permalink
Fix session leak in PeersV2NodeRefreshIT test
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dimakr authored and Piotr Grabowski committed May 6, 2024
1 parent d62b851 commit 597f0c8
Showing 1 changed file with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,18 @@ public static void tearDown() {
@Test
public void should_successfully_send_peers_v2_node_refresh_query()
throws InterruptedException, ExecutionException {
CqlSession session =
CqlSession.builder().addContactPoint(cluster.node(1).inetSocketAddress()).build();
Node node = findNonControlNode(session);
((InternalDriverContext) session.getContext())
.getMetadataManager()
.refreshNode(node)
.toCompletableFuture()
.get();
assertThat(hasNodeRefreshQuery())
.describedAs("Expecting peers_v2 node refresh query to be present but it wasn't")
.isTrue();
try (CqlSession session =
CqlSession.builder().addContactPoint(cluster.node(1).inetSocketAddress()).build()) {
Node node = findNonControlNode(session);
((InternalDriverContext) session.getContext())
.getMetadataManager()
.refreshNode(node)
.toCompletableFuture()
.get();
assertThat(hasNodeRefreshQuery())
.describedAs("Expecting peers_v2 node refresh query to be present but it wasn't")
.isTrue();
}
}

private Node findNonControlNode(CqlSession session) {
Expand Down

0 comments on commit 597f0c8

Please sign in to comment.