|
| 1 | +From 450b09950bd41f428e1594560a7c70988d94b138 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Ludovic Henry <git@ludovic.dev> |
| 3 | +Date: Fri, 18 Sep 2026 06:44:38 +0000 |
| 4 | +Subject: [PATCH] test: detect_platforms: raise the generous timeout from 1s to |
| 5 | + 30s |
| 6 | + |
| 7 | +detect_platforms() runs its six probes in a ThreadPoolExecutor and labels |
| 8 | +any that miss platform_detection_timeout_seconds with a "<name>_timeout" |
| 9 | +suffix. The tests that want no timeout label at all pass 1 second, with an |
| 10 | +inline comment saying the value is only there "to make sure no Thread-based |
| 11 | +timeout messes the results". |
| 12 | + |
| 13 | +On the riscv64 runners 1 second is not generous enough: has_aws_identity |
| 14 | +builds a boto3 STS client, and botocore's first service-model load, running |
| 15 | +alongside three other pytest-xdist workers, overshoots the budget. The |
| 16 | +future is then cancelled and test_no_platforms_detected sees |
| 17 | +['has_aws_identity_timeout'] instead of []. The four "not true" cases of |
| 18 | +test_platform_detection_disable_env_var_values assert the same empty list |
| 19 | +and are exposed the same way. |
| 20 | + |
| 21 | +csp_helpers patches urllib3's HTTPConnection.request to raise ConnectTimeout |
| 22 | +outright, so no probe ever waits on the network and a larger ceiling adds no |
| 23 | +wall-clock time anywhere. Sites that deliberately exercise the timeout path |
| 24 | +(None, 0, EXPECTED_MAX_TIMEOUT_FOR_PLATFORM_DETECTION) are left alone. |
| 25 | + |
| 26 | +Upstream-Status: Inappropriate [native runner specific] |
| 27 | +--- |
| 28 | + test/unit/test_detect_platforms.py | 36 +++++++++++++++--------------- |
| 29 | + 1 file changed, 18 insertions(+), 18 deletions(-) |
| 30 | + |
| 31 | +diff --git a/test/unit/test_detect_platforms.py b/test/unit/test_detect_platforms.py |
| 32 | +index b9b2d4f4..66a35420 100644 |
| 33 | +--- a/test/unit/test_detect_platforms.py |
| 34 | ++++ b/test/unit/test_detect_platforms.py |
| 35 | +@@ -69,14 +69,14 @@ class TestDetectPlatforms: |
| 36 | + self, unavailable_metadata_service_with_request_exception |
| 37 | + ): |
| 38 | + result = detect_platforms( |
| 39 | +- platform_detection_timeout_seconds=1 |
| 40 | ++ platform_detection_timeout_seconds=30 |
| 41 | + ) # increase timeout to make sure no Thread-based timeout messes the results |
| 42 | + assert result == [] |
| 43 | + |
| 44 | + def test_ec2_instance_detection( |
| 45 | + self, unavailable_metadata_service_with_request_exception, fake_aws_environment |
| 46 | + ): |
| 47 | +- result = detect_platforms(platform_detection_timeout_seconds=1) |
| 48 | ++ result = detect_platforms(platform_detection_timeout_seconds=30) |
| 49 | + assert "is_ec2_instance" in result |
| 50 | + |
| 51 | + def test_aws_lambda_detection( |
| 52 | +@@ -84,7 +84,7 @@ class TestDetectPlatforms: |
| 53 | + unavailable_metadata_service_with_request_exception, |
| 54 | + fake_aws_lambda_environment, |
| 55 | + ): |
| 56 | +- result = detect_platforms(platform_detection_timeout_seconds=1) |
| 57 | ++ result = detect_platforms(platform_detection_timeout_seconds=30) |
| 58 | + assert "is_aws_lambda" in result |
| 59 | + |
| 60 | + @pytest.mark.parametrize( |
| 61 | +@@ -104,44 +104,44 @@ class TestDetectPlatforms: |
| 62 | + fake_aws_environment, |
| 63 | + arn, |
| 64 | + ): |
| 65 | +- result = detect_platforms(platform_detection_timeout_seconds=1) |
| 66 | ++ result = detect_platforms(platform_detection_timeout_seconds=30) |
| 67 | + assert "has_aws_identity" in result |
| 68 | + |
| 69 | + def test_azure_vm_detection(self, fake_azure_vm_metadata_service): |
| 70 | +- result = detect_platforms(platform_detection_timeout_seconds=1) |
| 71 | ++ result = detect_platforms(platform_detection_timeout_seconds=30) |
| 72 | + assert "is_azure_vm" in result |
| 73 | + |
| 74 | + def test_azure_function_detection(self, fake_azure_function_metadata_service): |
| 75 | +- result = detect_platforms(platform_detection_timeout_seconds=1) |
| 76 | ++ result = detect_platforms(platform_detection_timeout_seconds=30) |
| 77 | + assert "is_azure_function" in result |
| 78 | + |
| 79 | + def test_azure_function_with_managed_identity( |
| 80 | + self, fake_azure_function_metadata_service |
| 81 | + ): |
| 82 | +- result = detect_platforms(platform_detection_timeout_seconds=1) |
| 83 | ++ result = detect_platforms(platform_detection_timeout_seconds=30) |
| 84 | + assert "is_azure_function" in result |
| 85 | + assert "has_azure_managed_identity" in result |
| 86 | + |
| 87 | + def test_gce_vm_detection(self, fake_gce_metadata_service): |
| 88 | +- result = detect_platforms(platform_detection_timeout_seconds=1) |
| 89 | ++ result = detect_platforms(platform_detection_timeout_seconds=30) |
| 90 | + assert "is_gce_vm" in result |
| 91 | + |
| 92 | + def test_gce_cloud_run_service_detection( |
| 93 | + self, fake_gce_cloud_run_service_metadata_service |
| 94 | + ): |
| 95 | +- result = detect_platforms(platform_detection_timeout_seconds=1) |
| 96 | ++ result = detect_platforms(platform_detection_timeout_seconds=30) |
| 97 | + assert "is_gce_cloud_run_service" in result |
| 98 | + |
| 99 | + def test_gce_cloud_run_job_detection(self, fake_gce_cloud_run_job_metadata_service): |
| 100 | +- result = detect_platforms(platform_detection_timeout_seconds=1) |
| 101 | ++ result = detect_platforms(platform_detection_timeout_seconds=30) |
| 102 | + assert "is_gce_cloud_run_job" in result |
| 103 | + |
| 104 | + def test_gcp_identity_detection(self, fake_gce_metadata_service): |
| 105 | +- result = detect_platforms(platform_detection_timeout_seconds=1) |
| 106 | ++ result = detect_platforms(platform_detection_timeout_seconds=30) |
| 107 | + assert "has_gcp_identity" in result |
| 108 | + |
| 109 | + def test_github_actions_detection(self, fake_github_actions_metadata_service): |
| 110 | +- result = detect_platforms(platform_detection_timeout_seconds=1) |
| 111 | ++ result = detect_platforms(platform_detection_timeout_seconds=30) |
| 112 | + assert "is_github_action" in result |
| 113 | + |
| 114 | + def test_multiple_platforms_detection( |
| 115 | +@@ -150,7 +150,7 @@ class TestDetectPlatforms: |
| 116 | + fake_github_actions_metadata_service, |
| 117 | + fake_gce_cloud_run_service_metadata_service, |
| 118 | + ): |
| 119 | +- result = detect_platforms(platform_detection_timeout_seconds=1) |
| 120 | ++ result = detect_platforms(platform_detection_timeout_seconds=30) |
| 121 | + assert "is_aws_lambda" in result |
| 122 | + assert "has_aws_identity" in result |
| 123 | + assert "is_github_action" in result |
| 124 | +@@ -267,14 +267,14 @@ class TestDetectPlatforms: |
| 125 | + arn, |
| 126 | + ): |
| 127 | + fake_aws_environment.caller_identity = {"Arn": arn} |
| 128 | +- result = detect_platforms(platform_detection_timeout_seconds=1) |
| 129 | ++ result = detect_platforms(platform_detection_timeout_seconds=30) |
| 130 | + assert "has_aws_identity" not in result |
| 131 | + |
| 132 | + def test_missing_arn_handling( |
| 133 | + self, unavailable_metadata_service_with_request_exception, fake_aws_environment |
| 134 | + ): |
| 135 | + fake_aws_environment.caller_identity = {"UserId": "test-user"} |
| 136 | +- result = detect_platforms(platform_detection_timeout_seconds=1) |
| 137 | ++ result = detect_platforms(platform_detection_timeout_seconds=30) |
| 138 | + assert "has_aws_identity" not in result |
| 139 | + |
| 140 | + def test_azure_managed_identity_no_token_endpoint( |
| 141 | +@@ -294,7 +294,7 @@ class TestDetectPlatforms: |
| 142 | + self, unavailable_metadata_service_with_request_exception, fake_aws_environment |
| 143 | + ): |
| 144 | + fake_aws_environment.instance_document = b"" |
| 145 | +- result = detect_platforms(platform_detection_timeout_seconds=1) |
| 146 | ++ result = detect_platforms(platform_detection_timeout_seconds=30) |
| 147 | + assert "is_ec2_instance" not in result |
| 148 | + |
| 149 | + def test_aws_lambda_empty_task_root( |
| 150 | +@@ -373,7 +373,7 @@ class TestDetectPlatforms: |
| 151 | + ): |
| 152 | + """Test that ENV_VAR_DISABLE_PLATFORM_DETECTION only disables when set to 'true' (case-insensitive)""" |
| 153 | + with patch.dict(os.environ, {ENV_VAR_DISABLE_PLATFORM_DETECTION: env_value}): |
| 154 | +- result = detect_platforms(platform_detection_timeout_seconds=1) |
| 155 | ++ result = detect_platforms(platform_detection_timeout_seconds=30) |
| 156 | + assert result == expected_result |
| 157 | + |
| 158 | + def test_platform_detection_disabled_overrides_all_other_detection( |
| 159 | +@@ -384,7 +384,7 @@ class TestDetectPlatforms: |
| 160 | + ): |
| 161 | + """Test that ENV_VAR_DISABLE_PLATFORM_DETECTION takes precedence over all detections""" |
| 162 | + with patch.dict(os.environ, {ENV_VAR_DISABLE_PLATFORM_DETECTION: "true"}): |
| 163 | +- result = detect_platforms(platform_detection_timeout_seconds=1) |
| 164 | ++ result = detect_platforms(platform_detection_timeout_seconds=30) |
| 165 | + assert result == _PLATFORM_DETECTION_DISABLED_RESULT |
| 166 | + assert "is_aws_lambda" not in result |
| 167 | + assert "is_github_action" not in result |
0 commit comments