Commit 2821290
committed
fix(test): stop telemetry bootstrap tests blocking on real OTel exporter under py3.14
Tests in TestConfigureTelemetryIdempotency and related classes were hanging
~277 s each on Python 3.14 (just under the 300 s pytest --timeout), causing
the CI unit leg to take ~40 min instead of 7-19 min.
Root cause: the _reset_otel_globals autouse fixture captured the current
global MeterProvider (which is _PROXY_METER_PROVIDER, the OTel process-wide
proxy singleton) and attempted to "restore" it in teardown by calling
set_meter_provider(_PROXY_METER_PROVIDER). OTel's set_meter_provider is
intentionally a one-shot operation guarded by a Once object. When no real
provider had yet been installed (because the test mocked set_meter_provider
at the opentelemetry.metrics namespace), the Once gate had not yet fired, so
the teardown call fired it for the first time with the proxy as its own
argument. This triggered:
_PROXY_METER_PROVIDER.on_set_meter_provider(_PROXY_METER_PROVIDER)
→ acquires _PROXY_METER_PROVIDER._lock
→ iterates proxy meters, calls meter.on_set_meter_provider(proxy)
→ _ProxyMeter.on_set_meter_provider calls proxy.get_meter()
→ _PROXY_METER_PROVIDER.get_meter() tries to acquire _PROXY_METER_PROVIDER._lock
→ deadlock (non-reentrant Lock, blocks forever)
On Python 3.12 this was order-dependent: if TestConfigureTelemetryEnabled ran
first, its teardown fired the Once gate harmlessly, making all later teardowns
no-ops. On Python 3.14, CI runs these test classes in isolation (per-class or
per-file grouping changed by bumping python.default_version 3.12→3.14), so the
gate fires in teardown of the very first test that mocked set_meter_provider,
hitting the deadlock deterministically every time.
Fix: remove the restore logic from _reset_otel_globals entirely. OTel's
global meter provider is a process-wide Once-guarded singleton; it is not
designed to be reset between tests. The module-level _state object
(_reset_telemetry_state) is the correct isolation boundary for unit tests
of idempotency/flag logic. Tests that need to intercept set_meter_provider
already mock it at the call site (which they do).1 parent 0c66fb7 commit 2821290
1 file changed
Lines changed: 17 additions & 16 deletions
Lines changed: 17 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
63 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
64 | 79 | | |
65 | 80 | | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | 81 | | |
74 | 82 | | |
75 | 83 | | |
76 | 84 | | |
77 | 85 | | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
| |||
0 commit comments