Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/integration/local/invoke/test_invoke_dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test_invoke_accepts_multiple_dns_servers(self):
and executes successfully
"""
command_list = self.get_command_list(
function_to_invoke="HelloWorldServerlessFunction",
function_to_invoke="WriteToStdoutFunction",
template_path=self.template_path,
no_event=True,
)
Expand All @@ -104,4 +104,4 @@ def test_invoke_accepts_multiple_dns_servers(self):
self.assertEqual(return_code, 0, f"Command failed with stderr: {stderr}")

output = stdout.decode("utf-8")
self.assertIn("Hello World", output)
self.assertIn("wrote to stdout", output)
23 changes: 20 additions & 3 deletions tests/integration/local/start_api/test_start_api_dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Integration tests for DNS option in sam local start-api
"""

import time
import threading
import requests
import pytest
from tests.integration.local.start_api.start_api_integ_base import StartApiIntegBaseClass
Expand Down Expand Up @@ -44,8 +46,19 @@ def test_dns_configured_in_container(self):
Test that DNS servers are actually configured in the Docker container.
This inspects the container configuration to verify DNS was set correctly.
"""
response = requests.get(f"http://127.0.0.1:{self.port}/anyandall", timeout=300)
self.assertEqual(response.status_code, 200)
# Start async request to keep container alive during inspection
response_holder = {}

def make_request():
response_holder["response"] = requests.get(
f"http://127.0.0.1:{self.port}/sleepfortenseconds/function0", timeout=300
)

request_thread = threading.Thread(target=make_request)
request_thread.start()

# Wait for container to start and be in sleep phase
time.sleep(7)

sam_containers = self.docker_client.containers.list(
all=False, filters={"label": "sam.cli.container.type=lambda"}
Expand Down Expand Up @@ -76,5 +89,9 @@ def test_dns_configured_in_container(self):

self.assertTrue(
dns_verified,
f"Could not verify DNS configuration in any container. " f"Checked {len(sam_containers)} containers",
f"Could not verify DNS configuration in any container. Checked {len(sam_containers)} containers",
)

# Wait for request to complete
request_thread.join()
self.assertEqual(response_holder["response"].status_code, 200)
23 changes: 20 additions & 3 deletions tests/integration/local/start_lambda/test_start_lambda_dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Integration tests for DNS option in sam local start-lambda
"""

import time
import threading
import pytest
from tests.integration.local.start_lambda.start_lambda_api_integ_base import StartLambdaIntegBaseClass

Expand Down Expand Up @@ -78,8 +80,19 @@ def test_dns_configured_in_container(self):
Test that DNS servers are actually configured in the Docker container.
This inspects the container configuration to verify DNS was set correctly.
"""
response = self.lambda_client.invoke(FunctionName="EchoEventFunction", Payload='{"key": "value"}')
self.assertEqual(response.get("StatusCode"), 200)
# Start async invocation to keep container alive during inspection
response_holder = {}

def invoke_function():
response_holder["response"] = self.lambda_client.invoke(
FunctionName="HelloWorldSleepFunction", Payload="{}"
)

invoke_thread = threading.Thread(target=invoke_function)
invoke_thread.start()

# Wait for container to start and be in sleep phase
time.sleep(5)

sam_containers = self.docker_client.containers.list(
all=False, filters={"label": "sam.cli.container.type=lambda"}
Expand Down Expand Up @@ -113,5 +126,9 @@ def test_dns_configured_in_container(self):

self.assertTrue(
dns_verified,
f"Could not verify DNS configuration in any container. " f"Checked {len(sam_containers)} containers",
f"Could not verify DNS configuration in any container. Checked {len(sam_containers)} containers",
)

# Wait for invocation to complete
invoke_thread.join()
self.assertEqual(response_holder["response"].get("StatusCode"), 200)
Loading