Skip to content
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

Switch to using named pipes for test communication #22390

Merged
merged 60 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
cc353a2
Add named pipe utility classes
karthiknadig Oct 31, 2023
f9943a5
Get test ids server working with named pipes
karthiknadig Oct 31, 2023
364ed9f
Add named pipes to pytest discovery and execution
karthiknadig Nov 1, 2023
5edfb26
get named sockets functioning for unix
eleanorjboyd Jan 3, 2024
7b387a8
move socket stuff to different file
eleanorjboyd Jan 3, 2024
c2fc87e
curr progress
eleanorjboyd Jan 8, 2024
59500b2
renamed vars
eleanorjboyd Jan 8, 2024
b43d073
cleanup
eleanorjboyd Jan 8, 2024
215af8d
update pytest unittests to get them working
eleanorjboyd Jan 11, 2024
585893c
fix tests
eleanorjboyd Jan 19, 2024
57e0c9b
fix unittests python tests
eleanorjboyd Jan 22, 2024
ca279f6
fix utils rename
eleanorjboyd Jan 22, 2024
322c9fc
Merge branch 'main' into named-pipes
eleanorjboyd Jan 22, 2024
a4d6367
windows work-in-progress
eleanorjboyd Feb 7, 2024
46abb41
fixing env vars pytest discovery adapter
eleanorjboyd Feb 8, 2024
544caed
Merge branch 'main' into named-pipes
eleanorjboyd Feb 13, 2024
219629e
pytest tests working mac
eleanorjboyd Feb 14, 2024
1b150ce
fix path
eleanorjboyd Feb 14, 2024
e02cc71
fixing some errors to run CI tests
eleanorjboyd Feb 14, 2024
b0fcf45
fix types
eleanorjboyd Feb 14, 2024
4d7fc7e
spot a
eleanorjboyd Feb 26, 2024
6f67ee3
working one pytest mac
eleanorjboyd Feb 26, 2024
784c318
spot b
eleanorjboyd Feb 26, 2024
2812465
edits for windows 14/16
eleanorjboyd Feb 28, 2024
89278ba
add conditional requirement for windows
eleanorjboyd Feb 28, 2024
b098067
Merge branch 'main' into named-pipes
eleanorjboyd Feb 28, 2024
f61086a
fix build errors
eleanorjboyd Feb 28, 2024
c999593
fix python types
eleanorjboyd Feb 28, 2024
a9f123d
fix python tests, return new helper
eleanorjboyd Feb 28, 2024
e8da064
type fixes
eleanorjboyd Feb 28, 2024
c16629b
rename to python_files to align with main
eleanorjboyd Apr 1, 2024
ef4f468
untracked align with main
eleanorjboyd Apr 1, 2024
a84b29f
Merge remote-tracking branch 'upstream/main' into named-pipes
eleanorjboyd Apr 1, 2024
0ab99d9
merge issues
eleanorjboyd Apr 1, 2024
071fc39
more merge conflicts
eleanorjboyd Apr 1, 2024
2fb7c83
merge with main again
eleanorjboyd Apr 1, 2024
0229592
updates to support large repos
eleanorjboyd Apr 1, 2024
e965362
Merge branch 'main' into named-pipes
eleanorjboyd Apr 1, 2024
63187b1
cancelationtokensworking
eleanorjboyd Apr 3, 2024
1235e7b
unittest discovery tests working
eleanorjboyd Apr 3, 2024
f4432f7
fix ruff requirements
eleanorjboyd Apr 5, 2024
9f55664
Merge remote-tracking branch 'upstream/main' into named-pipes
eleanorjboyd Apr 5, 2024
1855128
cleanup
eleanorjboyd Apr 5, 2024
ed52d0c
add logging to catch testing cwd issue
eleanorjboyd Apr 5, 2024
5911a44
fix import
eleanorjboyd Apr 9, 2024
dbee9bc
remove extra print lines
eleanorjboyd Apr 9, 2024
e2afae5
remove unneeded sections in helpers
eleanorjboyd Apr 9, 2024
5a1ba8f
add pytest.ini file to .data directory
eleanorjboyd Apr 9, 2024
8af151e
cleanup
eleanorjboyd Apr 9, 2024
4cf2cd4
fixing windows test
eleanorjboyd Apr 10, 2024
a513fff
remove socket manager reader for windows
eleanorjboyd Apr 10, 2024
8419dab
fix launch debug tests
eleanorjboyd Apr 10, 2024
da64ff5
add exception handling for reader
eleanorjboyd Apr 10, 2024
32c1af3
Merge branch 'main' into named-pipes
eleanorjboyd Apr 10, 2024
800c671
remove unneeded print
eleanorjboyd Apr 10, 2024
53beb2a
add reader to read method
eleanorjboyd Apr 10, 2024
921c924
Fix bug with windows named pipes
karthiknadig Apr 16, 2024
5f4d71c
Fix test and formatting
karthiknadig Apr 16, 2024
b128b68
Fix linting
karthiknadig Apr 16, 2024
a868c29
Fix pyright complaints
karthiknadig Apr 16, 2024
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
3 changes: 3 additions & 0 deletions build/test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ torch-tb-profiler

# extension build tests
freezegun

# testing custom pytest plugin require the use of named pipes
eleanorjboyd marked this conversation as resolved.
Show resolved Hide resolved
namedpipe; platform_system == "Windows"
6 changes: 3 additions & 3 deletions python_files/testing_tools/process_json_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# Licensed under the MIT License.
import io
import json
from typing import List
from typing import List, Dict

CONTENT_LENGTH: str = "Content-Length:"


def process_rpc_json(data: str) -> List[str]:
def process_rpc_json(data: str) -> Dict[str, List[str]]:
"""Process the JSON data which comes from the server."""
str_stream: io.StringIO = io.StringIO(data)

Expand All @@ -22,7 +22,7 @@ def process_rpc_json(data: str) -> List[str]:
if not line or line.isspace():
raise ValueError("Header does not contain Content-Length")

while True:
while True: # keep reading until the number of bytes is the CONTENT_LENGTH
line: str = str_stream.readline()
if not line or line.isspace():
break
Expand Down
70 changes: 70 additions & 0 deletions python_files/testing_tools/socket_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,76 @@
import socket
import sys

# set the socket before it gets blocked or overwritten by a user tests
_SOCKET = socket.socket


class PipeManager:
def __init__(self, name):
self.name = name

def __enter__(self):
return self.connect()

def __exit__(self, *_):
self.close()

def connect(self):
if sys.platform == "win32":
self._writer = open(self.name, "wt", encoding="utf-8")
# reader created in read method
else:
self._socket = _SOCKET(socket.AF_UNIX, socket.SOCK_STREAM)
self._socket.connect(self.name)
return self

def close(self):
if sys.platform == "win32":
self._writer.close()
else:
# add exception catch
self._socket.close()

def write(self, data: str):
if sys.platform == "win32":
try:
# for windows, is should only use \n\n
request = (
f"""content-length: {len(data)}\ncontent-type: application/json\n\n{data}"""
)
self._writer.write(request)
self._writer.flush()
except Exception as e:
print("error attempting to write to pipe", e)
raise (e)
else:
# must include the carriage-return defined (as \r\n) for unix systems
request = (
f"""content-length: {len(data)}\r\ncontent-type: application/json\r\n\r\n{data}"""
)
self._socket.send(request.encode("utf-8"))

def read(self, bufsize=1024) -> str:
"""Read data from the socket.

Args:
bufsize (int): Number of bytes to read from the socket.

Returns:
data (str): Data received from the socket.
"""
if sys.platform == "win32":
# returns a string automatically from read
if not hasattr(self, "_reader"):
self._reader = open(self.name, "rt", encoding="utf-8")
return self._reader.read(bufsize)
else:
# receive bytes and convert to string
while True:
part: bytes = self._socket.recv(bufsize)
data: str = part.decode("utf-8")
return data


class SocketManager(object):
"""Create a socket and connect to the given address.
Expand Down
5 changes: 5 additions & 0 deletions python_files/tests/pytestadapter/.data/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

# pytest.ini is specified here so the root directory of the tests is kept at .data instead of referencing
# the parent python_files/pyproject.toml for test_discovery.py and test_execution.py for pytest-adapter tests.
Loading
Loading