Skip to content

Commit

Permalink
Merge branch 'main' into fix-scheduler-race
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Izquierdo authored Jun 6, 2024
2 parents 4d3c4c1 + c4f87bd commit 8e95603
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/aap_eda/tasks/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import logging
import random
from collections import Counter
from datetime import datetime, timedelta
from typing import Optional, Union
Expand Down Expand Up @@ -333,7 +334,13 @@ def get_least_busy_queue_name() -> str:
"No healthy queue found to dispatch the request",
)

return queue_counter.most_common()[-1][0]
min_count = queue_counter.most_common()[-1][1]
least_common = [
queue for queue, count in queue_counter.items() if count == min_count
]
if len(least_common) == 1:
return least_common[0]
return random.choice(least_common)


def get_queue_name_by_parent_id(
Expand Down
38 changes: 38 additions & 0 deletions tests/unit/test_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,33 @@ def two_queues_neither_responsive(monkeypatch):
)


@pytest.fixture
def three_queues_two_candidates(monkeypatch):
return _mock_up_queues(
monkeypatch,
{
"queue1": {
"workers": {
"worker1_1": {"responsive": True},
},
"process_count": 1,
},
"queue2": {
"workers": {
"worker2_1": {"responsive": True},
},
"process_count": 1,
},
"queue3": {
"workers": {
"worker3_1": {"responsive": True},
},
"process_count": 2,
},
},
)


@pytest.mark.parametrize(
"fixture",
[
Expand Down Expand Up @@ -240,6 +267,17 @@ def test_get_least_busy_queue_name(fixture, request):
get_least_busy_queue_name()


def test_get_least_busy_queue_name_multiple_queues(
three_queues_two_candidates,
):
expected_queues = [
"queue1",
"queue2",
]
queue = get_least_busy_queue_name()
assert queue in expected_queues


@pytest.fixture
def multi_queue_various_states(monkeypatch):
return _mock_up_queues(
Expand Down

0 comments on commit 8e95603

Please sign in to comment.