コード例 #1
0
ファイル: test_tracers.py プロジェクト: jaredlwong/tryfer
 def setUp(self):
     self.mock_tracer = mock.Mock()
     self.clock = Clock()
     self.tracer = BufferingTracer(
         self.mock_tracer,
         _reactor=self.clock,
         max_traces=5)
コード例 #2
0
ファイル: test_tracers.py プロジェクト: jaredlwong/tryfer
 def test_default_reactor(self, mock_reactor):
     tracer = BufferingTracer(mock.Mock())
     tracer.record([(mock.Mock(), [mock.Mock()])])
     self.assertEqual(mock_reactor.callLater.call_count, 1)
コード例 #3
0
ファイル: test_tracers.py プロジェクト: jaredlwong/tryfer
class BufferingTracerTests(TestCase):
    def setUp(self):
        self.mock_tracer = mock.Mock()
        self.clock = Clock()
        self.tracer = BufferingTracer(
            self.mock_tracer,
            _reactor=self.clock,
            max_traces=5)

    def test_verifyObject(self):
        verifyObject(ITracer, self.tracer)

    def test_buffers_traces(self):
        self.tracer.record([(mock.Mock(), [mock.Mock()])])

        self.assertEqual(self.mock_tracer.record.call_count, 0)

    def test_flushes_buffer_on_max_traces(self):
        mockTrace = mock.Mock()
        mockAnnotation = mock.Mock()

        traces = [(mockTrace, [mockAnnotation]) for x in xrange(5)]

        self.tracer.record(traces)

        self.clock.advance(1)

        self.mock_tracer.record.assert_called_once_with(traces)

    def test_flushes_buffer_on_max_idle_time(self):
        mockTrace = mock.Mock()
        mockAnnotation = mock.Mock()

        traces = [(mockTrace, [mockAnnotation])]

        self.tracer.record(traces)

        self.clock.advance(10)

        self.mock_tracer.record.assert_called_once_with(traces)

    def test_new_traces_extend_idle_time(self):
        mockTrace = mock.Mock()
        mockAnnotation = mock.Mock()

        traces = [(mockTrace, [mockAnnotation])]

        # Record one trace and advance the clock by 9 seconds.
        self.tracer.record(traces)

        self.clock.advance(9)

        # We have not reached the idle time so nothing has been traced
        self.assertEqual(self.mock_tracer.record.call_count, 0)

        # Record a new trace which should reset the idle time.
        self.tracer.record(traces)

        # Advance the clock by 5 seconds.  We have now exceeded 10 seconds
        # since the original trace but we should not flush the buffer.
        self.clock.advance(5)

        self.assertEqual(self.mock_tracer.record.call_count, 0)

        # Advance the clock another 5 seconds.  And assert that both recorded
        # traces have been flushed from the buffer.
        self.clock.advance(5)

        self.mock_tracer.record.assert_called_once_with(traces + traces)

    @mock.patch('tryfer.tracers.reactor')
    def test_default_reactor(self, mock_reactor):
        tracer = BufferingTracer(mock.Mock())
        tracer.record([(mock.Mock(), [mock.Mock()])])
        self.assertEqual(mock_reactor.callLater.call_count, 1)

    def test_timer_reset_after_flush(self):
        trace = (mock.Mock(), [mock.Mock()])

        self.tracer.record([trace for x in xrange(5)])
        self.clock.advance(1)
        self.tracer.record([trace])
        self.clock.advance(1)

        self.mock_tracer.record.assert_called_once_with(
            [trace for x in xrange(5)])

    def test_complete_buffer_flushed(self):
        trace = (mock.Mock(), [mock.Mock()])
        self.tracer.record([trace for x in xrange(5)])
        self.tracer.record([trace for x in xrange(3)])

        self.clock.advance(1)

        self.mock_tracer.record.assert_called_once_with(
            [trace for x in xrange(8)])
コード例 #4
0
ファイル: test_tracers.py プロジェクト: bbotte/tryfer-zipkin
 def test_default_reactor(self, mock_reactor):
     tracer = BufferingTracer(mock.Mock())
     tracer.record([(mock.Mock(), [mock.Mock()])])
     self.assertEqual(mock_reactor.callLater.call_count, 1)
コード例 #5
0
ファイル: test_tracers.py プロジェクト: bbotte/tryfer-zipkin
 def setUp(self):
     self.mock_tracer = mock.Mock()
     self.clock = Clock()
     self.tracer = BufferingTracer(self.mock_tracer,
                                   _reactor=self.clock,
                                   max_traces=5)
コード例 #6
0
ファイル: test_tracers.py プロジェクト: bbotte/tryfer-zipkin
class BufferingTracerTests(TestCase):
    def setUp(self):
        self.mock_tracer = mock.Mock()
        self.clock = Clock()
        self.tracer = BufferingTracer(self.mock_tracer,
                                      _reactor=self.clock,
                                      max_traces=5)

    def test_verifyObject(self):
        verifyObject(ITracer, self.tracer)

    def test_buffers_traces(self):
        self.tracer.record([(mock.Mock(), [mock.Mock()])])

        self.assertEqual(self.mock_tracer.record.call_count, 0)

    def test_flushes_buffer_on_max_traces(self):
        mockTrace = mock.Mock()
        mockAnnotation = mock.Mock()

        traces = [(mockTrace, [mockAnnotation]) for x in xrange(5)]

        self.tracer.record(traces)

        self.clock.advance(1)

        self.mock_tracer.record.assert_called_once_with(traces)

    def test_flushes_buffer_on_max_idle_time(self):
        mockTrace = mock.Mock()
        mockAnnotation = mock.Mock()

        traces = [(mockTrace, [mockAnnotation])]

        self.tracer.record(traces)

        self.clock.advance(10)

        self.mock_tracer.record.assert_called_once_with(traces)

    def test_new_traces_extend_idle_time(self):
        mockTrace = mock.Mock()
        mockAnnotation = mock.Mock()

        traces = [(mockTrace, [mockAnnotation])]

        # Record one trace and advance the clock by 9 seconds.
        self.tracer.record(traces)

        self.clock.advance(9)

        # We have not reached the idle time so nothing has been traced
        self.assertEqual(self.mock_tracer.record.call_count, 0)

        # Record a new trace which should reset the idle time.
        self.tracer.record(traces)

        # Advance the clock by 5 seconds.  We have now exceeded 10 seconds
        # since the original trace but we should not flush the buffer.
        self.clock.advance(5)

        self.assertEqual(self.mock_tracer.record.call_count, 0)

        # Advance the clock another 5 seconds.  And assert that both recorded
        # traces have been flushed from the buffer.
        self.clock.advance(5)

        self.mock_tracer.record.assert_called_once_with(traces + traces)

    @mock.patch('tryfer.tracers.reactor')
    def test_default_reactor(self, mock_reactor):
        tracer = BufferingTracer(mock.Mock())
        tracer.record([(mock.Mock(), [mock.Mock()])])
        self.assertEqual(mock_reactor.callLater.call_count, 1)

    def test_timer_reset_after_flush(self):
        trace = (mock.Mock(), [mock.Mock()])

        self.tracer.record([trace for x in xrange(5)])
        self.clock.advance(1)
        self.tracer.record([trace])
        self.clock.advance(1)

        self.mock_tracer.record.assert_called_once_with(
            [trace for x in xrange(5)])

    def test_complete_buffer_flushed(self):
        trace = (mock.Mock(), [mock.Mock()])
        self.tracer.record([trace for x in xrange(5)])
        self.tracer.record([trace for x in xrange(3)])

        self.clock.advance(1)

        self.mock_tracer.record.assert_called_once_with(
            [trace for x in xrange(8)])