mirror of
https://github.com/ceph/s3-tests.git
synced 2024-12-23 13:41:52 +00:00
S3 Fuzzer: set values can be weighted lists now
This commit is contained in:
parent
4737652fc1
commit
3f1314f7c8
2 changed files with 31 additions and 4 deletions
|
@ -52,8 +52,14 @@ def build_graph():
|
|||
},
|
||||
'choices': ['leaf']
|
||||
}
|
||||
graph['weighted_choices'] = {
|
||||
'set': {},
|
||||
graph['weighted_node'] = {
|
||||
'set': {
|
||||
'k1': [
|
||||
'foo',
|
||||
'2 bar',
|
||||
'1 baz'
|
||||
]
|
||||
},
|
||||
'choices': [
|
||||
'foo',
|
||||
'2 bar',
|
||||
|
@ -169,7 +175,26 @@ def test_weighted_choices():
|
|||
|
||||
choices_made = {}
|
||||
for _ in xrange(1000):
|
||||
choice = make_choice(graph['weighted_choices']['choices'], prng)
|
||||
choice = make_choice(graph['weighted_node']['choices'], prng)
|
||||
if choices_made.has_key(choice):
|
||||
choices_made[choice] += 1
|
||||
else:
|
||||
choices_made[choice] = 1
|
||||
|
||||
foo_percentage = choices_made['foo'] / 1000.0
|
||||
bar_percentage = choices_made['bar'] / 1000.0
|
||||
baz_percentage = choices_made['baz'] / 1000.0
|
||||
nose.tools.assert_almost_equal(foo_percentage, 0.25, 1)
|
||||
nose.tools.assert_almost_equal(bar_percentage, 0.50, 1)
|
||||
nose.tools.assert_almost_equal(baz_percentage, 0.25, 1)
|
||||
|
||||
def test_weighted_set():
|
||||
graph = build_graph()
|
||||
prng = random.Random(1)
|
||||
|
||||
choices_made = {}
|
||||
for _ in xrange(1000):
|
||||
choice = make_choice(graph['weighted_node']['set']['k1'], prng)
|
||||
if choices_made.has_key(choice):
|
||||
choices_made[choice] += 1
|
||||
else:
|
||||
|
|
|
@ -36,11 +36,13 @@ def descend_graph(decision_graph, node_name, prng):
|
|||
for key in node['set']:
|
||||
if decision.has_key(key):
|
||||
raise KeyError("Node %s tried to set '%s', but that key was already set by a lower node!" %(node_name, key))
|
||||
decision[key] = node['set'][key]
|
||||
decision[key] = make_choice(node['set'][key], prng)
|
||||
return decision
|
||||
|
||||
|
||||
def make_choice(choices, prng):
|
||||
if isinstance(choices, str):
|
||||
return choices
|
||||
weighted_choices = []
|
||||
for option in choices:
|
||||
fields = option.split(None, 1)
|
||||
|
|
Loading…
Reference in a new issue