Skip to content

Commit e6c5ed8

Browse files
committed
test.py: make sure scylla start is not race prone
auth::standard_role_manager creates "cassandra" role in an async loop auth::do_after_system_ready(), which retries role creation with an exponential back-off. In other words, even after CQL port is up, Scylla may still be initializing. This race condition could lead to spurious errors during cluster bootstrap or during a test under CI. When the role is ready, queries begin to work, so rely on this "side effect".
1 parent 9cfc18b commit e6c5ed8

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

test/pylib/scylla_server.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import time
1212
import aiohttp
1313
from typing import Optional, List
14+
from cassandra import InvalidRequest # type: ignore
1415
from cassandra.auth import PlainTextAuthProvider # type: ignore
1516
from cassandra.cluster import Cluster, NoHostAvailable # type: ignore
1617
from cassandra.cluster import ExecutionProfile, EXEC_PROFILE_DEFAULT # type: ignore
@@ -215,9 +216,18 @@ async def cql_is_up(self) -> bool:
215216
try:
216217
with Cluster(execution_profiles={EXEC_PROFILE_DEFAULT: profile},
217218
contact_points=[self.hostname], auth_provider=auth) as cluster:
218-
with cluster.connect():
219+
with cluster.connect() as session:
220+
# auth::standard_role_manager creates "cassandra" role in an
221+
# async loop auth::do_after_system_ready(), which retries
222+
# role creation with an exponential back-off. In other
223+
# words, even after CQL port is up, Scylla may still be
224+
# initializing. When the role is ready, queries begin to
225+
# work, so rely on this "side effect".
226+
session.execute("CREATE KEYSPACE k WITH REPLICATION = {" +
227+
"'class' : 'SimpleStrategy', 'replication_factor' : 1 }")
228+
session.execute("DROP KEYSPACE k")
219229
return True
220-
except NoHostAvailable:
230+
except (NoHostAvailable, InvalidRequest):
221231
return False
222232
finally:
223233
caslog.setLevel(oldlevel)

0 commit comments

Comments
 (0)