|
12 | 12 |
|
13 | 13 |
|
14 | 14 | class TestColdStartTracingSetup(unittest.TestCase): |
| 15 | + def test_is_managed_instances_mode_when_set(self): |
| 16 | + os.environ["AWS_LAMBDA_INITIALIZATION_TYPE"] = "lambda-managed-instances" |
| 17 | + self.assertTrue(cold_start.is_managed_instances_mode()) |
| 18 | + # Clean up |
| 19 | + if "AWS_LAMBDA_INITIALIZATION_TYPE" in os.environ: |
| 20 | + del os.environ["AWS_LAMBDA_INITIALIZATION_TYPE"] |
| 21 | + |
| 22 | + def test_is_not_managed_instances_mode_when_not_set(self): |
| 23 | + if "AWS_LAMBDA_INITIALIZATION_TYPE" in os.environ: |
| 24 | + del os.environ["AWS_LAMBDA_INITIALIZATION_TYPE"] |
| 25 | + self.assertFalse(cold_start.is_managed_instances_mode()) |
| 26 | + |
| 27 | + def test_is_not_managed_instances_mode_with_different_value(self): |
| 28 | + os.environ["AWS_LAMBDA_INITIALIZATION_TYPE"] = "on-demand" |
| 29 | + self.assertFalse(cold_start.is_managed_instances_mode()) |
| 30 | + # Clean up |
| 31 | + if "AWS_LAMBDA_INITIALIZATION_TYPE" in os.environ: |
| 32 | + del os.environ["AWS_LAMBDA_INITIALIZATION_TYPE"] |
| 33 | + |
| 34 | + def test_initialize_cold_start_tracing_skips_in_managed_instances(self): |
| 35 | + # Set managed instances mode |
| 36 | + os.environ["AWS_LAMBDA_INITIALIZATION_TYPE"] = "lambda-managed-instances" |
| 37 | + os.environ["DD_COLD_START_TRACING"] = "true" |
| 38 | + cold_start._cold_start = True |
| 39 | + cold_start._lambda_container_initialized = False |
| 40 | + |
| 41 | + # Reset node stacks and wrapped loaders to get clean state |
| 42 | + cold_start.reset_node_stacks() |
| 43 | + cold_start.already_wrapped_loaders.clear() |
| 44 | + |
| 45 | + # Count wrapped loaders before |
| 46 | + wrapped_loaders_before = len(cold_start.already_wrapped_loaders) |
| 47 | + |
| 48 | + # Initialize cold start tracing - should skip in managed instances mode |
| 49 | + cold_start.initialize_cold_start_tracing() |
| 50 | + |
| 51 | + # Verify no loaders were wrapped |
| 52 | + wrapped_loaders_after = len(cold_start.already_wrapped_loaders) |
| 53 | + self.assertEqual(wrapped_loaders_before, wrapped_loaders_after) |
| 54 | + |
| 55 | + # Clean up |
| 56 | + if "AWS_LAMBDA_INITIALIZATION_TYPE" in os.environ: |
| 57 | + del os.environ["AWS_LAMBDA_INITIALIZATION_TYPE"] |
| 58 | + if "DD_COLD_START_TRACING" in os.environ: |
| 59 | + del os.environ["DD_COLD_START_TRACING"] |
| 60 | + |
15 | 61 | def test_proactive_init(self): |
16 | 62 | cold_start._cold_start = True |
17 | 63 | cold_start._proactive_initialization = False |
|
0 commit comments