Skip to content

[Test Proxy] Improved logging and timeout behavior #26903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 24, 2022
Merged
Changes from 1 commit
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
27 changes: 20 additions & 7 deletions tools/azure-sdk-tools/devtools_testutils/proxy_startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
CONTAINER_NAME = "ambitious_azsdk_test_proxy"
LINUX_IMAGE_SOURCE_PREFIX = "azsdkengsys.azurecr.io/engsys/testproxy-lin"
WINDOWS_IMAGE_SOURCE_PREFIX = "azsdkengsys.azurecr.io/engsys/testproxy-win"
CONTAINER_STARTUP_TIMEOUT = 6000
CONTAINER_STARTUP_TIMEOUT = 30
PROXY_MANUALLY_STARTED = os.getenv("PROXY_MANUAL_START", False)

PROXY_CHECK_URL = PROXY_URL + "/Info/Available"
Expand Down Expand Up @@ -71,22 +71,27 @@ def ascend_to_root(start_dir_or_file: str) -> str:

def delete_container() -> None:
"""Delete container if it remained"""
proc = subprocess.Popen(shlex.split(f"docker rm -f {CONTAINER_NAME}"))
output, stderr = proc.communicate()
proc = subprocess.Popen(
shlex.split(f"docker rm -f {CONTAINER_NAME}"),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.DEVNULL,
)
output, stderr = proc.communicate(timeout=10)
return None


def check_availability() -> None:
"""Attempts request to /Info/Available. If a test-proxy instance is responding, we should get a response."""
try:
response = requests.get(PROXY_CHECK_URL, timeout=60)
response = requests.get(PROXY_CHECK_URL, timeout=10)
return response.status_code
# We get an SSLError if the container is started but the endpoint isn't available yet
except requests.exceptions.SSLError as sslError:
_LOGGER.debug(sslError)
return 404
except Exception as e:
_LOGGER.error(e)
_LOGGER.debug(e)
return 404


Expand Down Expand Up @@ -121,7 +126,10 @@ def create_container(repo_root: str) -> None:
shlex.split(
f"docker run --rm --name {CONTAINER_NAME} -v '{repo_root}:{path_prefix}/srv/testproxy' "
f"{linux_container_args} -p 5001:5001 -p 5000:5000 {image_prefix}:{image_tag}"
)
),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.DEVNULL,
)


Expand Down Expand Up @@ -181,7 +189,12 @@ def stop_test_proxy() -> None:

else:
_LOGGER.info("Stopping the test proxy container...")
subprocess.Popen(shlex.split("docker stop " + CONTAINER_NAME))
subprocess.Popen(
shlex.split(f"docker stop {CONTAINER_NAME}"),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.DEVNULL,
)


@pytest.fixture(scope="session")
Expand Down