mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-24 12:41:02 +02:00
Fix some tests
This commit is contained in:
parent
34eb083836
commit
232c6ccebb
1 changed files with 31 additions and 35 deletions
|
|
@ -59,16 +59,16 @@ class MockWebSocket:
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_pulsar_client():
|
def mock_backend():
|
||||||
"""Mock Pulsar client for integration testing."""
|
"""Mock backend for integration testing."""
|
||||||
client = MagicMock()
|
backend = MagicMock()
|
||||||
|
|
||||||
# Mock producer
|
# Mock producer
|
||||||
producer = MagicMock()
|
producer = MagicMock()
|
||||||
producer.send = MagicMock()
|
producer.send = MagicMock()
|
||||||
producer.flush = MagicMock()
|
producer.flush = MagicMock()
|
||||||
producer.close = MagicMock()
|
producer.close = MagicMock()
|
||||||
client.create_producer.return_value = producer
|
backend.create_producer.return_value = producer
|
||||||
|
|
||||||
# Mock consumer
|
# Mock consumer
|
||||||
consumer = MagicMock()
|
consumer = MagicMock()
|
||||||
|
|
@ -78,17 +78,15 @@ def mock_pulsar_client():
|
||||||
consumer.pause_message_listener = MagicMock()
|
consumer.pause_message_listener = MagicMock()
|
||||||
consumer.unsubscribe = MagicMock()
|
consumer.unsubscribe = MagicMock()
|
||||||
consumer.close = MagicMock()
|
consumer.close = MagicMock()
|
||||||
client.subscribe.return_value = consumer
|
backend.create_consumer.return_value = consumer
|
||||||
|
|
||||||
return client
|
return backend
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_import_graceful_shutdown_integration():
|
async def test_import_graceful_shutdown_integration(mock_backend):
|
||||||
"""Test import path handles shutdown gracefully with real message flow."""
|
"""Test import path handles shutdown gracefully with real message flow."""
|
||||||
mock_client = MagicMock()
|
mock_producer = mock_backend.create_producer.return_value
|
||||||
mock_producer = MagicMock()
|
|
||||||
mock_client.create_producer.return_value = mock_producer
|
|
||||||
|
|
||||||
# Track sent messages
|
# Track sent messages
|
||||||
sent_messages = []
|
sent_messages = []
|
||||||
|
|
@ -104,7 +102,7 @@ async def test_import_graceful_shutdown_integration():
|
||||||
import_handler = TriplesImport(
|
import_handler = TriplesImport(
|
||||||
ws=ws,
|
ws=ws,
|
||||||
running=running,
|
running=running,
|
||||||
pulsar_client=mock_client,
|
backend=mock_backend,
|
||||||
queue="test-triples-import"
|
queue="test-triples-import"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -151,11 +149,9 @@ async def test_import_graceful_shutdown_integration():
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_export_no_message_loss_integration():
|
async def test_export_no_message_loss_integration(mock_backend):
|
||||||
"""Test export path doesn't lose acknowledged messages."""
|
"""Test export path doesn't lose acknowledged messages."""
|
||||||
mock_client = MagicMock()
|
mock_consumer = mock_backend.create_consumer.return_value
|
||||||
mock_consumer = MagicMock()
|
|
||||||
mock_client.subscribe.return_value = mock_consumer
|
|
||||||
|
|
||||||
# Create test messages
|
# Create test messages
|
||||||
test_messages = []
|
test_messages = []
|
||||||
|
|
@ -202,7 +198,7 @@ async def test_export_no_message_loss_integration():
|
||||||
export_handler = TriplesExport(
|
export_handler = TriplesExport(
|
||||||
ws=ws,
|
ws=ws,
|
||||||
running=running,
|
running=running,
|
||||||
pulsar_client=mock_client,
|
backend=mock_backend,
|
||||||
queue="test-triples-export",
|
queue="test-triples-export",
|
||||||
consumer="test-consumer",
|
consumer="test-consumer",
|
||||||
subscriber="test-subscriber"
|
subscriber="test-subscriber"
|
||||||
|
|
@ -245,14 +241,14 @@ async def test_export_no_message_loss_integration():
|
||||||
async def test_concurrent_import_export_shutdown():
|
async def test_concurrent_import_export_shutdown():
|
||||||
"""Test concurrent import and export shutdown scenarios."""
|
"""Test concurrent import and export shutdown scenarios."""
|
||||||
# Setup mock clients
|
# Setup mock clients
|
||||||
import_client = MagicMock()
|
import_backend = MagicMock()
|
||||||
export_client = MagicMock()
|
export_backend = MagicMock()
|
||||||
|
|
||||||
import_producer = MagicMock()
|
import_producer = MagicMock()
|
||||||
export_consumer = MagicMock()
|
export_consumer = MagicMock()
|
||||||
|
|
||||||
import_client.create_producer.return_value = import_producer
|
import_backend.create_producer.return_value = import_producer
|
||||||
export_client.subscribe.return_value = export_consumer
|
export_backend.subscribe.return_value = export_consumer
|
||||||
|
|
||||||
# Track operations
|
# Track operations
|
||||||
import_operations = []
|
import_operations = []
|
||||||
|
|
@ -280,14 +276,14 @@ async def test_concurrent_import_export_shutdown():
|
||||||
import_handler = TriplesImport(
|
import_handler = TriplesImport(
|
||||||
ws=import_ws,
|
ws=import_ws,
|
||||||
running=import_running,
|
running=import_running,
|
||||||
pulsar_client=import_client,
|
backend=import_backend,
|
||||||
queue="concurrent-import"
|
queue="concurrent-import"
|
||||||
)
|
)
|
||||||
|
|
||||||
export_handler = TriplesExport(
|
export_handler = TriplesExport(
|
||||||
ws=export_ws,
|
ws=export_ws,
|
||||||
running=export_running,
|
running=export_running,
|
||||||
pulsar_client=export_client,
|
backend=export_backend,
|
||||||
queue="concurrent-export",
|
queue="concurrent-export",
|
||||||
consumer="concurrent-consumer",
|
consumer="concurrent-consumer",
|
||||||
subscriber="concurrent-subscriber"
|
subscriber="concurrent-subscriber"
|
||||||
|
|
@ -328,9 +324,9 @@ async def test_concurrent_import_export_shutdown():
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_websocket_close_during_message_processing():
|
async def test_websocket_close_during_message_processing():
|
||||||
"""Test graceful handling when websocket closes during active message processing."""
|
"""Test graceful handling when websocket closes during active message processing."""
|
||||||
mock_client = MagicMock()
|
mock_backend_local = MagicMock()
|
||||||
mock_producer = MagicMock()
|
mock_producer = MagicMock()
|
||||||
mock_client.create_producer.return_value = mock_producer
|
mock_backend_local.create_producer.return_value = mock_producer
|
||||||
|
|
||||||
# Simulate slow message processing
|
# Simulate slow message processing
|
||||||
processed_messages = []
|
processed_messages = []
|
||||||
|
|
@ -346,7 +342,7 @@ async def test_websocket_close_during_message_processing():
|
||||||
import_handler = TriplesImport(
|
import_handler = TriplesImport(
|
||||||
ws=ws,
|
ws=ws,
|
||||||
running=running,
|
running=running,
|
||||||
pulsar_client=mock_client,
|
backend=mock_backend,
|
||||||
queue="slow-processing-import"
|
queue="slow-processing-import"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -395,9 +391,9 @@ async def test_websocket_close_during_message_processing():
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_backpressure_during_shutdown():
|
async def test_backpressure_during_shutdown():
|
||||||
"""Test graceful shutdown under backpressure conditions."""
|
"""Test graceful shutdown under backpressure conditions."""
|
||||||
mock_client = MagicMock()
|
mock_backend_local = MagicMock()
|
||||||
mock_consumer = MagicMock()
|
mock_consumer = MagicMock()
|
||||||
mock_client.subscribe.return_value = mock_consumer
|
mock_backend_local.subscribe.return_value = mock_consumer
|
||||||
|
|
||||||
# Mock slow websocket
|
# Mock slow websocket
|
||||||
class SlowWebSocket(MockWebSocket):
|
class SlowWebSocket(MockWebSocket):
|
||||||
|
|
@ -411,7 +407,7 @@ async def test_backpressure_during_shutdown():
|
||||||
export_handler = TriplesExport(
|
export_handler = TriplesExport(
|
||||||
ws=ws,
|
ws=ws,
|
||||||
running=running,
|
running=running,
|
||||||
pulsar_client=mock_client,
|
backend=mock_backend,
|
||||||
queue="backpressure-export",
|
queue="backpressure-export",
|
||||||
consumer="backpressure-consumer",
|
consumer="backpressure-consumer",
|
||||||
subscriber="backpressure-subscriber"
|
subscriber="backpressure-subscriber"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue