fix: cleanup worker test stability (#7826)

* Update test_temp_flow_cleanup.py

fix: component cleanup test

* [autofix.ci] apply automated fixes

* Update test_temp_flow_cleanup.py

The test seems so flaky and unpredictable, hence proceeding with a mock patch of langflow.services.task.temp_flow_cleanup.logger

* Update test_temp_flow_cleanup.py

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Edwin Jose 2025-04-28 17:20:53 -04:00 committed by GitHub
commit 6019b3ee06
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -94,16 +94,24 @@ async def test_cleanup_worker_start_stop():
@pytest.mark.asyncio
async def test_cleanup_worker_run_with_exception(caplog):
async def test_cleanup_worker_run_with_exception(mocker):
"""Test CleanupWorker handles exceptions gracefully."""
# Mock the logger to capture log calls
mock_logger = mocker.patch("langflow.services.task.temp_flow_cleanup.logger")
settings = get_settings_service().settings
settings.public_flow_cleanup_interval = 601 # Minimum valid interval
worker = CleanupWorker()
# Start worker and let it run briefly
# Start and immediately stop the worker
await worker.start()
await worker.stop()
# Check logs for expected messages
assert any("Started database cleanup worker" in record.message for record in caplog.records)
assert any("Stopping database cleanup worker" in record.message for record in caplog.records)
# Verify the worker was started and stopped properly
assert worker._task is None
assert worker._stop_event.is_set()
# Verify the expected log messages were called
mock_logger.debug.assert_any_call("Started database cleanup worker")
mock_logger.debug.assert_any_call("Stopping database cleanup worker...")
mock_logger.debug.assert_any_call("Database cleanup worker stopped")