From: Kyle Marsh Date: Wed, 10 Aug 2011 22:10:24 +0000 (-0700) Subject: S3 Fuzzer: set values can be weighted lists now X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3f1314f7c816be193b1bf53c419334e1552220b2;p=s3-tests.git S3 Fuzzer: set values can be weighted lists now --- diff --git a/s3tests/functional/test_fuzzer.py b/s3tests/functional/test_fuzzer.py index dabdbee8..f6fb3b53 100644 --- a/s3tests/functional/test_fuzzer.py +++ b/s3tests/functional/test_fuzzer.py @@ -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: diff --git a/s3tests/fuzz_headers.py b/s3tests/fuzz_headers.py index 64245ec3..d01da8c6 100644 --- a/s3tests/fuzz_headers.py +++ b/s3tests/fuzz_headers.py @@ -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)