Skip to content

Commit 1f22092

Browse files
committed
Fix flakiness of AuditLoggerAuthTest and CQLUserAuditTest by awaiting of default superuser role creation
patch by Dmitry Konstantinov; reviewed by Michael Semb Wever for CASSANDRA-19165
1 parent 350c83d commit 1f22092

2 files changed

Lines changed: 20 additions & 10 deletions

File tree

test/unit/org/apache/cassandra/audit/AuditLoggerAuthTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.junit.Test;
3737

3838
import org.apache.cassandra.ServerTestUtils;
39+
import org.apache.cassandra.auth.AuthTestUtils;
3940
import org.apache.cassandra.auth.CassandraAuthorizer;
4041
import org.apache.cassandra.auth.CassandraRoleManager;
4142
import org.apache.cassandra.auth.PasswordAuthenticator;
@@ -82,6 +83,7 @@ public static void setup() throws Exception
8283

8384
SUPERUSER_SETUP_DELAY_MS.setLong(0);
8485
embedded = ServerTestUtils.startEmbeddedCassandraService();
86+
AuthTestUtils.waitForExistingRoles();
8587

8688
executeWithCredentials(
8789
Arrays.asList(getCreateRoleCql(TEST_USER, true, false, false),
@@ -368,6 +370,8 @@ private static void executeWithCredentials(List<String> queries, String username
368370
}
369371
catch (AuthenticationException e)
370372
{
373+
if (expectedType == null)
374+
throw e;
371375
authFailed = true;
372376
}
373377
catch (UnauthorizedException ue)

test/unit/org/apache/cassandra/transport/CQLUserAuditTest.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.apache.cassandra.audit.AuditLogEntryType;
4545
import org.apache.cassandra.audit.AuditLogManager;
4646
import org.apache.cassandra.audit.DiagnosticEventAuditLogger;
47+
import org.apache.cassandra.auth.AuthTestUtils;
4748
import org.apache.cassandra.auth.CassandraRoleManager;
4849
import org.apache.cassandra.auth.PasswordAuthenticator;
4950
import org.apache.cassandra.config.DatabaseDescriptor;
@@ -78,6 +79,8 @@ public static void setup() throws Exception
7879
SUPERUSER_SETUP_DELAY_MS.setLong(0);
7980

8081
embedded = ServerTestUtils.startEmbeddedCassandraService();
82+
AuthTestUtils.waitForExistingRoles();
83+
8184

8285
executeAs(Arrays.asList("CREATE ROLE testuser WITH LOGIN = true AND SUPERUSER = false AND PASSWORD = 'foo'",
8386
"CREATE ROLE testuser_nologin WITH LOGIN = false AND SUPERUSER = false AND PASSWORD = 'foo'",
@@ -214,20 +217,23 @@ private static ArrayList<AuditEvent> executeAs(List<String> queries, String user
214217
AuditLogEntryType expectedAuthType) throws Exception
215218
{
216219
boolean authFailed = false;
217-
Cluster cluster = Cluster.builder().addContactPoints(InetAddress.getLoopbackAddress())
220+
try(Cluster cluster = Cluster.builder().addContactPoints(InetAddress.getLoopbackAddress())
218221
.withoutJMXReporting()
219222
.withCredentials(username, password)
220-
.withPort(DatabaseDescriptor.getNativeTransportPort()).build();
221-
try (Session session = cluster.connect())
222-
{
223-
for (String query : queries)
224-
session.execute(query);
225-
}
226-
catch (AuthenticationException e)
223+
.withPort(DatabaseDescriptor.getNativeTransportPort()).build())
227224
{
228-
authFailed = true;
225+
try (Session session = cluster.connect())
226+
{
227+
for (String query : queries)
228+
session.execute(query);
229+
}
230+
catch (AuthenticationException e)
231+
{
232+
if (expectedAuthType == null)
233+
throw e;
234+
authFailed = true;
235+
}
229236
}
230-
cluster.close();
231237

232238
if (expectedAuthType == null) return null;
233239

0 commit comments

Comments
 (0)