Skip to content

Conversation

@WangzJi
Copy link
Contributor

@WangzJi WangzJi commented Nov 12, 2025

Ⅰ. Describe what this PR did

Ⅱ. Does this pull request fix one issue?

Ⅲ. Why don't you add test cases (unit test/integration test)?

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

Added 35 new unit test cases for RaftRegistryServiceImpl class to improve
code coverage. Tests cover:

1. Core functionality:
   - Singleton pattern verification
   - Empty implementation methods (register/unregister/subscribe/unsubscribe)
   - Close method and CLOSED flag management
   - Endpoint selection with and without preferredNetworks

2. Authentication and token management:
   - Token refresh with success and failure scenarios
   - Token expiration checks
   - JWT token update verification

3. Metadata operations:
   - Cluster metadata acquisition (success and auth failure scenarios)
   - Metadata lookup with existing data
   - Alive lookup in Raft mode with leader
   - Query HTTP address with nodes

4. Endpoint selection:
   - Control and transaction endpoint selection
   - External endpoint selection with various edge cases:
     * Empty/null metadata
     * Empty external endpoint list
     * No matching network patterns
     * Successful matching with preferredNetworks
   - Endpoint creation and validation

5. Network preference matching:
   - Prefix pattern matching (10.10.*)
   - Regex pattern matching
   - Handling blank patterns

6. Configuration key methods:
   - Raft server address key
   - Username and password keys
   - Preferred networks configuration
   - Token expiration time key
   - Metadata max age key

7. Background operations:
   - Watch method for cluster changes
   - Alive lookup refresh in Raft mode

All test methods follow camelCase naming convention ending with "Test"
(e.g., loginFailedTest, getInstanceTest, selectEndpointTest).

Tests use Mockito for HTTP mocking and reflection to access private methods.
Proper cleanup is implemented in @AfterEach to reset CLOSED flag between tests.

Fixed test failures by:
- Adjusting endpoint selection assertions for internal vs external addresses
- Setting up INIT_ADDRESSES to prevent NullPointerException
- Handling Map.put() return value behavior correctly
- Removing invalid "term" field from Node JSON test data
@WangzJi WangzJi force-pushed the claude/raft-registry-service-impl-011CV4AXp6GJAAkeRroKDAix branch from 4815a7f to 5817eba Compare November 12, 2025 15:56
@codecov
Copy link

codecov bot commented Nov 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.27%. Comparing base (78c275e) to head (77a732e).

Additional details and impacted files
@@             Coverage Diff              @@
##                2.x    #7779      +/-   ##
============================================
+ Coverage     70.95%   71.27%   +0.31%     
- Complexity      992     1042      +50     
============================================
  Files          1322     1322              
  Lines         50322    50322              
  Branches       5946     5946              
============================================
+ Hits          35705    35866     +161     
+ Misses        11670    11500     -170     
- Partials       2947     2956       +9     

see 8 files with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Enhanced tests for `RaftRegistryServiceImpl`:

- Improved assertions for endpoint selection methods.
- Added tests for null response, null status line, and unauthorized responses in the `watch` method.
- Reformatted and cleaned up test methods.
@WangzJi WangzJi marked this pull request as ready for review November 24, 2025 08:49
@WangzJi WangzJi added type: test test case module/discovery discovery module labels Nov 24, 2025
@WangzJi WangzJi added this to the 2.6.0 milestone Nov 24, 2025
@WangzJi WangzJi requested a review from maple525866 November 26, 2025 14:21
Copy link
Contributor

@lokidundun lokidundun left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@maple525866 maple525866 left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module/discovery discovery module type: test test case

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants