shivvani-r opened a new pull request, #15986: URL: https://github.com/apache/dubbo/pull/15986
## What is the purpose of the change This PR addresses **[Issue #15935](https://github.com/apache/dubbo/issues/15935)** by significantly enhancing the unit test coverage for the `NetUtils` class. Prior to this change, several critical logic branches in `NetUtils` were untested, including: 1. **Safety Guard Clauses:** The null checks in `matchIpRange` were never triggered, risking silent failures if removed. 2. **Complex Matching Logic:** The logic handling zero-padded IP segments (e.g., matching `00` against `0`) in `matchIpRange` was dead code during testing. 3. **Resource Management:** `isPortInUsed` was only tested for free ports (returning `false`), never verifying it could correctly detect a busy port (returning `true`). 4. **Boundary Conditions:** Multicast address detection lacked checks for exact boundary values (`224.0.0.0` and `239.255.255.255`). This PR fills these gaps, achieving 100% logic coverage for `matchIpRange` and `isValidV4Address`, and improving the reliability of network utility methods. ## Brief changelog **Modified Existing Tests:** * **`testValidAddress`**: Added strict negative cases for invalid formats (e.g., `127.0.0.0.1`, `127.0.0.-1`). * **`testIsValidAddress`**: Added coverage for `isLinkLocalAddress` (169.254.x.x) and fixed a test bug where mocks were not reset between assertions. * **`testToAddress`**: Added validation to ensure invalid port formats throw `NumberFormatException`. * **`testIsMulticastAddress`**: Added boundary checks for `224.0.0.0` and `239.255.255.255` to prevent off-by-one errors. **Added New Tests:** * **`testMatchIpRange_NullInputs`**: Verifies that passing `null` inputs throws `IllegalArgumentException`. * **`testMatchIpRange_ZeroPadding`**: Verifies logic for zero-padded IP segments (e.g., matching `00` against `0`). * **`testIsPortInUsed_True`**: Verified that `isPortInUsed` correctly identifies a busy port (positive case). * **`testIsIPV6URLStdFormat`**: Added validation for standard IPv6 URL formats. * **`testGetLegalIP`**: Added verification for extracting legal IPs from various IPv6/IPv4 strings. * **`testGetLocalHostName`**: Added smoke test for local hostname retrieval. * **`testGetLocalHostV6`**: Added smoke test for local IPv6 address retrieval. * **`testIsReuseAddressSupported`**: Added verification for environment support of `SO_REUSEADDR`. ## Verifying this change This change can be verified by running the specific unit test suite for `dubbo-common`: ```bash ./mvnw -Dtest=NetUtilsTest test -pl dubbo-common ## What is the purpose of the change? ## Checklist - [x] Make sure there is a [GitHub_issue](https://github.com/apache/dubbo/issues) field for the change. - [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why. - [x] Write necessary unit-test to verify your logic correction. If the new feature or significant change is committed, please remember to add sample in [dubbo samples](https://github.com/apache/dubbo-samples) project. - [x] Make sure gitHub actions can pass. [Why the workflow is failing and how to fix it?](../CONTRIBUTING.md) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
