]> git-server-git.apps.pok.os.sepia.ceph.com Git - s3-tests.git/commitdiff
S3 Fuzzer: set values can be weighted lists now
authorKyle Marsh <kyle.marsh@dreamhost.com>
Wed, 10 Aug 2011 22:10:24 +0000 (15:10 -0700)
committerKyle Marsh <kyle.marsh@dreamhost.com>
Mon, 12 Sep 2011 19:53:18 +0000 (12:53 -0700)
s3tests/functional/test_fuzzer.py
s3tests/fuzz_headers.py

index dabdbee86e7d7b81fa699c7006651d54e29637c0..f6fb3b53d5fdd96e8271c463a911d109d1500ce7 100644 (file)
@@ -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:
index 64245ec3940e658b9ad35e69c537fc6933ea074e..d01da8c6b746fd1496d20126f9a777682f28f575 100644 (file)
@@ -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)