|
5 | 5 | from unittest import skipIf |
6 | 6 | import uuid |
7 | 7 | import random |
8 | | -import logging |
9 | 8 | from pathlib import Path |
10 | 9 | from typing import Dict |
11 | 10 |
|
|
22 | 21 | from samcli.commands.local.cli_common.options import get_default_layer_cache_dir |
23 | 22 | from samcli.local.apigw.route import Route |
24 | 23 | from samcli.local.docker.utils import get_validated_container_client |
25 | | -from tests.testing_utils import IS_WINDOWS, get_sam_command |
| 24 | +from tests.testing_utils import IS_WINDOWS |
26 | 25 | from .start_api_integ_base import StartApiIntegBaseClass, WritableStartApiIntegBaseClass |
27 | 26 | from ..invoke.layer_utils import LayerUtils |
28 | 27 |
|
29 | | -LOG = logging.getLogger(__name__) |
30 | | - |
31 | 28 |
|
32 | 29 | @parameterized_class( |
33 | 30 | ("template_path",), |
@@ -3443,165 +3440,3 @@ def test_starts_process_successfully(self): |
3443 | 3440 |
|
3444 | 3441 | self.assertEqual(response.status_code, 200) |
3445 | 3442 | self.assertEqual(response.json(), {"hello": "world"}) |
3446 | | - |
3447 | | - |
3448 | | -class TestFunctionNameFilteringWithFilter(StartApiIntegBaseClass): |
3449 | | - """Test function name filtering with specific functions""" |
3450 | | - |
3451 | | - template_path = "/testdata/start_api/template.yaml" |
3452 | | - |
3453 | | - @classmethod |
3454 | | - def setUpClass(cls): |
3455 | | - cls.command_list = [ |
3456 | | - get_sam_command(), |
3457 | | - "local", |
3458 | | - "start-api", |
3459 | | - "HelloWorldFunction", |
3460 | | - "EchoEventFunction", |
3461 | | - "-t", |
3462 | | - cls.integration_dir + cls.template_path, |
3463 | | - ] |
3464 | | - super().setUpClass() |
3465 | | - |
3466 | | - def setUp(self): |
3467 | | - self.url = f"http://127.0.0.1:{self.port}" |
3468 | | - |
3469 | | - @pytest.mark.flaky(reruns=3) |
3470 | | - @pytest.mark.timeout(timeout=600, method="thread") |
3471 | | - def test_accessing_filtered_route(self): |
3472 | | - """Test accessing a route backed by a filtered function""" |
3473 | | - response = requests.get(self.url + "/anyandall", timeout=300) |
3474 | | - self.assertEqual(response.status_code, 200) |
3475 | | - self.assertEqual(response.json(), {"hello": "world"}) |
3476 | | - |
3477 | | - @pytest.mark.flaky(reruns=3) |
3478 | | - @pytest.mark.timeout(timeout=600, method="thread") |
3479 | | - def test_accessing_filtered_route_post(self): |
3480 | | - """Test accessing another filtered route""" |
3481 | | - response = requests.post(self.url + "/echoeventbody", json={}, timeout=300) |
3482 | | - self.assertEqual(response.status_code, 200) |
3483 | | - |
3484 | | - @pytest.mark.flaky(reruns=3) |
3485 | | - @pytest.mark.timeout(timeout=600, method="thread") |
3486 | | - def test_accessing_non_filtered_route(self): |
3487 | | - """Test accessing a route backed by non-filtered function returns 404""" |
3488 | | - response = requests.get(self.url + "/onlysetbody", timeout=300) |
3489 | | - self.assertIn(response.status_code, [403, 404]) |
3490 | | - |
3491 | | - |
3492 | | -class TestFunctionNameFilteringMultipleRoutes(StartApiIntegBaseClass): |
3493 | | - """Test that filtering works correctly when functions have multiple routes""" |
3494 | | - |
3495 | | - template_path = "/testdata/start_api/template.yaml" |
3496 | | - |
3497 | | - @classmethod |
3498 | | - def setUpClass(cls): |
3499 | | - cls.command_list = [ |
3500 | | - get_sam_command(), |
3501 | | - "local", |
3502 | | - "start-api", |
3503 | | - "HelloWorldFunction", |
3504 | | - "-t", |
3505 | | - cls.integration_dir + cls.template_path, |
3506 | | - ] |
3507 | | - super().setUpClass() |
3508 | | - |
3509 | | - def setUp(self): |
3510 | | - self.url = f"http://127.0.0.1:{self.port}" |
3511 | | - |
3512 | | - @pytest.mark.flaky(reruns=3) |
3513 | | - @pytest.mark.timeout(timeout=600, method="thread") |
3514 | | - def test_all_routes_for_filtered_function_available(self): |
3515 | | - """Test that all routes for a filtered function are available""" |
3516 | | - self.assertEqual(requests.get(self.url + "/anyandall", timeout=300).status_code, 200) |
3517 | | - self.assertEqual(requests.post(self.url + "/id", json={}, timeout=300).status_code, 200) |
3518 | | - self.assertEqual(requests.get(self.url + "/proxypath/some/path", timeout=300).status_code, 200) |
3519 | | - |
3520 | | - |
3521 | | -class TestFunctionNameFilteringWarmContainersEager(StartApiIntegBaseClass): |
3522 | | - """Test function filtering with EAGER warm containers""" |
3523 | | - |
3524 | | - template_path = "/testdata/start_api/template-warm-containers.yaml" |
3525 | | - container_mode = ContainersInitializationMode.EAGER.value |
3526 | | - mode_env_variable = str(uuid.uuid4()) |
3527 | | - parameter_overrides = {"ModeEnvVariable": mode_env_variable} |
3528 | | - |
3529 | | - @classmethod |
3530 | | - def setUpClass(cls): |
3531 | | - cls.command_list = [ |
3532 | | - get_sam_command(), |
3533 | | - "local", |
3534 | | - "start-api", |
3535 | | - "HelloWorldFunction", |
3536 | | - "-t", |
3537 | | - cls.integration_dir + cls.template_path, |
3538 | | - "--warm-containers", |
3539 | | - cls.container_mode, |
3540 | | - "--parameter-overrides", |
3541 | | - cls._make_parameter_override_arg(cls.parameter_overrides), |
3542 | | - ] |
3543 | | - super().setUpClass() |
3544 | | - |
3545 | | - def setUp(self): |
3546 | | - self.url = f"http://127.0.0.1:{self.port}" |
3547 | | - |
3548 | | - @pytest.mark.flaky(reruns=3) |
3549 | | - @pytest.mark.timeout(timeout=600, method="thread") |
3550 | | - def test_only_filtered_function_has_container(self): |
3551 | | - """Test that only the filtered function has a pre-warmed container in EAGER mode""" |
3552 | | - self.assertEqual(requests.get(self.url + "/hello", timeout=300).status_code, 200) |
3553 | | - sleep(2) |
3554 | | - |
3555 | | - containers = self.docker_client.containers.list(all=True, filters={"label": "sam.cli.container.type=lambda"}) |
3556 | | - initiated_containers = sum( |
3557 | | - 1 |
3558 | | - for c in containers |
3559 | | - if any(self.mode_env_variable in env for env in c.attrs.get("Config", {}).get("Env", [])) |
3560 | | - ) |
3561 | | - self.assertEqual(initiated_containers, 1) |
3562 | | - |
3563 | | - |
3564 | | -class TestFunctionNameFilteringWarmContainersLazy(StartApiIntegBaseClass): |
3565 | | - """Test function filtering with LAZY warm containers""" |
3566 | | - |
3567 | | - template_path = "/testdata/start_api/template-warm-containers.yaml" |
3568 | | - container_mode = ContainersInitializationMode.LAZY.value |
3569 | | - mode_env_variable = str(uuid.uuid4()) |
3570 | | - parameter_overrides = {"ModeEnvVariable": mode_env_variable} |
3571 | | - |
3572 | | - @classmethod |
3573 | | - def setUpClass(cls): |
3574 | | - cls.command_list = [ |
3575 | | - get_sam_command(), |
3576 | | - "local", |
3577 | | - "start-api", |
3578 | | - "HelloWorldFunction", |
3579 | | - "-t", |
3580 | | - cls.integration_dir + cls.template_path, |
3581 | | - "--warm-containers", |
3582 | | - cls.container_mode, |
3583 | | - "--parameter-overrides", |
3584 | | - cls._make_parameter_override_arg(cls.parameter_overrides), |
3585 | | - ] |
3586 | | - super().setUpClass() |
3587 | | - |
3588 | | - def setUp(self): |
3589 | | - self.url = f"http://127.0.0.1:{self.port}" |
3590 | | - |
3591 | | - def _count_containers(self): |
3592 | | - """Count containers with the test's unique environment variable""" |
3593 | | - containers = self.docker_client.containers.list(all=True, filters={"label": "sam.cli.container.type=lambda"}) |
3594 | | - return sum( |
3595 | | - 1 |
3596 | | - for c in containers |
3597 | | - if any(self.mode_env_variable in env for env in c.attrs.get("Config", {}).get("Env", [])) |
3598 | | - ) |
3599 | | - |
3600 | | - @pytest.mark.flaky(reruns=3) |
3601 | | - @pytest.mark.timeout(timeout=600, method="thread") |
3602 | | - def test_container_created_on_demand_for_filtered_function(self): |
3603 | | - """Test that containers are created on-demand only for filtered functions in LAZY mode""" |
3604 | | - initial_count = self._count_containers() |
3605 | | - self.assertEqual(requests.get(self.url + "/hello", timeout=300).status_code, 200) |
3606 | | - sleep(2) |
3607 | | - self.assertEqual(self._count_containers() - initial_count, 1) |
0 commit comments