Skip to content

Commit 05a27c0

Browse files
test: Reduce FIPS import timeout flakes and capture diagnostics
Signed-off-by: Francisco Javier Arceo <[email protected]>
1 parent b7a8928 commit 05a27c0

1 file changed

Lines changed: 25 additions & 9 deletions

File tree

‎sdk/python/tests/unit/test_offline_server.py‎

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from unittest.mock import MagicMock, mock_open, patch
66

77
import assertpy
8+
import pytest
89

910
from feast.infra.offline_stores.remote import (
1011
RemoteOfflineStore,
@@ -142,15 +143,18 @@ def test_configure_grpc_fips_noop_without_fips():
142143
assert "GRPC_SSL_CIPHER_SUITES" not in os.environ
143144

144145

145-
def test_module_level_fips_sets_env_before_pyarrow_import():
146+
def test_module_level_fips_sets_env_before_pyarrow_import() -> None:
146147
"""GRPC_SSL_CIPHER_SUITES must be set at module load time,
147148
before pyarrow.flight (which bundles gRPC) is imported.
148149
149150
Uses a subprocess so pyarrow.flight is not already cached in
150151
sys.modules, which lets us verify the true import ordering.
151152
"""
152153
script = textwrap.dedent("""\
153-
import io, os, sys
154+
import faulthandler, io, os, sys
155+
156+
# Capture a stalled import before the parent terminates this process.
157+
faulthandler.dump_traceback_later(120)
154158
155159
# Intercept only /proc/sys/crypto/fips_enabled to simulate FIPS
156160
_real_open = open
@@ -177,18 +181,30 @@ def tracking_import(name, *args, **kwargs):
177181
assert "GRPC_SSL_CIPHER_SUITES" in os.environ
178182
assert "AES128-GCM-SHA256" in os.environ["GRPC_SSL_CIPHER_SUITES"]
179183
finally:
184+
faulthandler.cancel_dump_traceback_later()
180185
builtins.__import__ = original_import
181186
builtins.open = _real_open
182187
""")
183188
env = os.environ.copy()
184189
env.pop("GRPC_SSL_CIPHER_SUITES", None)
185-
result = subprocess.run(
186-
[sys.executable, "-c", script],
187-
capture_output=True,
188-
text=True,
189-
env=env,
190-
timeout=60,
191-
)
190+
try:
191+
result = subprocess.run(
192+
[sys.executable, "-c", script],
193+
capture_output=True,
194+
text=True,
195+
env=env,
196+
# Cold imports can be slow on macOS under parallel test load.
197+
timeout=180,
198+
)
199+
except subprocess.TimeoutExpired as exc:
200+
# TimeoutExpired captures bytes even when subprocess.run uses text=True.
201+
stdout = (exc.stdout or b"").decode(errors="replace")
202+
stderr = (exc.stderr or b"").decode(errors="replace")
203+
pytest.fail(
204+
f"Subprocess timed out after {exc.timeout}s:\n"
205+
f"stdout: {stdout}\nstderr: {stderr}",
206+
pytrace=False,
207+
)
192208
assert result.returncode == 0, (
193209
f"Subprocess failed:\nstdout: {result.stdout}\nstderr: {result.stderr}"
194210
)

0 commit comments

Comments
 (0)