コード例 #1
0
ファイル: test_stopwatch.py プロジェクト: rjain11/stopwatch
    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
コード例 #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
コード例 #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')])
コード例 #4
0
ファイル: test_stopwatch.py プロジェクト: rjain11/stopwatch
    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