From 1a852d00923a08e91e735a0a14265444413d16f8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 26 Jan 2026 10:41:29 +0000 Subject: [PATCH 1/4] Initial plan From 45f20dff06c88a0832d4d58c2f9f9e5af678dfbb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 26 Jan 2026 10:45:47 +0000 Subject: [PATCH 2/4] Address code review comments: fix imports, unix socket test, and cleanup Co-authored-by: ochui <21917688+ochui@users.noreply.github.com> --- tests/test_edge_cases.py | 20 ++++++++++++++++++++ tests/test_func.py | 35 +++++++++++++++++++++++++---------- 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/tests/test_edge_cases.py b/tests/test_edge_cases.py index 0d10f88..58762ec 100644 --- a/tests/test_edge_cases.py +++ b/tests/test_edge_cases.py @@ -115,6 +115,20 @@ class TestEdgeCases(unittest.IsolatedAsyncioTestCase): async def asyncSetUp(self): cwd = os.path.dirname(os.path.realpath(__file__)) self.config_path = os.path.join(cwd, "test.conf") + self.fq_instance = None + + async def asyncTearDown(self): + """Clean up Redis state and close connections after each test.""" + # If a test initialized FQ with real Redis, clean up + if self.fq_instance is not None: + try: + if self.fq_instance._r is not None: + await self.fq_instance._r.flushdb() + await self.fq_instance.close() + except Exception: + # Ignore errors during cleanup + pass + self.fq_instance = None def test_missing_config_file_raises(self): with self.assertRaisesRegex(FQException, "Config file not found"): @@ -159,6 +173,7 @@ async def test_cluster_initialization(self): async def test_dequeue_payload_none(self): """Covers dequeue branch where payload is None (queue.py line 212).""" fq = FQ(self.config_path) + self.fq_instance = fq await fq._initialize() fake_dequeue = FakeLuaDequeue() fq._lua_dequeue = fake_dequeue @@ -166,15 +181,18 @@ async def test_dequeue_payload_none(self): self.assertEqual(result["status"], "failure") self.assertTrue(fake_dequeue.called) await fq.close() + self.fq_instance = None async def test_clear_queue_delete_only(self): """Covers clear_queue else branch (queue.py lines 499, 502).""" fq = FQ(self.config_path) + self.fq_instance = fq await fq._initialize() await fq._r.flushdb() response = await fq.clear_queue(queue_type="noqueue", queue_id="missing") self.assertEqual(response["status"], "Failure") await fq.close() + self.fq_instance = None async def test_close_fallback_paths(self): """Covers close() fallback paths (queue.py lines 528-549).""" @@ -249,10 +267,12 @@ async def test_get_queue_length_invalid_params(self): async def test_deep_status_real_redis(self): """Covers deep_status with real redis (queue.py line 420).""" fq = FQ(self.config_path) + self.fq_instance = fq await fq._initialize() result = await fq.deep_status() self.assertTrue(result) await fq.close() + self.fq_instance = None if __name__ == "__main__": diff --git a/tests/test_func.py b/tests/test_func.py index d20ae06..480bbf5 100644 --- a/tests/test_func.py +++ b/tests/test_func.py @@ -8,7 +8,7 @@ import unittest import msgpack import tempfile -from unittest.mock import patch, AsyncMock +from unittest.mock import AsyncMock, MagicMock from fq import FQ from fq.exceptions import FQException from fq.utils import generate_epoch, deserialize_payload @@ -1816,7 +1816,7 @@ async def test_close_with_none_client(self): self.assertIsNone(fq._r) async def test_initialize_unix_socket_connection(self): - """Test initialization with unix socket connection - tests line 59.""" + """Test initialization with Unix socket connection - tests line 59.""" # Create a temporary config with unix_sock with tempfile.NamedTemporaryFile(mode='w', suffix='.conf', delete=False) as f: f.write("""[fq] @@ -1833,14 +1833,29 @@ async def test_initialize_unix_socket_connection(self): config_path = f.name try: - fq = FQ(config_path) - # Mock the Redis ping to avoid actual connection attempt - mock_redis = AsyncMock() - mock_redis.ping = AsyncMock(return_value=True) - fq._r = mock_redis - # This tests the unix_sock path was configured (line 59) - self.assertIsNotNone(fq._r) - await fq.close() + # Create a mock Redis class to capture initialization parameters + mock_redis_instance = MagicMock() + mock_redis_instance.ping = AsyncMock(return_value=True) + mock_redis_instance.register_script = MagicMock(return_value=MagicMock()) + mock_redis_instance.aclose = AsyncMock() + + redis_init_kwargs = {} + + def capture_redis_init(**kwargs): + redis_init_kwargs.update(kwargs) + return mock_redis_instance + + # Patch Redis to intercept the initialization + with unittest.mock.patch('fq.queue.Redis', side_effect=capture_redis_init): + fq = FQ(config_path) + await fq._initialize() + + # Verify that Redis was initialized with unix_socket_path + self.assertIn('unix_socket_path', redis_init_kwargs) + self.assertEqual(redis_init_kwargs['unix_socket_path'], '/tmp/redis_nonexistent.sock') + self.assertEqual(redis_init_kwargs['db'], '0') + + await fq.close() finally: os.unlink(config_path) From 5d5b515dcd0c2893c1a1f0b0a4c5b65e49e3ff4d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 26 Jan 2026 10:47:15 +0000 Subject: [PATCH 3/4] Improve code review feedback: better naming and comments Co-authored-by: ochui <21917688+ochui@users.noreply.github.com> --- tests/test_edge_cases.py | 3 ++- tests/test_func.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test_edge_cases.py b/tests/test_edge_cases.py index 58762ec..8424638 100644 --- a/tests/test_edge_cases.py +++ b/tests/test_edge_cases.py @@ -126,7 +126,8 @@ async def asyncTearDown(self): await self.fq_instance._r.flushdb() await self.fq_instance.close() except Exception: - # Ignore errors during cleanup + # Ignore errors during cleanup - tests may have mocked or closed connections + # This prevents tearDown failures from masking test failures pass self.fq_instance = None diff --git a/tests/test_func.py b/tests/test_func.py index 480bbf5..52aad13 100644 --- a/tests/test_func.py +++ b/tests/test_func.py @@ -1841,12 +1841,12 @@ async def test_initialize_unix_socket_connection(self): redis_init_kwargs = {} - def capture_redis_init(**kwargs): + def mock_redis_constructor(**kwargs): redis_init_kwargs.update(kwargs) return mock_redis_instance # Patch Redis to intercept the initialization - with unittest.mock.patch('fq.queue.Redis', side_effect=capture_redis_init): + with unittest.mock.patch('fq.queue.Redis', side_effect=mock_redis_constructor): fq = FQ(config_path) await fq._initialize() From a5c093406232a554ce578cefdaa270c791e6bce3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 26 Jan 2026 11:00:04 +0000 Subject: [PATCH 4/4] Fix tearDown cleanup and db assertion brittleness Co-authored-by: ochui <21917688+ochui@users.noreply.github.com> --- tests/test_edge_cases.py | 6 ------ tests/test_func.py | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/test_edge_cases.py b/tests/test_edge_cases.py index 8424638..87c8721 100644 --- a/tests/test_edge_cases.py +++ b/tests/test_edge_cases.py @@ -181,8 +181,6 @@ async def test_dequeue_payload_none(self): result = await fq.dequeue() self.assertEqual(result["status"], "failure") self.assertTrue(fake_dequeue.called) - await fq.close() - self.fq_instance = None async def test_clear_queue_delete_only(self): """Covers clear_queue else branch (queue.py lines 499, 502).""" @@ -192,8 +190,6 @@ async def test_clear_queue_delete_only(self): await fq._r.flushdb() response = await fq.clear_queue(queue_type="noqueue", queue_id="missing") self.assertEqual(response["status"], "Failure") - await fq.close() - self.fq_instance = None async def test_close_fallback_paths(self): """Covers close() fallback paths (queue.py lines 528-549).""" @@ -272,8 +268,6 @@ async def test_deep_status_real_redis(self): await fq._initialize() result = await fq.deep_status() self.assertTrue(result) - await fq.close() - self.fq_instance = None if __name__ == "__main__": diff --git a/tests/test_func.py b/tests/test_func.py index 52aad13..0116167 100644 --- a/tests/test_func.py +++ b/tests/test_func.py @@ -1853,7 +1853,7 @@ def mock_redis_constructor(**kwargs): # Verify that Redis was initialized with unix_socket_path self.assertIn('unix_socket_path', redis_init_kwargs) self.assertEqual(redis_init_kwargs['unix_socket_path'], '/tmp/redis_nonexistent.sock') - self.assertEqual(redis_init_kwargs['db'], '0') + self.assertEqual(int(redis_init_kwargs['db']), 0) await fq.close() finally: