Skip to content

Commit

Permalink
tests: simple_client refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jimf5 committed Dec 9, 2023
1 parent 1a20d63 commit 07fc783
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions tests/test_otel.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,31 +160,31 @@ def session(http_ver, url):

@pytest.fixture
def simple_client(url, logger):

def do_get(sock, path):
http_send = f"GET {parsed.path}\n".encode()
logger.debug(f"{http_send=}")
sock.sendall(http_send)
http_recv = ssock.recv(1024)
logger.debug(f"{http_recv=}")
return http_recv.decode("utf-8")

parsed = urlparse(url)
host = parsed.hostname
if parsed.port is not None:
port = parsed.port
else:
port = 8443
port = 8443 if parsed.scheme == "https" else 8080
if parsed.scheme == "https":
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
with socket.create_connection((host, port)) as sock:
with ctx.wrap_socket(sock, server_hostname="localhost") as ssock:
http_send = f"GET {parsed.path}\n".encode()
logger.debug(f"{http_send=}")
ssock.sendall(http_send)
http_recv = ssock.recv(1024)
logger.debug(f"{http_recv=}")
yield http_recv.decode("utf-8")
yield do_get(ssock, parsed.path)
else:
with socket.create_connection((host, port)) as sock:
logger.debug(f"{http_send=}")
ssock.sendall(f"GET {parsed.path}\n".encode())
http_recv = ssock.recv(1024).decode("utf-8")
logger.debug(f"{http_recv=}")
yield http_recv.decode("utf-8")
yield do_get(sock, parsed.path)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -238,7 +238,7 @@ class TestOTelGenerateSpansOldClient:
for x in range(1, 26)
],
)
def test_do_request_old_client(self, simple_client, url, response):
def test_do_request(self, simple_client, url, response):
assert response == simple_client


Expand Down

0 comments on commit 07fc783

Please sign in to comment.