Example #1
0
    def test_nonce(self):
        n1 = util.nonce()
        n2 = util.nonce()
        self.assertNotEqual(n1, n2)

        s = b''.join(util.nonce() for i in range(100))
        self.assertRandomish(s)
Example #2
0
    def test_nonce(self):
        n1 = util.nonce()
        n2 = util.nonce()
        self.assertNotEqual(n1, n2)

        s = b''.join(util.nonce() for i in range(100))
        self.assertRandomish(s)
Example #3
0
 def test_choose_population_bool(self):
     a = 0
     for ii in range(200):
         if util.choose_population(util.nonce()):
             a += 1
     # Make sure it's relatively uniform...
     self.assertRoughly(a, 100)
Example #4
0
def run_logger(log, num_requests=10000, goal_every=50, split_every=1):
    """
    Test the frontend performance by simulating a stream of requests.

    Tweak the following parameters:

    :param goal_every:
        Record a goal hit every ``goal_every`` requests.

    :param split_every:
        Record a split every ``split_every`` requests.
    """
    vid = nonce()
    req = Request.blank('/foo/bar')

    print("Logging %d requests." % num_requests)
    start = time()
    count = 0
    for ii in range(num_requests):
        count += 1
        vis = Visitor(vid, log)
        vis.page(req)
        if split_every and (ii % split_every) == 0:
            count += 1
            vis.split('fake test')
        if goal_every and (ii % goal_every) == 0:
            count += 1
            vis.goal('fake goal')
    end = time()
    elapsed = end - start
    throughput = num_requests / elapsed
    print("Handled %0.2f req / sec" % throughput)
Example #5
0
 def test_choose_population_bool(self):
     a = 0
     for ii in range(200):
         if util.choose_population(util.nonce()):
             a += 1
     # Make sure it's relatively uniform...
     self.assertRoughly(a, 100)
Example #6
0
 def test_choose_population_list(self):
     counts = defaultdict(int)
     for ii in range(300):
         choice = util.choose_population(util.nonce(),
                                         ['foo', 'bar', 'baz'])
         counts[choice] += 1
     self.assertRoughly(counts['foo'], 100)
     self.assertRoughly(counts['bar'], 100)
     self.assertRoughly(counts['baz'], 100)
Example #7
0
 def test_choose_population_list(self):
     counts = defaultdict(int)
     for ii in range(300):
         choice = util.choose_population(util.nonce(),
                                         ['foo', 'bar', 'baz'])
         counts[choice] += 1
     self.assertRoughly(counts['foo'], 100)
     self.assertRoughly(counts['bar'], 100)
     self.assertRoughly(counts['baz'], 100)
Example #8
0
 def test_choose_population_weighted(self):
     counts = defaultdict(int)
     for ii in range(300):
         choice = util.choose_population(util.nonce(), {'foo': 0.1,
                                                        'quux': 0,
                                                        'bar': 0.1,
                                                        'baz': 0.8})
         counts[choice] += 1
     self.assertRoughly(counts['foo'], 30)
     self.assertRoughly(counts['bar'], 30)
     self.assertRoughly(counts['baz'], 240)
     self.assertEqual(counts['quux'], 0)
Example #9
0
 def test_choose_population_weighted(self):
     counts = defaultdict(int)
     for ii in range(300):
         choice = util.choose_population(util.nonce(), {
             'foo': 0.1,
             'quux': 0,
             'bar': 0.1,
             'baz': 0.8
         })
         counts[choice] += 1
     self.assertRoughly(counts['foo'], 30)
     self.assertRoughly(counts['bar'], 30)
     self.assertRoughly(counts['baz'], 240)
     self.assertEqual(counts['quux'], 0)
Example #10
0
 def setUp(self):
     self.sample = util.nonce()
Example #11
0
 def test_choose_population_zero_mass(self):
     with self.assertRaises(ValueError):
         util.choose_population(util.nonce(), {'foo': 0})
Example #12
0
 def test_chose_population_bad_value(self):
     with self.assertRaises(ValueError):
         util.choose_population(util.nonce(), 123)
Example #13
0
 def setUp(self):
     self.sample = util.nonce()
Example #14
0
 def test_choose_population_zero_mass(self):
     with self.assertRaises(ValueError):
         util.choose_population(util.nonce(), {'foo': 0})
Example #15
0
 def test_chose_population_bad_value(self):
     with self.assertRaises(ValueError):
         util.choose_population(util.nonce(), 123)