|
23 | 23 | MAX_UINT_64BITS = (1 << 64) - 1 |
24 | 24 |
|
25 | 25 |
|
| 26 | +@pytest.mark.parametrize("sca_enabled", [False, True]) |
| 27 | +def test_sca_startup(sca_enabled, monkeypatch): |
| 28 | + product = MagicMock() |
| 29 | + monkeypatch.setattr("datadog_lambda.config.Config.sca_enabled", sca_enabled) |
| 30 | + monkeypatch.setitem(sys.modules, "ddtrace.internal.sca.product", product) |
| 31 | + |
| 32 | + importlib.reload(wrapper) |
| 33 | + |
| 34 | + assert product.mock_calls == ( |
| 35 | + [call.start(), call.post_preload()] if sca_enabled else [] |
| 36 | + ) |
| 37 | + |
| 38 | + |
| 39 | +def test_sca_startup_with_older_tracer(monkeypatch): |
| 40 | + monkeypatch.setattr("datadog_lambda.config.Config.sca_enabled", True) |
| 41 | + monkeypatch.setitem(sys.modules, "ddtrace.internal.sca.product", None) |
| 42 | + |
| 43 | + importlib.reload(wrapper) |
| 44 | + |
| 45 | + |
| 46 | +def test_sca_startup_failure_preserves_handler(monkeypatch): |
| 47 | + product = MagicMock() |
| 48 | + product.start.side_effect = RuntimeError("SCA startup failed") |
| 49 | + monkeypatch.setattr("datadog_lambda.config.Config.sca_enabled", True) |
| 50 | + monkeypatch.setitem(sys.modules, "ddtrace.internal.sca.product", product) |
| 51 | + |
| 52 | + importlib.reload(wrapper) |
| 53 | + |
| 54 | + product.post_preload.assert_not_called() |
| 55 | + assert callable(wrapper.datadog_lambda_wrapper) |
| 56 | + |
| 57 | + |
26 | 58 | class TestDatadogLambdaWrapper(unittest.TestCase): |
27 | 59 | def setUp(self): |
28 | 60 | # Force @datadog_lambda_wrapper to always create a real |
|
0 commit comments