Skip to content
Permalink
Browse files
Fix flaky test consistent_bootstrap_test.py::TestBootstrapConsistency…
…::test_consistent_reads_after_move

patch by David Capwell; reviewed by Abe Ratnofsky, Ekaterina Dimitrova for CASSANDRA-16826
  • Loading branch information
dcapwell committed Aug 4, 2021
1 parent 8fb42c0 commit 230c66c9395fb339d08744d832279281928d3b9b
Showing 3 changed files with 9 additions and 6 deletions.
@@ -49,10 +49,10 @@ def test_consistent_reads_after_move(self):

logger.debug("Checking that no data was lost")
for n in range(10, 20):
query_c1c2(n2session, n, ConsistencyLevel.ALL)
query_c1c2(n2session, n, ConsistencyLevel.ALL, max_attempts=3)

for n in range(30, 1000):
query_c1c2(n2session, n, ConsistencyLevel.ALL)
query_c1c2(n2session, n, ConsistencyLevel.ALL, max_attempts=3)

def test_consistent_reads_after_bootstrap(self):
logger.debug("Creating a ring")
@@ -8,6 +8,7 @@
from . import assertions
from dtest import create_cf, DtestTimeoutError
from tools.funcutils import get_rate_limited_function
from tools.flaky import retry

logger = logging.getLogger(__name__)

@@ -29,9 +30,9 @@ def insert_c1c2(session, keys=None, n=None, consistency=ConsistencyLevel.QUORUM)
execute_concurrent_with_args(session, statement, [['k{}'.format(k)] for k in keys])


def query_c1c2(session, key, consistency=ConsistencyLevel.QUORUM, tolerate_missing=False, must_be_missing=False):
def query_c1c2(session, key, consistency=ConsistencyLevel.QUORUM, tolerate_missing=False, must_be_missing=False, max_attempts=1):
query = SimpleStatement('SELECT c1, c2 FROM cf WHERE key=\'k%d\'' % key, consistency_level=consistency)
rows = list(session.execute(query))
rows = list(retry(lambda: session.execute(query), max_attempts=max_attempts))
if not tolerate_missing:
assertions.assert_length_equal(rows, 1)
res = rows[0]
@@ -36,9 +36,11 @@ def requires_rerun(err, *args):
# err[0] contains the type of the error that occurred
return err[0] == RerunTestException

def retry(fn, num_retries=10, allowed_error=None, sleep_seconds=1):
def retry(fn, max_attempts=10, allowed_error=None, sleep_seconds=1):
if max_attempts <= 0:
raise ValueError("max_attempts must be a positive value, but given {}".format(str(max_attempts)))
last_error = None
for x in range(0, num_retries):
for _ in range(0, max_attempts):
try:
return fn()
except Exception as e:

0 comments on commit 230c66c

Please sign in to comment.