Skip to content

Commit 2366b0b

Browse files
committed
fix: stabilize prepared statement invalidation test
1 parent 412b95c commit 2366b0b

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

integration-tests/src/test/java/com/datastax/oss/driver/core/cql/PreparedStatementCachingIT.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.datastax.oss.driver.core.cql;
1919

2020
import static org.assertj.core.api.Assertions.assertThat;
21+
import static org.awaitility.Awaitility.await;
2122

2223
import com.codahale.metrics.Gauge;
2324
import com.datastax.oss.driver.api.core.CqlSession;
@@ -226,7 +227,6 @@ private void invalidationTestInner(
226227
ByteBuffer queryId2 = session.prepare(preparedStmtQueryType2).getId();
227228
assertThat(getPreparedCacheSize(session)).isEqualTo(2);
228229

229-
CountDownLatch preparedStmtCacheRemoveLatch = new CountDownLatch(1);
230230
CountDownLatch typeChangeEventLatch = new CountDownLatch(expectedChangedTypes.size());
231231

232232
DefaultDriverContext ctx = (DefaultDriverContext) session.getContext();
@@ -260,23 +260,24 @@ private void invalidationTestInner(
260260
removedQueryEventError.set(
261261
Optional.of("Unable to set reference for PS removal event"));
262262
}
263-
preparedStmtCacheRemoveLatch.countDown();
264263
});
265264

266265
// alter test_type_2 to trigger cache invalidation and above events
267266
session.execute("ALTER TYPE test_type_2 add i blob");
268267

269-
// wait for latches and fail if they don't reach zero before timeout
268+
// wait for schema propagation and prepared statement invalidation to settle
270269
assertThat(Uninterruptibles.awaitUninterruptibly(typeChangeEventLatch, 60, TimeUnit.SECONDS))
271270
.withFailMessage("typeChangeEventLatch did not trigger before timeout")
272271
.isTrue();
273-
assertThat(
274-
Uninterruptibles.awaitUninterruptibly(
275-
preparedStmtCacheRemoveLatch, 60, TimeUnit.SECONDS))
276-
.withFailMessage("preparedStmtCacheRemoveLatch did not trigger before timeout")
277-
.isTrue();
272+
await()
273+
.atMost(120, TimeUnit.SECONDS)
274+
.untilAsserted(
275+
() -> {
276+
assertThat(removedQueryIds.get()).isNotEmpty().get().isEqualTo(queryId2);
277+
assertThat(getPreparedCacheSize(session)).isEqualTo(1);
278+
});
278279

279-
/* Okay, the latch triggered so cache processing should now be done. Let's validate :allthethings: */
280+
/* Okay, the type change and cache invalidation events should now be done. */
280281
assertThat(changedTypes.keySet()).isEqualTo(expectedChangedTypes);
281282
assertThat(removedQueryIds.get()).isNotEmpty().get().isEqualTo(queryId2);
282283
assertThat(getPreparedCacheSize(session)).isEqualTo(1);

0 commit comments

Comments
 (0)