Improve tracing test isolation

We never ran the cleanup method for the OTLP fake server, which
means we never shut it down properly.  This would leak threadpool
executor threads.

We also need to reset the tracing configuration at the end of tests,
otherwise subsequent tests will end up using the tracing provider
from the previous test.  This is because we currently only run
the reset at the start of a test that using tracing; so new tests
that startup without using tracing won't run the provider reset.

This change corrects both issues, which should mean that the tracing
configuration is isolated to the currently running test.

Change-Id: Ib1edf51ad8ef3550b16dc888883f86a96bfb2dc2
This commit is contained in:
James E. Blair 2024-07-30 11:01:53 -07:00
parent c4a590df59
commit 8caebf37ce

View File

@ -51,8 +51,12 @@ class OTLPFixture(fixtures.Fixture):
def _setUp(self):
self.server.start()
self.addCleanup(self._cleanup)
def _cleanup(self):
self.server.stop()
self.server.stop(None)
self.server.wait_for_termination()
self.executor.shutdown()
# Reset global tracer provider
trace._TRACER_PROVIDER_SET_ONCE = trace.Once()
trace._TRACER_PROVIDER = None