Skip to content

[TEST] Add NetworkGetRequest_test covering the offline / bad-URL paths (#9460) - #9532

Merged
timosachsenberg merged 1 commit into
OpenMS:developfrom
timosachsenberg:test/9460-networkgetrequest-test
Jun 17, 2026
Merged

timosachsenberg merged 1 commit into
OpenMS:developfrom
timosachsenberg:test/9460-networkgetrequest-test

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

What

Adds the missing NetworkGetRequest_test (and registers it in executables.cmake). NetworkGetRequest is the libcurl-backed synchronous HTTP GET that UpdateCheck delegates to; it had no class test.

The test pins the documented contract — run() never throws; failures surface via hasError()/getErrorString() — across the offline / bad-URL paths:

  • fresh instance → no error, empty response;
  • empty URL and http:// (scheme, no host) → libcurl URL-parse errors, exercised with no network access at all;
  • unresolvable host (…​.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);
  • reuse → a second 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):

Cover libcurl UpdateCheck … Test the offline/bad-URL path. Pass: NetworkGetRequest sets an error and does not throw.

(Network_test covers a different class — SYSTEM/Network.h's downloadFile — so there was a real gap.)

Test plan

Tests only — no production code changed. Verified locally: -fsyntax-only clean, CMake reconfigure to register the new target, full build green, test runs PASSED. The offline/malformed cases need no network; the .invalid case fails on local DNS resolution.

Part of #9460. Follows #9524, #9525, #9526, #9528, #9530, #9531.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Added comprehensive unit test coverage for network request functionality, including validation of successful instantiation, error handling across various failure scenarios (empty/malformed URLs, unresolvable hosts), and proper state management during operation and recovery.

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]>
@github-actions

Copy link
Copy Markdown
Contributor

@timosachsenberg The following names might be missing from the AUTHORS file:

  • Timo Sachsenberg

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

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

A new C++ unit test file for OpenMS::NetworkGetRequest is added, covering default construction state, safe teardown, and run() contract behavior under offline failure conditions (empty URL, malformed URL, unresolvable host). The test is registered in executables.cmake so it is included in the build system's test target.

Changes

NetworkGetRequest Unit Test

Layer / File(s) Summary
CMake registration and test harness setup
src/tests/class_tests/openms/executables.cmake, src/tests/class_tests/openms/source/NetworkGetRequest_test.cpp
NetworkGetRequest_test is added to system_executables_list; the test file includes required headers and asserts that a freshly constructed NetworkGetRequest has no error, empty response fields, and can be safely deleted.
run() contract and accessor tests
src/tests/class_tests/openms/source/NetworkGetRequest_test.cpp
Tests that run() does not throw for empty, malformed, or unresolvable URLs; asserts hasError() is true, getErrorString() is non-empty, and both response accessors are empty after each failure; verifies that rerunning with a new bad URL replaces prior state; accessor sections are marked NOT_TESTABLE with coverage provided indirectly.

🐇 A test for the network hops along,
With bad URLs to make errors strong.
Empty strings and hosts that won't resolve —
No throw, just errors, that's the resolve!
CMake now knows the test by name,
The rabbit wired it into the game. 🌐

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: adding a test file for NetworkGetRequest that covers offline and bad-URL scenarios, with specific reference to the relevant issue (#9460).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between aacd941 and c8be37e.

📒 Files selected for processing (2)
  • src/tests/class_tests/openms/executables.cmake
  • src/tests/class_tests/openms/source/NetworkGetRequest_test.cpp

Comment on lines +103 to +106
NetworkGetRequest req;
req.setUrl("");
req.run();
TEST_EQUAL(req.hasError(), true)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

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.

Suggested change
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 timosachsenberg left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

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

@timosachsenberg
timosachsenberg merged commit 3c54b47 into OpenMS:develop Jun 17, 2026
41 checks passed
@timosachsenberg timosachsenberg mentioned this pull request Jun 17, 2026
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.

1 participant