Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 26, 2026

  • Remove unused patch import from tests/test_func.py
  • Fix test_initialize_unix_socket_connection to actually exercise unix-socket initialization
  • Add asyncTearDown to tests/test_edge_cases.py for proper cleanup
  • Address code review nitpicks (better naming and exception comments)
  • Fix tearDown to actually run by removing manual cleanup in tests
  • Make db assertion less brittle by accepting numeric values

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Expand test coverage to improve FQ queueing system Fix test coverage gaps: unused imports, mock unix socket init, and cleanup Jan 26, 2026
Copilot AI requested a review from ochui January 26, 2026 10:48
@ochui ochui marked this pull request as ready for review January 26, 2026 10:49
Copilot AI review requested due to automatic review settings January 26, 2026 10:49
@coderabbitai
Copy link

coderabbitai bot commented Jan 26, 2026

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens test quality around Redis initialization and cleanup, removing an unused mock import, making the Unix-socket initialization test exercise the real code path, and adding Redis cleanup logic for edge-case tests.

Changes:

  • Removed an unused patch import from tests/test_func.py and added MagicMock for more flexible mocking.
  • Reworked test_initialize_unix_socket_connection to patch fq.queue.Redis, call FQ._initialize(), and assert that the Unix socket path and DB index are passed correctly.
  • Added asyncTearDown and fq_instance tracking in tests/test_edge_cases.py to perform Redis DB flush and connection cleanup around tests that use a real Redis client.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
tests/test_func.py Cleans up mock imports and strengthens the Unix-socket Redis initialization test by exercising the actual _initialize path and verifying constructor kwargs.
tests/test_edge_cases.py Introduces per-test Redis cleanup via asyncTearDown and tracks real FQ instances to avoid cross-test interference and resource warnings.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +122 to +126
# 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()
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new asyncTearDown is intended to flush Redis and close connections after each test, but the current pattern of setting self.fq_instance = None inside tests (e.g., lines 176-185, 189-196, 270-276) means that on successful test runs this teardown block is skipped, so Redis state is not actually cleaned between tests. To ensure the cleanup described in the PR, consider relying on asyncTearDown as the single place that closes and resets fq_instance (and avoid resetting it to None in the tests themselves), or at least avoid clearing self.fq_instance before teardown runs.

Copilot uses AI. Check for mistakes.
# 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')
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertion tightly couples the test to db being the string '0', even though the production code only requires that the logical DB index be 0. To make the test less brittle against harmless implementation changes (e.g., casting db to an int), consider asserting on the numeric value instead, or relaxing the check so it does not depend on the exact type representation.

Suggested change
self.assertEqual(redis_init_kwargs['db'], '0')
self.assertEqual(int(redis_init_kwargs['db']), 0)

Copilot uses AI. Check for mistakes.
@ochui
Copy link
Member

ochui commented Jan 26, 2026

@copilot apply changes based on the comments in this thread

Copy link
Contributor Author

Copilot AI commented Jan 26, 2026

@copilot apply changes based on the comments in this thread

I've applied both changes from the review in commit a5c0934:

  1. Fixed tearDown cleanup: Removed manual await fq.close() and self.fq_instance = None from three tests (test_dequeue_payload_none, test_clear_queue_delete_only, test_deep_status_real_redis). Now asyncTearDown properly runs and performs cleanup after each test.

  2. Fixed db assertion brittleness: Changed self.assertEqual(redis_init_kwargs['db'], '0') to self.assertEqual(int(redis_init_kwargs['db']), 0) to accept both string and numeric values, making the test less brittle to implementation changes.

All tests pass including the full edge case test suite (12/12 tests).

@ochui ochui merged commit b82003d into test/coverage Jan 26, 2026
@ochui ochui deleted the copilot/sub-pr-4 branch January 26, 2026 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants