Skip to content

Commit

Permalink
node: stress_object: ignore commas in numbers
Browse files Browse the repository at this point in the history
Some resharding_test dtest, e.g. `test_resharding_counter` fails locally for me:
```
    def _run_stress(self, op_cnt, stress_cmd):
        res = self.node.stress_object(stress_cmd)
        if not isinstance(res, dict):
            raise Exception('Error running cassandra-stress: {}'.format(res))
        assert res['total errors'] == 0
>       assert res['total partitions'] >= op_cnt
E       assert 10.0 >= 10000
```

When printing the cassandra-stress stdout I saw that it
uses a comma as a 1000s separator:
```
Total partitions          :     10,000 [COUNTER_READ: 10,000]
```

This is probably related to the LOCALE on my machine.

This change removes any commas from the value
in _set_stress_val before converting it to `float`
using `locale.atof`.

Signed-off-by: Benny Halevy <[email protected]>
  • Loading branch information
bhalevy committed Dec 17, 2023
1 parent 40f3517 commit e4cc609
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions ccmlib/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -1383,22 +1383,24 @@ def _set_keyspace_initial_tablets(stress_options: List[str], initial_tablets:int
def _set_stress_val(key, val, res):
# Set locale to the user's default value (usually specified in the LANG)
locale.setlocale(locale.LC_NUMERIC, '')
def atof(v):
return locale.atof(v.replace(',', ''))
if "[" in val:
p = re.compile(r'^\s*([\d\.\,]+\d?)\s*\[.*')
m = p.match(val)
if m:
res[key] = locale.atof(m.group(1))
res[key] = atof(m.group(1))
p = re.compile(r'^.*READ:\s*([\d\.\,]+\d?)[^\d].*')
m = p.match(val)
if m:
res[key + ":read"] = locale.atof(m.group(1))
res[key + ":read"] = atof(m.group(1))
p = re.compile(r'.*WRITE:\s*([\d\.\,]+\d?)[^\d].*')
m = p.match(val)
if m:
res[key + ":write"] = locale.atof(m.group(1))
res[key + ":write"] = atof(m.group(1))
else:
try:
res[key] = locale.atof(val)
res[key] = atof(val)
except ValueError:
res[key] = val

Expand All @@ -1408,6 +1410,9 @@ def stress_object(self, stress_options=None, ignore_errors=None, **kwargs):
ret = self.stress(stress_options, **kwargs)
p = re.compile(r'^\s*([^:]+)\s*:\s*(\S.*)\s*$')
res = {}
res['stdout'] = ret.stdout
res['stderr'] = ret.stderr
res['rc'] = ret.rc
start = False
for line in [s.strip() for s in ret.stdout.splitlines()]:
if start:
Expand Down

0 comments on commit e4cc609

Please sign in to comment.