Skip to content

Commit

Permalink
Add test name print out
Browse files Browse the repository at this point in the history
Signed-off-by: Sharpner6 <1sc2l4qi@duck.com>
  • Loading branch information
sharpener6 committed Oct 16, 2024
1 parent b0ec4a3 commit 3ce9336
Show file tree
Hide file tree
Showing 18 changed files with 79 additions and 20 deletions.
2 changes: 1 addition & 1 deletion scaler/about.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.8.8"
__version__ = "1.8.9"
6 changes: 6 additions & 0 deletions tests/test_async_indexed_queue.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import asyncio
import unittest

from scaler.utility.logging.utility import setup_logger
from scaler.utility.queues.async_indexed_queue import AsyncIndexedQueue
from tests.utility import logging_test_name


class TestAsyncIndexedQueue(unittest.TestCase):
def setUp(self) -> None:
setup_logger()
logging_test_name(self)

def test_async_indexed_queue(self):
async def async_test():
queue = AsyncIndexedQueue()
Expand Down
6 changes: 6 additions & 0 deletions tests/test_async_priority_queue.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import asyncio
import unittest

from scaler.utility.logging.utility import setup_logger
from scaler.utility.queues.async_priority_queue import AsyncPriorityQueue
from tests.utility import logging_test_name


class TestAsyncPriorityQueue(unittest.TestCase):
def setUp(self) -> None:
setup_logger()
logging_test_name(self)

def test_async_priority_queue(self):
async def async_test():
queue = AsyncPriorityQueue()
Expand Down
6 changes: 6 additions & 0 deletions tests/test_async_sorted_priority_queue.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import asyncio
import unittest

from scaler.utility.logging.utility import setup_logger
from scaler.utility.queues.async_sorted_priority_queue import AsyncSortedPriorityQueue
from tests.utility import logging_test_name


class TestSortedPriorityQueue(unittest.TestCase):
def setUp(self) -> None:
setup_logger()
logging_test_name(self)

def test_sorted_priority_queue(self):
async def async_test():
queue = AsyncSortedPriorityQueue()
Expand Down
7 changes: 6 additions & 1 deletion tests/test_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import unittest

from scaler import Client, Cluster, SchedulerClusterCombo
from tests.utility import get_available_tcp_port
from scaler.utility.logging.utility import setup_logger
from tests.utility import get_available_tcp_port, logging_test_name


def sleep_and_return_pid(sec: int):
Expand All @@ -12,6 +13,10 @@ def sleep_and_return_pid(sec: int):


class TestBalance(unittest.TestCase):
def setUp(self) -> None:
setup_logger()
logging_test_name(self)

def test_balance(self):
"""
Schedules a few long-lasting tasks to a single process cluster, then adds workers. We expect the remaining tasks
Expand Down
3 changes: 2 additions & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from scaler.utility.exceptions import ProcessorDiedError
from scaler.utility.logging.scoped_logger import ScopedLogger
from scaler.utility.logging.utility import setup_logger
from tests.utility import get_available_tcp_port
from tests.utility import get_available_tcp_port, logging_test_name


def noop(sec: int):
Expand All @@ -32,6 +32,7 @@ def raise_exception(foo: int):
class TestClient(unittest.TestCase):
def setUp(self) -> None:
setup_logger()
logging_test_name(self)
self.address = f"tcp://127.0.0.1:{get_available_tcp_port()}"
self._workers = 3
self.cluster = SchedulerClusterCombo(address=self.address, n_workers=self._workers, event_loop="builtin")
Expand Down
18 changes: 10 additions & 8 deletions tests/test_death_timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
)
from scaler.utility.logging.utility import setup_logger
from scaler.utility.zmq_config import ZMQConfig
from tests.utility import get_available_tcp_port
from tests.utility import get_available_tcp_port, logging_test_name


# This is a manual test because it can loop infinitely if it fails


class TestDeathTimeout(unittest.TestCase):
def setUp(self) -> None:
setup_logger()
logging_test_name(self)

def test_no_scheduler(self):
logging.info("test with no scheduler")
Expand Down Expand Up @@ -61,16 +63,16 @@ def test_shutdown(self):

def test_no_timeout_if_suspended(self):
"""
Client and scheduler shouldn't timeout a client if it is running inside a suspended processor.
Client and scheduler shouldn't time out a client if it is running inside a suspended processor.
"""

CLIENT_TIMEOUT_SECONDS = 3
client_timeout_seconds = 3

def parent(client: Client):
return client.submit(child).result()
def parent(c: Client):
return c.submit(child).result()

def child():
time.sleep(CLIENT_TIMEOUT_SECONDS + 1) # prevents the parent task to execute.
time.sleep(client_timeout_seconds + 1) # prevents the parent task to execute.
return "OK"

address = f"tcp://127.0.0.1:{get_available_tcp_port()}"
Expand All @@ -79,11 +81,11 @@ def child():
n_workers=1,
per_worker_queue_size=2,
event_loop="builtin",
client_timeout_seconds=CLIENT_TIMEOUT_SECONDS,
client_timeout_seconds=client_timeout_seconds,
)

try:
with Client(address, timeout_seconds=CLIENT_TIMEOUT_SECONDS) as client:
with Client(address, timeout_seconds=client_timeout_seconds) as client:
future = client.submit(parent, client)
self.assertEqual(future.result(), "OK")
finally:
Expand Down
3 changes: 2 additions & 1 deletion tests/test_future.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from scaler import Client, SchedulerClusterCombo
from scaler.utility.logging.utility import setup_logger
from tests.utility import get_available_tcp_port
from tests.utility import get_available_tcp_port, logging_test_name


def noop_sleep(sec: int):
Expand All @@ -16,6 +16,7 @@ def noop_sleep(sec: int):
class TestFuture(unittest.TestCase):
def setUp(self) -> None:
setup_logger()
logging_test_name(self)
self.address = f"tcp://127.0.0.1:{get_available_tcp_port()}"
self._workers = 3
self.cluster = SchedulerClusterCombo(address=self.address, n_workers=self._workers, event_loop="builtin")
Expand Down
3 changes: 2 additions & 1 deletion tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from scaler.utility.graph.optimization import cull_graph
from scaler.utility.logging.scoped_logger import ScopedLogger
from scaler.utility.logging.utility import setup_logger
from tests.utility import get_available_tcp_port
from tests.utility import get_available_tcp_port, logging_test_name


def inc(i):
Expand All @@ -24,6 +24,7 @@ def minus(a, b):
class TestGraph(unittest.TestCase):
def setUp(self) -> None:
setup_logger()
logging_test_name(self)
self.address = f"tcp://127.0.0.1:{get_available_tcp_port()}"
self.cluster = SchedulerClusterCombo(address=self.address, n_workers=3, event_loop="builtin")

Expand Down
6 changes: 6 additions & 0 deletions tests/test_indexed_queue.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import unittest

from scaler.utility.logging.utility import setup_logger
from scaler.utility.queues.indexed_queue import IndexedQueue
from tests.utility import logging_test_name


class TestIndexedQueue(unittest.TestCase):
def setUp(self) -> None:
setup_logger()
logging_test_name(self)

def test_indexed_queue(self):
queue = IndexedQueue()
queue.put(1)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_nested_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from scaler import Client, SchedulerClusterCombo
from scaler.utility.logging.utility import setup_logger
from tests.utility import logging_test_name

N_TASKS = 30
N_WORKERS = 3
Expand All @@ -11,6 +12,7 @@
class TestNestedTask(unittest.TestCase):
def setUp(self) -> None:
setup_logger()
logging_test_name(self)
self.address = "tcp://127.0.0.1:23456"
self.cluster = SchedulerClusterCombo(address=self.address, n_workers=N_WORKERS, event_loop="builtin")

Expand Down
5 changes: 4 additions & 1 deletion tests/test_object_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from scaler.scheduler.object_usage.object_tracker import ObjectTracker, ObjectUsage
from scaler.utility.logging.utility import setup_logger
from tests.utility import logging_test_name


@dataclasses.dataclass
Expand All @@ -19,9 +20,11 @@ def sample_ready(obj: Sample):


class TestObjectUsage(unittest.TestCase):
def test_object_usage(self):
def setUp(self) -> None:
setup_logger()
logging_test_name(self)

def test_object_usage(self):
object_usage: ObjectTracker[str, Sample] = ObjectTracker("sample", sample_ready)

object_usage.add_object(Sample("a", "value1"))
Expand Down
5 changes: 4 additions & 1 deletion tests/test_profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import unittest

from scaler import Client, SchedulerClusterCombo
from tests.utility import get_available_tcp_port
from scaler.utility.logging.utility import setup_logger
from tests.utility import get_available_tcp_port, logging_test_name


def dummy(n: int):
Expand All @@ -20,6 +21,8 @@ def busy_dummy(n: int):

class TestProfiling(unittest.TestCase):
def setUp(self):
setup_logger()
logging_test_name(self)
self.address = f"tcp://127.0.0.1:{get_available_tcp_port()}"
self.cluster = SchedulerClusterCombo(
address=self.address, n_workers=2, per_worker_queue_size=2, event_loop="builtin"
Expand Down
8 changes: 6 additions & 2 deletions tests/test_protected.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
import unittest

from scaler import Client, SchedulerClusterCombo

from tests.utility import get_available_tcp_port
from scaler.utility.logging.utility import setup_logger
from tests.utility import get_available_tcp_port, logging_test_name


class TestProtected(unittest.TestCase):
def setUp(self) -> None:
setup_logger()
logging_test_name(self)

def test_protected_true(self) -> None:
address = f"tcp://127.0.0.1:{get_available_tcp_port()}"
cluster = SchedulerClusterCombo(
Expand Down
3 changes: 2 additions & 1 deletion tests/test_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from scaler import Client, SchedulerClusterCombo, Serializer
from scaler.utility.logging.scoped_logger import ScopedLogger
from scaler.utility.logging.utility import setup_logger
from tests.utility import get_available_tcp_port
from tests.utility import get_available_tcp_port, logging_test_name


def noop(sec: int):
Expand Down Expand Up @@ -52,6 +52,7 @@ def trim_message_internal(message: Any) -> str:
class TestSerializer(unittest.TestCase):
def setUp(self) -> None:
setup_logger()
logging_test_name(self)
self.address = f"tcp://127.0.0.1:{get_available_tcp_port()}"
self._workers = 3
self.cluster = SchedulerClusterCombo(address=self.address, n_workers=self._workers, event_loop="builtin")
Expand Down
4 changes: 2 additions & 2 deletions tests/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from scaler import Client, SchedulerClusterCombo
from scaler.utility.logging.scoped_logger import ScopedLogger
from scaler.utility.logging.utility import setup_logger

from tests.utility import get_available_tcp_port
from tests.utility import get_available_tcp_port, logging_test_name


def noop(sec: int):
Expand All @@ -30,6 +29,7 @@ def noop_memory(length: int):
class TestUI(unittest.TestCase):
def setUp(self) -> None:
setup_logger()
logging_test_name(self)
self.address = f"tcp://127.0.0.1:{get_available_tcp_port()}"
self._workers = 10
self.cluster = SchedulerClusterCombo(address=self.address, n_workers=self._workers, event_loop="builtin")
Expand Down
6 changes: 6 additions & 0 deletions tests/test_worker_object_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

from scaler.protocol.python.common import ObjectContent
from scaler.protocol.python.message import ObjectInstruction, ObjectRequest, ObjectResponse
from scaler.utility.logging.utility import setup_logger
from scaler.worker.agent.object_tracker import VanillaObjectTracker
from tests.utility import logging_test_name


class TestWorkerObjectTracker(unittest.TestCase):
def setUp(self) -> None:
setup_logger()
logging_test_name(self)

def test_object_tracker(self) -> None:
tracker = VanillaObjectTracker()

Expand Down
6 changes: 6 additions & 0 deletions tests/utility.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import logging
import socket
import unittest


def get_available_tcp_port(hostname: str = "127.0.0.1") -> int:
with socket.socket(socket.AddressFamily.AF_INET, socket.SocketKind.SOCK_STREAM) as sock:
sock.bind((hostname, 0))
return sock.getsockname()[1]


def logging_test_name(obj: unittest.TestCase):
logging.info(f"{obj.__class__.__name__}:{obj._testMethodName} ==============================================")

0 comments on commit 3ce9336

Please sign in to comment.