From 8caebf37ce78a41d374eb58be52e4e137ff1d92f Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Tue, 30 Jul 2024 11:01:53 -0700 Subject: [PATCH] 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 --- tests/otlp_fixture.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/otlp_fixture.py b/tests/otlp_fixture.py index 633296facd..944ff82040 100644 --- a/tests/otlp_fixture.py +++ b/tests/otlp_fixture.py @@ -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