Beispiel #1
0
 def test_scenario_collapse(self):
     """
     If the scenario collapses, a failure is returned.
     """
     samples_ready = benchmark(FakeScenario(fail(RuntimeError('collapse'))),
                               FakeOperation(repeat(True)),
                               FakeMetric(count(5)), 3)
     self.assertFailure(samples_ready, RuntimeError)
Beispiel #2
0
 def test_scenario_collapse(self):
     """
     If the scenario collapses, a failure is returned.
     """
     samples_ready = benchmark(
         FakeScenario(fail(RuntimeError('collapse'))),
         FakeOperation(repeat(True)),
         FakeMetric(count(5)),
         3)
     self.assertFailure(samples_ready, RuntimeError)
Beispiel #3
0
    def test_sample_count(self, _logger):
        """
        The sample count determines the number of samples.
        """
        samples_ready = benchmark(FakeScenario(), FakeOperation(repeat(True)),
                                  FakeMetric(count(5)), 5)

        def check(samples):
            self.assertEqual(len(samples), 5)

        samples_ready.addCallback(check)
        return samples_ready
Beispiel #4
0
    def test_sample_count(self, _logger):
        """
        The sample count determines the number of samples.
        """
        samples_ready = benchmark(
            FakeScenario(),
            FakeOperation(repeat(True)),
            FakeMetric(count(5)),
            5)

        def check(samples):
            self.assertEqual(len(samples), 5)
        samples_ready.addCallback(check)
        return samples_ready
Beispiel #5
0
    def test_good_probes(self, logger):
        """
        Sampling returns results when probes succeed.
        """
        samples_ready = benchmark(FakeScenario(), FakeOperation(repeat(True)),
                                  FakeMetric(count(5)), 3)

        def check(outputs):
            self.assertEqual(outputs, ([{
                'success': True,
                'value': x
            } for x in [5, 6, 7]], None))

        samples_ready.addCallback(check)
        return samples_ready
Beispiel #6
0
    def test_good_probes(self, logger):
        """
        Sampling returns results when probes succeed.
        """
        samples_ready = benchmark(
            FakeScenario(),
            FakeOperation(repeat(True)),
            FakeMetric(count(5)),
            3)

        def check(samples):
            self.assertEqual(
                samples, [{'success': True, 'value': x} for x in [5, 6, 7]])
        samples_ready.addCallback(check)
        return samples_ready
Beispiel #7
0
    def test_bad_probes(self, logger):
        """
        Sampling returns reasons when probes fail.
        """
        samples_ready = benchmark(FakeScenario(), FakeOperation(repeat(False)),
                                  FakeMetric(count(5)), 3)

        def check(outputs):
            # We don't care about the actual value for reason.
            for s in outputs[0]:
                if 'reason' in s:
                    s['reason'] = None
            self.assertEqual(outputs, ([{
                'success': False,
                'reason': None
            } for x in [5, 6, 7]], None))

        samples_ready.addCallback(check)
        return samples_ready
Beispiel #8
0
    def test_bad_probes(self, logger):
        """
        Sampling returns reasons when probes fail.
        """
        samples_ready = benchmark(
            FakeScenario(),
            FakeOperation(repeat(False)),
            FakeMetric(count(5)),
            3)

        def check(samples):
            # We don't care about the actual value for reason.
            for s in samples:
                if 'reason' in s:
                    s['reason'] = None
            self.assertEqual(
                samples,
                [{'success': False, 'reason': None} for x in [5, 6, 7]])
        samples_ready.addCallback(check)
        return samples_ready