Beispiel #1
0
    def test_stopwatch_full_cancel(self):
        """Test that an entire span - from root to children, can be cancelled."""

        sw = StopWatch()

        sw.start('root')
        sw.start('child')
        sw.start('grand')
        sw.cancel('grand')
        sw.cancel('child')
        sw.cancel('root')

        assert not sw.get_last_aggregated_report()
        assert not sw._cancelled_spans

        sw = StopWatch()
        with sw.timer('root'):
            with sw.timer('child'):
                with sw.timer('grandchild'):
                    sw.cancel('grandchild')
                    sw.cancel('child')
                    sw.cancel('root')

        assert not sw.get_last_aggregated_report()
        assert not sw._cancelled_spans
Beispiel #2
0
 def test_stopwatch_cancel(self):
     """Test that spans can be correctly cancelled and not reported."""
     sw = StopWatch()
     sw.start('root')
     sw.start('child')
     sw.cancel('child')
     sw.end('root')
     agg_values = sw.get_last_aggregated_report().aggregated_values
     assert len(agg_values) == 1
     assert 'root' in agg_values
Beispiel #3
0
 def test_stopwatch_cancel_context_manager(self):
     """Test that spans can be cancelled while inside a span context."""
     sw = StopWatch()
     with sw.timer('root'):
         with sw.timer('child'):
             sw.cancel('child')
             with sw.timer('grand'):
                 pass
     agg_values = sw.get_last_aggregated_report().aggregated_values
     assert len(agg_values) == 2
     assert all([span in agg_values for span in ('root', 'root#grand')])
Beispiel #4
0
    def test_stopwatch_cancel_multiple_root_spans(self):
        """Test that spans can be cancelled inside a span context, with multiple
           of the same root span created. Ensure that they behave in an expected way.
        """

        sw = StopWatch()
        with sw.timer('root'):
            with sw.timer('child'):
                sw.cancel('child')
                pass

        with sw.timer('root'):
            with sw.timer('child'):
                pass

        agg_values = sw.get_last_aggregated_report().aggregated_values
        assert len(agg_values) == 2
        assert all([span in agg_values for span in ('root', 'root#child')])

        # Ensure that we are not leaking cancelled span data
        assert not sw._cancelled_spans