diff --git a/.githooks/readme-template.md b/.githooks/readme-template.md index 73405b0..f3c1d3e 100644 --- a/.githooks/readme-template.md +++ b/.githooks/readme-template.md @@ -2,7 +2,6 @@ [![CI](https://github.com/jbaldwin/liblifthttp/workflows/build/badge.svg)](https://github.com/jbaldwin/liblifthttp/workflows/build/badge.svg) [![Coverage Status](https://coveralls.io/repos/github/jbaldwin/liblifthttp/badge.svg?branch=master)](https://coveralls.io/github/jbaldwin/liblifthttp?branch=master) -[![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/jbaldwin/liblifthttp.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/jbaldwin/liblifthttp/context:cpp) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/2625260f88524abfa2c2974ad9328e45)](https://www.codacy.com/gh/jbaldwin/liblifthttp/dashboard?utm_source=github.com&utm_medium=referral&utm_content=jbaldwin/liblifthttp&utm_campaign=Badge_Grade) [![language][badge.language]][language] [![license][badge.license]][license] @@ -116,8 +115,8 @@ target_link_libraries(${PROJECT_NAME} PUBLIC lifthttp) #### Running Tests The tests are automatically run by GitHub Actions on all Pull Requests. They can also be ran locally with a default -localhost instance of `nginx`. To do so the CMake option `LIFT_LOCALHOST_TESTS=ON` must be set otherwise the tests -will use the hostname `nginx` setup in the CI settings. After building and starting `nginx` tests can be run by issuing: +localhost instance of `nginx` and `haproxy`. To do so the CMake option `LIFT_LOCALHOST_TESTS=ON` must be set otherwise the tests +will use the hostname `nginx` setup in the CI settings. After building and starting `nginx` and `haproxy` tests can be run by issuing: ```bash # Invoke via cmake: @@ -127,8 +126,10 @@ ctest -v ./test/liblifthttp_tests ``` -Note there are now proxy http requests that utilize an `haproxy` instance. To run these locally you will also need -to start an instance of `haproxy`. +Note: +* `nginx` should be default install/configuration running on port `80`. +* `haproxy` should be running on port `*3128` with a backend pointing at the `nginx` instance. See `docker/build/haproxy/haproxy.cfg` to update the local configuration. + ### Benchmarks Using the example benchmark code and a local `nginx` instance serving its default welcome page. All benchmarks use `keep-alive` connections. The benchmark is compared against `wrk` as that is basically optimal performance since @@ -169,7 +170,7 @@ Using `nginx` as the webserver with the default `fedora` configuration. File bug reports, feature requests and questions using [GitHub Issues](https://github.com/jbaldwin/liblifthttp/issues) -Copyright © 2017-2022, Josh Baldwin +Copyright © 2017-2023, Josh Baldwin [badge.language]: https://img.shields.io/badge/language-C%2B%2B17-yellow.svg [badge.license]: https://img.shields.io/badge/license-Apache--2.0-blue diff --git a/README.md b/README.md index 5a819e8..2f0d800 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ [![CI](https://github.com/jbaldwin/liblifthttp/workflows/build/badge.svg)](https://github.com/jbaldwin/liblifthttp/workflows/build/badge.svg) [![Coverage Status](https://coveralls.io/repos/github/jbaldwin/liblifthttp/badge.svg?branch=master)](https://coveralls.io/github/jbaldwin/liblifthttp?branch=master) -[![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/jbaldwin/liblifthttp.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/jbaldwin/liblifthttp/context:cpp) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/2625260f88524abfa2c2974ad9328e45)](https://www.codacy.com/gh/jbaldwin/liblifthttp/dashboard?utm_source=github.com&utm_medium=referral&utm_content=jbaldwin/liblifthttp&utm_campaign=Badge_Grade) [![language][badge.language]][language] [![license][badge.license]][license] @@ -199,8 +198,8 @@ target_link_libraries(${PROJECT_NAME} PUBLIC lifthttp) #### Running Tests The tests are automatically run by GitHub Actions on all Pull Requests. They can also be ran locally with a default -localhost instance of `nginx`. To do so the CMake option `LIFT_LOCALHOST_TESTS=ON` must be set otherwise the tests -will use the hostname `nginx` setup in the CI settings. After building and starting `nginx` tests can be run by issuing: +localhost instance of `nginx` and `haproxy`. To do so the CMake option `LIFT_LOCALHOST_TESTS=ON` must be set otherwise the tests +will use the hostname `nginx` setup in the CI settings. After building and starting `nginx` and `haproxy` tests can be run by issuing: ```bash # Invoke via cmake: @@ -210,8 +209,10 @@ ctest -v ./test/liblifthttp_tests ``` -Note there are now proxy http requests that utilize an `haproxy` instance. To run these locally you will also need -to start an instance of `haproxy`. +Note: +* `nginx` should be default install/configuration running on port `80`. +* `haproxy` should be running on port `*3128` with a backend pointing at the `nginx` instance. See `docker/build/haproxy/haproxy.cfg` to update the local configuration. + ### Benchmarks Using the example benchmark code and a local `nginx` instance serving its default welcome page. All benchmarks use `keep-alive` connections. The benchmark is compared against `wrk` as that is basically optimal performance since @@ -252,7 +253,7 @@ Using `nginx` as the webserver with the default `fedora` configuration. File bug reports, feature requests and questions using [GitHub Issues](https://github.com/jbaldwin/liblifthttp/issues) -Copyright © 2017-2022, Josh Baldwin +Copyright © 2017-2023, Josh Baldwin [badge.language]: https://img.shields.io/badge/language-C%2B%2B17-yellow.svg [badge.license]: https://img.shields.io/badge/license-Apache--2.0-blue diff --git a/test/test_proxy.cpp b/test/test_proxy.cpp index bf984e0..130d2e0 100644 --- a/test/test_proxy.cpp +++ b/test/test_proxy.cpp @@ -18,7 +18,7 @@ TEST_CASE("proxy") { if (header.name() == "server") { - REQUIRE(header.value() == "nginx/1.22.1"); + REQUIRE(header.value().substr(0, 6) == "nginx/"); } else if (header.name() == "content-length") { @@ -51,7 +51,7 @@ TEST_CASE("proxy Basic Auth") { if (header.name() == "server") { - REQUIRE(header.value() == "nginx/1.22.1"); + REQUIRE(header.value().substr(0, 6) == "nginx/"); } else if (header.name() == "content-length") { @@ -84,7 +84,7 @@ TEST_CASE("proxy Any Auth") { if (header.name() == "server") { - REQUIRE(header.value() == "nginx/1.22.1"); + REQUIRE(header.value().substr(0, 6) == "nginx/"); } else if (header.name() == "content-length") { diff --git a/test/test_timesup.cpp b/test/test_timesup.cpp index d000069..2e62dd1 100644 --- a/test/test_timesup.cpp +++ b/test/test_timesup.cpp @@ -11,7 +11,7 @@ TEST_CASE("Timesup single request") auto r = std::make_unique( "http://www.reddit.com", // should be slow enough /shrug - std::chrono::milliseconds{25}); + std::chrono::milliseconds{5}); client.start_request( std::move(r), @@ -19,30 +19,33 @@ TEST_CASE("Timesup single request") { REQUIRE(response.lift_status() == lift::lift_status::timeout); REQUIRE(response.status_code() == lift::http::status_code::http_504_gateway_timeout); - REQUIRE(response.total_time() == std::chrono::milliseconds{25}); + REQUIRE(response.total_time() == std::chrono::milliseconds{5}); REQUIRE(response.num_connects() == 0); REQUIRE(response.num_redirects() == 0); }); } -TEST_CASE("Timesup two requests") -{ - lift::client client{lift::client::options{.connect_timeout = std::chrono::seconds{1}}}; +// TEST_CASE("Timesup two requests") +// { +// // TODO: This test requires a re-work with a proper "timeout" endpoint in nginx. It does not work against random +// // urls consistently. - std::vector requests{}; +// lift::client client{lift::client::options{.connect_timeout = std::chrono::seconds{1}}}; - auto callback = [](std::unique_ptr rh, lift::response response) -> void - { - REQUIRE(response.lift_status() == lift::lift_status::timeout); - REQUIRE(response.status_code() == lift::http::status_code::http_504_gateway_timeout); - REQUIRE( - (response.total_time() == std::chrono::milliseconds{25} || - response.total_time() == std::chrono::milliseconds{50})); - }; +// std::vector requests{}; - // should be slow enough /shrug - requests.push_back(std::make_unique("http://www.reddit.com", std::chrono::milliseconds{25})); - requests.push_back(std::make_unique("http://www.reddit.com", std::chrono::milliseconds{50})); +// auto callback = [](std::unique_ptr rh, lift::response response) -> void +// { +// REQUIRE(response.lift_status() == lift::lift_status::timeout); +// REQUIRE(response.status_code() == lift::http::status_code::http_504_gateway_timeout); +// REQUIRE( +// (response.total_time() == std::chrono::milliseconds{5} || +// response.total_time() == std::chrono::milliseconds{10})); +// }; - client.start_requests(std::move(requests)); -} +// // should be slow enough /shrug +// requests.push_back(std::make_unique("http://www.old.reddit.com", std::chrono::milliseconds{5})); +// requests.push_back(std::make_unique("http://www.old.reddit.com", std::chrono::milliseconds{10})); + +// client.start_requests(std::move(requests), callback); +// }