Example #1
0
    def test_context_worker_thread_main_acquire(self):
        store = aws.XrayContext()
        x = Segment('foo')
        a = Subsegment('bar', 'boo', x)
        store.put_segment(x)
        store.put_subsegment(a)

        def get_ident():
            return 42

        self.patch(threading, 'get_ident', get_ident)
        self.assertEqual(store.get_trace_entity(), a)
Example #2
0
    def test_context(self):
        store = aws.XrayContext()
        self.assertEqual(store.handle_context_missing(), None)
        x = Segment('foo')
        y = Segment('foo')
        a = Subsegment('bar', 'boo', x)
        b = Subsegment('bar', 'boo', x)
        b.thread_id = '123'
        store.put_segment(x)
        store.put_subsegment(a)
        store.put_subsegment(b)

        self.assertEqual(store._local.entities, [x, a, b])
        self.assertEqual(store.get_trace_entity(), a)
        store.end_subsegment(a)
        self.assertEqual(store.get_trace_entity(), x)
        store.put_segment(y)
        self.assertEqual(store._local.entities, [y])
        self.assertEqual(store.get_trace_entity(), y)
        self.assertFalse(store.end_subsegment(42))