def setUp(self):
     self.api = DummmyAPI()
     self.traces = Q()
     self.services = Q()
     for i in range(N_TRACES):
         self.traces.put([
             Span(tracer=None, name='name', trace_id=i, span_id=j, parent_id=j - 1 or None)
             for j in range(7)
         ])
def test_queue_get():
    q = Q(maxsize=3)
    q.put(1)
    q.put(2)
    assert list(q.get()) == [1, 2]
    with pytest.raises(Empty):
        q.get(block=False)
def test_queue_full():
    q = Q(maxsize=3)
    q.put(1)
    q.put(2)
    q.put(3)
    q.put(4)
    assert (list(q.queue) == [1, 2, 4] or
            list(q.queue) == [1, 4, 3] or
            list(q.queue) == [4, 2, 3])
Пример #4
0
 def test_trace_buffer_without_cap(self):
     # the trace buffer must have unlimited size if users choose that
     trace_buff = Q(max_size=0)
     span_1 = Span(tracer=None, name='client.testing')
     span_2 = Span(tracer=None, name='client.testing')
     trace_buff.add(span_1)
     trace_buff.add(span_2)
     eq_(len(trace_buff._things), 2)
     ok_(span_1 in trace_buff._things)
     ok_(span_2 in trace_buff._things)
Пример #5
0
    def test_trace_buffer_closed(self):
        # the trace buffer must not add new elements if the buffer is closed
        trace_buff = Q()
        trace_buff.close()
        span = Span(tracer=None, name='client.testing')
        result = trace_buff.add(span)

        # the item must not be added and the result should be False
        eq_(len(trace_buff._things), 0)
        eq_(result, False)
Пример #6
0
 def test_trace_buffer_limit(self):
     # the trace buffer must have a limit, if the limit is reached a
     # trace must be discarded
     trace_buff = Q(max_size=1)
     span_1 = Span(tracer=None, name='client.testing')
     span_2 = Span(tracer=None, name='client.testing')
     trace_buff.add(span_1)
     trace_buff.add(span_2)
     eq_(len(trace_buff._things), 1)
     eq_(trace_buff._things[0], span_2)
Пример #7
0
    def test_q_statements(self):
        # test returned Q statements
        q = Q(3)
        assert q.add(1)
        assert q.add(2)
        assert q.add(3)
        assert q.size() == 3
        assert not q.add(4)
        assert q.size() == 3

        assert len(q.pop()) == 3
        assert q.size() == 0
Пример #8
0
    def test_trace_buffer_pop(self):
        # the trace buffer must return all internal traces
        trace_buff = Q()
        span_1 = Span(tracer=None, name='client.testing')
        span_2 = Span(tracer=None, name='client.testing')
        trace_buff.add(span_1)
        trace_buff.add(span_2)
        eq_(len(trace_buff._things), 2)

        # get the traces and be sure that the queue is empty
        traces = trace_buff.pop()
        eq_(len(trace_buff._things), 0)
        eq_(len(traces), 2)
        ok_(span_1 in traces)
        ok_(span_2 in traces)
Пример #9
0
 def test_trace_buffer_empty_pop(self):
     # the trace buffer must return None if it's empty
     trace_buff = Q()
     traces = trace_buff.pop()
     eq_(traces, None)