Ejemplo n.º 1
0
    def test_set_context(self):
        # the Context can be set in the current Thread
        ctx = Context()
        local = ThreadLocalContext()
        ok_(local.get() is not ctx)

        local.set(ctx)
        ok_(local.get() is ctx)
Ejemplo n.º 2
0
    def test_set_context(self):
        # the Context can be set in the current Thread
        ctx = Context()
        local = ThreadLocalContext()
        assert local.get() is not ctx

        local.set(ctx)
        assert local.get() is ctx
Ejemplo n.º 3
0
    def test_multiple_threads_multiple_context(self):
        # each thread should have it's own Context
        l_ctx = ThreadLocalContext()

        def _fill_ctx():
            ctx = l_ctx.get()
            span = Span(tracer=None, name='fake_span')
            ctx.add_span(span)
            assert 1 == len(ctx._trace)

        threads = [threading.Thread(target=_fill_ctx) for _ in range(100)]

        for t in threads:
            t.daemon = True
            t.start()

        for t in threads:
            t.join()

        # the main instance should have an empty Context
        # because it has not been used in this thread
        ctx = l_ctx.get()
        assert 0 == len(ctx._trace)
Ejemplo n.º 4
0
    def test_multiple_threads_multiple_context(self):
        # each thread should have it's own Context
        l_ctx = ThreadLocalContext()

        def _fill_ctx():
            ctx = l_ctx.get()
            span = Span(tracer=None, name='fake_span')
            ctx.add_span(span)
            eq_(1, len(ctx._trace))

        threads = [threading.Thread(target=_fill_ctx) for _ in range(100)]

        for t in threads:
            t.daemon = True
            t.start()

        for t in threads:
            t.join()

        # the main instance should have an empty Context
        # because it has not been used in this thread
        ctx = l_ctx.get()
        eq_(0, len(ctx._trace))
Ejemplo n.º 5
0
 def test_get_or_create(self):
     # asking the Context multiple times should return
     # always the same instance
     l_ctx = ThreadLocalContext()
     assert l_ctx.get() == l_ctx.get()
Ejemplo n.º 6
0
 def test_get_or_create(self):
     # asking the Context multiple times should return
     # always the same instance
     l_ctx = ThreadLocalContext()
     eq_(l_ctx.get(), l_ctx.get())