Skip to content

Commit c4c9309

Browse files
committed
small changes
1 parent 8f30a98 commit c4c9309

File tree

3 files changed

+3
-33
lines changed

3 files changed

+3
-33
lines changed

src/asyncflow/runtime/actors/routing/lb_algorithms.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
"""algorithms to simulate the load balancer during the simulation"""
22
import random
33
from collections import OrderedDict
4-
from collections.abc import Callable, Mapping
4+
from collections.abc import Callable
55

66
from asyncflow.config.enums import LbAlgorithmsName
77
from asyncflow.runtime.actors.edge import EdgeRuntime
88

9+
910
def least_connections(
1011
edges: OrderedDict[str, EdgeRuntime],
1112
) -> EdgeRuntime:

src/asyncflow/runtime/actors/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def __init__( # noqa: PLR0913
104104
self._server_enabled_metrics = build_server_metrics(
105105
settings.enabled_sample_metrics,
106106
)
107-
107+
108108
# Per-request metrics are keyed by request_id (int), not by RequestState object:
109109
# - ints are stable, lightweight, and hash/GC-friendly
110110
# - avoids holding strong refs to RequestState (no memory leaks)

tests/unit/runtime/actors/test_lb_algo.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from asyncflow.config.enums import LbAlgorithmsName
1616
from asyncflow.runtime.actors.routing.lb_algorithms import (
1717
LB_TABLE,
18-
fcfs_picker,
1918
least_connections,
2019
random_choice,
2120
round_robin,
@@ -42,36 +41,6 @@ def _mk_edges(pairs: list[tuple[str, int]]) -> OrderedDict[str, _DummyEdge]:
4241
return OrderedDict((k, _DummyEdge(cc)) for k, cc in pairs)
4342

4443

45-
# ------------------------------- FCFS picker -------------------------------- #
46-
47-
def test_fcfs_picker_returns_first_free_without_mutation() -> None:
48-
"""FCFS picker must return first *free* edge and not mutate the dict."""
49-
od = _mk_edges([("a", 2), ("b", 1), ("c", 3)])
50-
edges = cast("OrderedDict[str, EdgeRuntime]", od)
51-
52-
# a busy, b free, c busy
53-
busy = {"a": 1, "b": 0, "c": 2}
54-
55-
pick = fcfs_picker(edges, busy)
56-
assert pick is not None
57-
edge_id, edge_rt = pick
58-
assert edge_id == "b"
59-
assert cast("_DummyEdge", edge_rt) is od["b"]
60-
61-
# Ensure no mutation of the original OrderedDict order/size
62-
assert list(od.keys()) == ["a", "b", "c"]
63-
64-
65-
def test_fcfs_picker_all_busy_returns_none() -> None:
66-
"""FCFS picker should return None if no edges are free."""
67-
od = _mk_edges([("a", 0), ("b", 0)])
68-
edges = cast("OrderedDict[str, EdgeRuntime]", od)
69-
70-
busy = {"a": 1, "b": 3}
71-
pick = fcfs_picker(edges, busy)
72-
assert pick is None
73-
74-
7544
# ----------------------------- Other algorithms ----------------------------- #
7645

7746
def test_round_robin_rotates_and_returns_first() -> None:

0 commit comments

Comments
 (0)