Skip to content

Commit

Permalink
fix macos tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jericho Tolentino <[email protected]>
  • Loading branch information
jericht committed May 21, 2024
1 parent 0d356b9 commit 4035b4c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/openjd/adaptor_runtime/_http/sockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ def gen_socket_path(dir: str, base_name: str):
return os.path.join(dir, name)

if not base_dir:
socket_dir = tempfile.gettempdir()
socket_dir = os.path.realpath(tempfile.gettempdir())
# Check that the sticky bit is set on the temp dir
if not os.stat(socket_dir).st_mode & stat.S_ISVTX:
raise NoSocketPathFoundException(
f"Cannot use temporary directory {socket_dir} because it does not have the "
"sticky bit (restricted deletion flag) set"
)
else:
socket_dir = base_dir
socket_dir = os.path.realpath(base_dir)

if namespace:
socket_dir = os.path.join(socket_dir, namespace)
Expand Down
19 changes: 16 additions & 3 deletions test/openjd/adaptor_runtime/conftest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
import platform
import random
import string
from typing import Generator
from unittest.mock import MagicMock, patch

from openjd.adaptor_runtime._osname import OSName
import string
import random
import pytest

from openjd.adaptor_runtime._osname import OSName
from openjd.adaptor_runtime._http import sockets

if OSName.is_windows():
import win32net
import win32netcon
Expand Down Expand Up @@ -92,3 +95,13 @@ def delete_user() -> None:
yield username, password
# Delete the user after test completes
delete_user()


@pytest.fixture(scope="session", autouse=OSName().is_macos())
def mock_sockets_py_tempfile_gettempdir_to_slash_tmp() -> Generator[MagicMock, None, None]:
"""
Mock that is automatically used on Mac to override the tempfile.gettempdir() usages in sockets.py
because the folder returned by it on Mac is too long for the socket name to fit (max 104 bytes, see sockets.py)
"""
with patch.object(sockets.tempfile, "gettempdir", return_value="/tmp") as m:
yield m
2 changes: 1 addition & 1 deletion test/openjd/adaptor_runtime/unit/http/test_sockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def test_handles_socket_name_collisions(

# THEN
assert result.endswith(expected_sock_name)
mock_exists.call_count == len(existing_sock_names) + 1
assert mock_exists.call_count == (len(existing_sock_names) + 1)


class TestLinuxSocketPaths:
Expand Down

0 comments on commit 4035b4c

Please sign in to comment.