Repository navigation
[TEST] Add NetworkGetRequest_test covering the offline / bad-URL paths (#9460) - #9532
Conversation
OpenMS#9460) NetworkGetRequest (the libcurl HTTP GET used by UpdateCheck) had no class test. This adds one, focused on the contract that run() never throws and reports failures via hasError()/getErrorString(): - fresh instance: no error, empty response - empty URL and "http://" (no host): libcurl URL-parse errors, no network needed - unresolvable ".invalid" host (RFC 6761 reserved): a transport error (CURLE_COULDNT_RESOLVE_HOST) without depending on any reachable server - reuse: a second run() replaces the prior error/response state All cases assert no exception is thrown and an error is set. Registered in executables.cmake (system_executables_list). Verified: builds clean and the test runs PASSED. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
@timosachsenberg The following names might be missing from the
Please consider applying the following patch: --- AUTHORS 2026-06-15 15:46:36.708708599 +0000
+++ AUTHORS.new 2026-06-15 15:46:41.819648315 +0000
@@ -23,8 +23,8 @@
- Chirag Dave
- Chris Bauer
- Chris Bielow
- - Christie Mathews
- Christian Ehrlich
+ - Christie Mathews
- Clemens Groepl
- Cornelia Friedle
- Daniel Jameson |
📝 WalkthroughWalkthroughA new C++ unit test file for ChangesNetworkGetRequest Unit Test
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/tests/class_tests/openms/source/NetworkGetRequest_test.cpp`:
- Around line 103-106: The call to req.run() on line 105 is missing an explicit
no-throw assertion that is used elsewhere in the test to verify the documented
contract. Add a no-throw assertion wrapper around the req.run() call to
explicitly verify that the method does not throw an exception when given an
empty URL, making this test path consistent with the pattern used in other test
cases within this file.
🪄 Autofix (Beta)
❌ Autofix failed (check again to retry)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: fd2dc61b-343c-4d78-a7e1-0e68d9e1409d
📒 Files selected for processing (2)
src/tests/class_tests/openms/executables.cmakesrc/tests/class_tests/openms/source/NetworkGetRequest_test.cpp
| NetworkGetRequest req; | ||
| req.setUrl(""); | ||
| req.run(); | ||
| TEST_EQUAL(req.hasError(), true) |
There was a problem hiding this comment.
Add an explicit no-throw assertion for the first reuse call.
Line 105 calls req.run() without the no-throw check used elsewhere, so this path does not explicitly verify the documented contract in this sub-case.
Proposed fix
{
NetworkGetRequest req;
req.setUrl("");
- req.run();
+ bool threw = false;
+ try { req.run(); } catch (...) { threw = true; }
+ TEST_EQUAL(threw, false)
TEST_EQUAL(req.hasError(), true)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| NetworkGetRequest req; | |
| req.setUrl(""); | |
| req.run(); | |
| TEST_EQUAL(req.hasError(), true) | |
| NetworkGetRequest req; | |
| req.setUrl(""); | |
| bool threw = false; | |
| try { req.run(); } catch (...) { threw = true; } | |
| TEST_EQUAL(threw, false) | |
| TEST_EQUAL(req.hasError(), true) |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/tests/class_tests/openms/source/NetworkGetRequest_test.cpp` around lines
103 - 106, The call to req.run() on line 105 is missing an explicit no-throw
assertion that is used elsewhere in the test to verify the documented contract.
Add a no-throw assertion wrapper around the req.run() call to explicitly verify
that the method does not throw an exception when given an empty URL, making this
test path consistent with the pattern used in other test cases within this file.
timosachsenberg
left a comment
There was a problem hiding this comment.
I found one test flakiness risk in the network error coverage.
| // reachable server. The short timeout keeps it fast on slow-DNS hosts. | ||
| { | ||
| NetworkGetRequest req; | ||
| req.setUrl("http://openms-nonexistent-host.invalid/resource"); |
There was a problem hiding this comment.
This unit test now depends on real DNS/proxy/network behavior. Although .invalid is reserved, the request still goes through the host resolver and possibly corporate proxy configuration, which can be slow or produce different errors/timeouts across CI environments. Please use a deterministic local fixture/mock for the transport-error path, or isolate this as a network-dependent test instead of a normal class test.
|
Note Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it. An unexpected error occurred while generating fixes: Not Found - https://docs.github.com/rest/git/refs#get-a-reference |
What
Adds the missing
NetworkGetRequest_test(and registers it inexecutables.cmake).NetworkGetRequestis the libcurl-backed synchronous HTTP GET thatUpdateCheckdelegates to; it had no class test.The test pins the documented contract —
run()never throws; failures surface viahasError()/getErrorString()— across the offline / bad-URL paths:http://(scheme, no host) → libcurl URL-parse errors, exercised with no network access at all;….invalid, an RFC 6761-reserved TLD that always fails name resolution) → a libcurl transport error (CURLE_COULDNT_RESOLVE_HOST) without depending on any reachable server (5 s timeout keeps it fast);run()replaces the prior error/response state rather than accumulating it.Every case asserts no exception is thrown and an error is reported.
Why
Closes the §1 (Qt removal:
Qt6::Network → libcurl)[AUTO]task in the OpenMS 3.6.0 pre-release testing plan (#9460):(
Network_testcovers a different class —SYSTEM/Network.h'sdownloadFile— so there was a real gap.)Test plan
Tests only — no production code changed. Verified locally:
-fsyntax-onlyclean, CMake reconfigure to register the new target, full build green, test runs PASSED. The offline/malformed cases need no network; the.invalidcase fails on local DNS resolution.Part of #9460. Follows #9524, #9525, #9526, #9528, #9530, #9531.
🤖 Generated with Claude Code
Summary by CodeRabbit