Relax auth error metric count validation in reconnection test (#754)
Test previously asserted that the getAuthenticationErrors() metric
incremented at the same rate as the AuthProvider#newAuthenticator count,
which may not be true as we could be checking between a newAuthenticator
request and an authentication request happening. Instead ensure that
the count goes up.
diff --git a/driver-core/src/test/java/com/datastax/driver/core/ReconnectionTest.java b/driver-core/src/test/java/com/datastax/driver/core/ReconnectionTest.java
index 20a45f3..b79698a 100644
--- a/driver-core/src/test/java/com/datastax/driver/core/ReconnectionTest.java
+++ b/driver-core/src/test/java/com/datastax/driver/core/ReconnectionTest.java
@@ -106,17 +106,19 @@
ccm().start(1);
ccm().waitForUp(1);
- // Wait a few iterations to ensure that our authProvider has returned the wrong credentials at least once
+ // Wait a few iterations to ensure that our authProvider has returned the wrong credentials at least twice
// NB: authentication errors show up in the logs
int initialCount = authProvider.count.get();
+ long initialMetricCount = cluster.getMetrics().getErrorMetrics().getAuthenticationErrors().getCount();
int iterations = 0, maxIterations = 12; // make sure we don't wait indefinitely
do {
iterations += 1;
TimeUnit.SECONDS.sleep(5);
- } while (iterations < maxIterations && authProvider.count.get() <= initialCount);
+ } while (iterations < maxIterations && authProvider.count.get() <= initialCount + 1);
assertThat(iterations).isLessThan(maxIterations);
+ // Number of authentication errors should have increased.
assertThat(cluster.getMetrics().getErrorMetrics().getAuthenticationErrors().getCount())
- .isEqualTo(authProvider.count.get() - initialCount);
+ .isGreaterThan(initialMetricCount);
// Fix the credentials
authProvider.setPassword("cassandra");