Skip to content

Commit

Permalink
Fix the http UT failures
Browse files Browse the repository at this point in the history
  • Loading branch information
Pichi committed Mar 24, 2020
1 parent 136ec99 commit 2916bd5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions cmake/ProcessOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ if (STATIC_LINK)
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib)
endif ()
set(Boost_USE_STATIC_LIBS ON)
else ()
add_definitions(-DBOOST_ALL_DYN_LINK)
endif ()

# Using rpath for dynamic linking
Expand Down
18 changes: 14 additions & 4 deletions src/net/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,20 @@ template <typename Stream> void HttpIngress<Stream>::disconnect(exception_ptr ep
}
catch (sys::system_error const& e) {
// TODO classify these errors
static auto const& HTTP_ERROR_CATEGORY =
http::make_error_code(http::error::end_of_stream).category();
rep.result(e.code().category() == HTTP_ERROR_CATEGORY ? http::status::bad_request :
http::status::gateway_timeout);

/* TODO It's not clear that http::make_error_code() will return error codes with different
* categories when its invoker are located in the different DLLs. As the result,
* the pre-defined category will never equal to what comes from Boost.Test.
* The downcasting at runtime has to be used to detect the equation here.
*
* The original code:
* static auto const& HTTP_ERROR_CATEGORY =
* http::make_error_code(http::error::end_of_stream).category();
*/

using CategoryPtr = http::detail::http_error_category const*;
auto pCat = dynamic_cast<CategoryPtr>(&e.code().category());
rep.result(pCat ? http::status::bad_request : http::status::gateway_timeout);
}
auto ec = sys::error_code{};
// Ignoring all errors here
Expand Down
3 changes: 0 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ set(HTTP_TESTS http)
set(SS_TESTS ss)
set(BALANCER_TESTS balancer)

if (NOT STATIC_LINK)
add_definitions(-DBOOST_TEST_DYN_LINK)
endif ()
link_libraries(${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_CONTEXT_LIBRARY})

configure_file(geo.mmdb ${CMAKE_CURRENT_BINARY_DIR}/geo.mmdb COPYONLY)
Expand Down

0 comments on commit 2916bd5

Please sign in to comment.