test(UnitTest): handle early local HTTP requests - #14729
Conversation
03ee5b0 to
903cd28
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #14729 +/- ##
==========================================
+ Coverage 25.47% 32.65% +7.18%
==========================================
Files 769 783 +14
Lines 65912 67513 +1601
Branches 30495 31263 +768
==========================================
+ Hits 16788 22047 +5259
+ Misses 37285 30606 -6679
- Partials 11839 14860 +3021
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
Build ResultsPlatform Status
All builds passed. Pre-commit
Pre-commit hooks: 0 passed, 0 failed, 0 skipped. Test Resultslinux-coverage-integration: 37 passed, 0 skipped Code Coverage
Artifact Sizes
Updated: 2026-07-28 13:13:00 UTC • Commit: e7bb8c4 • Triggered by: Android |
There was a problem hiding this comment.
Pull request overview
This PR improves the reliability of the TestFixtures::LocalHttpTestServer test infrastructure by ensuring already-buffered and fragmented HTTP request headers are fully accumulated before a response is sent, and adds a regression unit test covering the early/fragmented request scenario.
Changes:
- Adds
LocalHttpTestServerTestto validate that the server does not respond to an incomplete HTTP request header fragment. - Updates
LocalHttpTestServer::installRawResponderto consume already-buffered bytes and wait for\r\n\r\nbefore responding. - Registers the new unit test in the UnitTestFramework Tests CMake target.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| test/UnitTestFramework/Tests/LocalHttpTestServerTest.h | Adds a new UnitTest class for LocalHttpTestServer regression coverage. |
| test/UnitTestFramework/Tests/LocalHttpTestServerTest.cc | Implements a regression test that splits an HTTP header across writes and asserts no early response. |
| test/UnitTestFramework/Tests/CMakeLists.txt | Adds the new test sources and registers LocalHttpTestServerTest. |
| test/UnitTestFramework/Fixtures/LocalHttpTestServer.cc | Updates the raw responder to accumulate request data and respond only after the header terminator is received. |
| state->request.append(socket->readAll()); | ||
| if (!state->request.contains(QByteArrayLiteral("\r\n\r\n"))) { | ||
| if (state->request.size() > MAX_REQUEST_HEADER_SIZE) { | ||
| socket->disconnectFromHost(); | ||
| } | ||
| return; | ||
| } |
| #include <QtNetwork/QHostAddress> | ||
| #include <QtNetwork/QTcpSocket> | ||
| #include <QtTest/QSignalSpy> | ||
|
|
||
| #include "Fixtures/LocalHttpTestServer.h" | ||
|
|
||
| void LocalHttpTestServerTest::_testEarlyRequest() | ||
| { | ||
| TestFixtures::LocalHttpTestServer server; | ||
| QVERIFY(server.listen()); | ||
| server.installHttpResponder(QByteArrayLiteral("ready")); | ||
|
|
||
| QTcpSocket client; | ||
| client.connectToHost(QHostAddress::LocalHost, server.port()); | ||
| QVERIFY(client.waitForConnected(TestTimeout::mediumMs())); |
|
Review feedback from a Claude Fable review: Worth changing
Optional
For the record: the core fix is correct and well-tested — the fragmented-header regression test genuinely fails against the old single-shot responder, and the shared-state/lifetime handling ( |
|
Claude Fable review — assessment of the two Copilot inline comments: 1. IPv4/IPv6 bind mismatch in 2. Size bound enforced after |
Description
LocalHttpTestServerpreviously had two timing gaps:readyReadconnection was installedreadyReadcould contain only part of an HTTP request, causing the fixture to respond and close before the header was completeThe responder now consumes any already-buffered bytes, accumulates a bounded request header across
readyReadnotifications, and sends one response only after\r\n\r\narrives. The regression test deliberately splits the request header across two writes and verifies that the server does not answer the incomplete first fragment.This is test infrastructure only; application networking is unchanged.
Type of Change
Testing
Local checks on exact head
e7bb8c40f:git diff --checkExact PR head
e7bb8c40f2c179541f4efd91bcd2b51f26e91dfbpassed all reported QGC checks.Platforms Tested
Flight Stacks Tested
Not applicable: this changes a unit-test fixture only.
Screenshots
Not applicable; there is no UI change.
Checklist
Related Issues
This fixture correction remains independently reviewable. #14730 carries it as a test-infrastructure prerequisite because its camera-free MJPEG delivery test uses
installRawResponder.By submitting this pull request, I confirm that my contribution is made under the terms of the project's dual license (Apache 2.0 and GPL v3).