refactor: Minor improvements to HTTP unit tests #36160

pull hodlinator wants to merge 2 commits into bitcoin:master from hodlinator:2026/09/improve_http_tests changing 1 files +72 −71
  1. hodlinator commented at 10:41 AM on September 3, 2026: contributor

    Improves recently added unit tests.

    • Simplify HTTP response check in http_server_socket_tests, is was incorrectly referring to unordered_map
    • Make http_request_state_tests unit test method use Uppercase as per developer-notes.md, shorten enum values for readibility
  2. refactor(test): Simplify HTTP response check
    During the development of the new HTTP server, the headers where initially stored in an unordered_map, but later it was changed to a vector.
    8b1c375a85
  3. refactor(test): Make test method use Uppercase, shorten enum values
    The former conforms to developer-notes.md, the latter increase readability.
    e69331c329
  4. DrahtBot added the label Refactoring on Sep 3, 2026
  5. DrahtBot commented at 10:41 AM on September 3, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/36160.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    Concept ACK janb84

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  6. fanquake requested review from pinheadmz on Sep 3, 2026
  7. in src/test/httpserver_tests.cpp:888 in e69331c329
     891 | -    BOOST_CHECK(actual.find("Date: Wed, 11 Dec 2024 00:47:09 GMT\r\n") != std::string::npos);
     892 | +    BOOST_CHECK_EQUAL(actual, "HTTP/1.1 200 OK\r\n"
     893 | +                              "Date: Wed, 11 Dec 2024 00:47:09 GMT\r\n"
     894 | +                              "Content-Length: 7\r\n"
     895 | +                              "Content-Type: text/html; charset=ISO-8859-1\r\n"
     896 | +                              "Connection: close\r\n"
    


    janb84 commented at 8:12 PM on September 3, 2026:

    NIT: Although the suggested code in the PR is already a great improvement, I would suggest to hoist the expected string to the top. This remove some magic numbers (the reserve of 146 bytes with 10ms sleep is redundant) and the actual.length can be compared with the expected.length. And removes some risk of code drift (between the loop and expectation)

        const std::string expected{"HTTP/1.1 200 OK\r\n"
                                   "Date: Wed, 11 Dec 2024 00:47:09 GMT\r\n"
                                   "Content-Length: 7\r\n"
                                   "Content-Type: text/html; charset=ISO-8859-1\r\n"
                                   "Connection: close\r\n"
                                   "\r\n874140\n"};
        std::string actual;
        // Wait up to one minute for all the bytes to appear in the "send" pipe.
        char buf[0x10000] = {};
        attempts = 6000;
        while (attempts > 0)
        {
            ssize_t bytes_read = mock_client_socket_pipes->send.GetBytes(buf, sizeof(buf), 0);
            if (bytes_read > 0) {
                actual.append(buf, bytes_read);
                if (actual.length() >= expected.length()) {
                    break;
                }
            }
            std::this_thread::sleep_for(10ms);
            --attempts;
        }
        BOOST_CHECK_EQUAL(actual, expected);
    
  8. janb84 commented at 8:15 PM on September 3, 2026: contributor

    Concept ACK e69331c329877f824ac06a92b00abff116125bad

    Great improvement in readability! using enum matches the existing usage in the other files.

    Found some typo's in the commit messages: In commit message of 8b1c375a85a36118388e88c56bdc2b8543c7fc4f where -> were In commit message of 'e69331c329877f824ac06a92b00abff116125bad' incresae -> increases


pinheadmz


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-09-04 08:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me