Fix the global unique ID generator recursive constructor call

This commit is contained in:
Stanislav Hejny
2025-07-12 22:59:21 +01:00
parent dd590a11b5
commit 0e294b223d
8 changed files with 122 additions and 326 deletions
@@ -2,7 +2,8 @@ import logging
import os
import threading
from amqp.service.consul_global_id_generator import get_unique_instance_id
from amqp.adapter.consul_global_id_generator import get_unique_instance_id
from amqp.config.amq_configuration import AMQConfiguration
CONSUL_HOST = os.environ.get("CONSUL_HOST", "localhost")
CONSUL_PORT = int(os.environ.get("CONSUL_PORT", 8500))
@@ -20,7 +21,7 @@ logger = logging.getLogger(__name__)
# --- Demo: Simulate Concurrent Access ---
def worker_thread(results_list):
"""A function to be run by multiple threads to get unique IDs."""
instance_id = get_unique_instance_id()
instance_id = get_unique_instance_id(AMQConfiguration("").amq_adapter)
results_list.append(instance_id)
logger.info(f"Thread {threading.current_thread().name} got ID: {instance_id}")
+13 -5
View File
@@ -275,7 +275,9 @@ class TestBackpressureHandler:
"""
Pytest fixture to create a mock AMQConfiguration.
"""
return AMQConfiguration("")
amq_cfg = AMQConfiguration("")
amq_cfg.backpressure.cpu_monitoring_enabled = True
return amq_cfg
def test_backpressure_handler_initialization(self, mock_channel, mock_loop, mock_config):
"""
@@ -649,8 +651,12 @@ class TestBackpressureHandler:
mock_time.return_value = current_time
# Set last data message time to be older than idle_duration
handler.last_data_message_time = current_time - mock_config.backpressure.idle_duration - 10
handler.last_backpressure_event_time = current_time - mock_config.backpressure.time_window - 10
handler.last_data_message_time = (
current_time - mock_config.backpressure.idle_duration - 10
)
handler.last_backpressure_event_time = (
current_time - mock_config.backpressure.time_window - 10
)
# Call the method
await handler.check_overload_condition()
@@ -679,7 +685,9 @@ class TestBackpressureHandler:
mock_time.return_value = current_time
# Set last event time to be older than time_window
handler.last_backpressure_event_time = current_time - mock_config.backpressure.time_window - 10
handler.last_backpressure_event_time = (
current_time - mock_config.backpressure.time_window - 10
)
# Call the method
await handler.check_overload_condition()
@@ -701,7 +709,7 @@ class TestBackpressureHandler:
# Verify no thread was started
assert thread is None
assert not hasattr(handler, 'thread') or handler.thread is None
assert not hasattr(handler, "thread") or handler.thread is None
def test_start_backpressure_monitor_enabled(self, mock_channel, mock_loop, mock_config):
"""