|
3 | 3 | """ |
4 | 4 |
|
5 | 5 | import os |
| 6 | +import sys |
6 | 7 | import unittest |
7 | 8 | from awslambdaric.lambda_config import LambdaConfigProvider |
8 | 9 |
|
@@ -41,16 +42,45 @@ def test_concurrency_and_is_multi_concurrent(self): |
41 | 42 | self.assertIsNone(cfg2.max_concurrency) |
42 | 43 | self.assertFalse(cfg2.is_multi_concurrent) |
43 | 44 |
|
44 | | - def test_use_thread_polling_flag(self): |
| 45 | + def test_use_thread_polling_disabled_for_unsupported_managed_envs(self): |
| 46 | + # Managed runtimes on the denylist never use thread polling, |
| 47 | + # regardless of the Python version the code happens to run on. |
| 48 | + for exec_env in LambdaConfigProvider.UNSUPPORTED_THREADPOLLING_ENVS: |
| 49 | + env = { |
| 50 | + "AWS_LAMBDA_RUNTIME_API": "a", |
| 51 | + "AWS_EXECUTION_ENV": exec_env, |
| 52 | + } |
| 53 | + cfg = LambdaConfigProvider(["p", "h.fn"], environ=env) |
| 54 | + self.assertFalse( |
| 55 | + cfg.use_thread_polling, |
| 56 | + msg=f"expected thread polling disabled for {exec_env}", |
| 57 | + ) |
| 58 | + |
| 59 | + def test_use_thread_polling_enabled_for_custom_oci_image(self): |
| 60 | + # Custom OCI images (AWS_Lambda_Image) are not on the denylist and |
| 61 | + # fall back to the minimum-supported Python version check. |
| 62 | + env = { |
| 63 | + "AWS_LAMBDA_RUNTIME_API": "a", |
| 64 | + "AWS_EXECUTION_ENV": "AWS_Lambda_Image", |
| 65 | + } |
| 66 | + cfg = LambdaConfigProvider(["p", "h.fn"], environ=env) |
| 67 | + self.assertEqual(cfg.use_thread_polling, sys.version_info >= (3, 4)) |
| 68 | + |
| 69 | + def test_use_thread_polling_enabled_for_supported_managed_env(self): |
| 70 | + # Managed runtimes not on the denylist (e.g. newer versions) fall |
| 71 | + # back to the Python version check. |
45 | 72 | env = { |
46 | 73 | "AWS_LAMBDA_RUNTIME_API": "a", |
47 | 74 | "AWS_EXECUTION_ENV": "AWS_Lambda_python3.12", |
48 | 75 | } |
49 | 76 | cfg = LambdaConfigProvider(["p", "h.fn"], environ=env) |
50 | | - self.assertTrue(cfg.use_thread_polling) |
51 | | - env2 = {"AWS_LAMBDA_RUNTIME_API": "a", "AWS_EXECUTION_ENV": "OTHER"} |
52 | | - cfg2 = LambdaConfigProvider(["p", "h.fn"], environ=env2) |
53 | | - self.assertFalse(cfg2.use_thread_polling) |
| 77 | + self.assertEqual(cfg.use_thread_polling, sys.version_info >= (3, 4)) |
| 78 | + |
| 79 | + def test_use_thread_polling_without_execution_env(self): |
| 80 | + # With no AWS_EXECUTION_ENV set, fall back to the version check. |
| 81 | + env = {"AWS_LAMBDA_RUNTIME_API": "a"} |
| 82 | + cfg = LambdaConfigProvider(["p", "h.fn"], environ=env) |
| 83 | + self.assertEqual(cfg.use_thread_polling, sys.version_info >= (3, 4)) |
54 | 84 |
|
55 | 85 | def test_lmi_socket_path_property(self): |
56 | 86 | env = { |
|
0 commit comments