Build the HostDB pending test in the hostdb directory The test is for HostDB internals, so it belongs with the other HostDB unit tests. A link group resolves the references between HostDB, the net layer and the proxy libraries on Linux.
diff --git a/src/iocore/hostdb/unit_tests/CMakeLists.txt b/src/iocore/hostdb/unit_tests/CMakeLists.txt index 8e14474..bc93241 100644 --- a/src/iocore/hostdb/unit_tests/CMakeLists.txt +++ b/src/iocore/hostdb/unit_tests/CMakeLists.txt
@@ -35,3 +35,65 @@ # test_RefCountCache has its own main() and uses no Catch2 at all, so it cannot be # split into per-case ctest entries. add_test(NAME test_hostdb_RefCountCache COMMAND $<TARGET_FILE:test_RefCountCache>) + +# test_HostDBPending +# HostDB, the net layer and the proxy libraries refer to each other, so the link needs a group. +add_executable(test_HostDBPending test_HostDBPending.cc) +target_include_directories(test_HostDBPending PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/..") +set(HOSTDB_LINK_GROUP_LIBS + ts::logging + ts::inknet + ts::inkhostdb + ts::proxy + ts::tsapibackend + ts::inkdns + ts::http2 + ts::inkcache + ts::rpcpublichandlers + ts::overridable_txn_vars + ts::http + ts::http_remap +) +if(TS_USE_QUIC OR TS_USE_QMUX) + list(APPEND HOSTDB_LINK_GROUP_LIBS quic http3) + if(TS_HAS_QUICHE) + list(APPEND HOSTDB_LINK_GROUP_LIBS quiche::quiche) + endif() +endif() +if(TS_USE_QMUX) + list(APPEND HOSTDB_LINK_GROUP_LIBS qmux) +endif() +if(CMAKE_LINK_GROUP_USING_RESCAN_SUPPORTED OR CMAKE_CXX_LINK_GROUP_USING_RESCAN_SUPPORTED) + string(JOIN "," HOSTDB_LINK_GROUP_LIBS_CSV ${HOSTDB_LINK_GROUP_LIBS}) + target_link_libraries( + test_HostDBPending PRIVATE Catch2::Catch2WithMain ts::tscore "$<LINK_GROUP:RESCAN,${HOSTDB_LINK_GROUP_LIBS_CSV}>" + ts::tsutil ts::inkevent configmanager + ) +elseif(APPLE) + target_link_libraries( + test_HostDBPending + PRIVATE + Catch2::Catch2WithMain + ts::inkhostdb + ts::inknet + ts::proxy + ts::tscore + ts::tsutil + ts::inkevent + configmanager + ) +else() + target_link_libraries( + test_HostDBPending + PRIVATE + Catch2::Catch2WithMain + ts::tscore + -Wl,--start-group + ${HOSTDB_LINK_GROUP_LIBS} + -Wl,--end-group + ts::tsutil + ts::inkevent + configmanager + ) +endif() +add_catch2_test(NAME test_hostdb_pending COMMAND $<TARGET_FILE:test_HostDBPending>)
diff --git a/src/iocore/hostdb/unit_tests/test_HostDBPending.cc b/src/iocore/hostdb/unit_tests/test_HostDBPending.cc index 5d50f46..d0fd5c0 100644 --- a/src/iocore/hostdb/unit_tests/test_HostDBPending.cc +++ b/src/iocore/hostdb/unit_tests/test_HostDBPending.cc
@@ -22,13 +22,37 @@ */ #include "P_HostDB.h" +#include "records/RecordsConfig.h" +#include "tscore/Layout.h" + +#include "iocore/utils/diags.i" #include <catch2/catch_test_macros.hpp> +#include <catch2/reporters/catch_reporter_event_listener.hpp> +#include <catch2/reporters/catch_reporter_registrars.hpp> extern ClassAllocator<HostDBContinuation, false> hostDBContAllocator; namespace { +struct HostDBListener : Catch::EventListenerBase { + using EventListenerBase::EventListenerBase; + + void + testRunStarting(Catch::TestRunInfo const &) override + { + Layout::create(); + init_diags("", nullptr); + RecProcessInit(); + LibRecordsConfigInit(); + ink_event_system_init(EVENT_SYSTEM_MODULE_PUBLIC_VERSION); + (new EThread)->set_specific(); + hostDB.refcountcache = new RefCountCache<HostDBRecord>(1); + hostDB.pending_dns = new Queue<HostDBContinuation, Continuation::Link_link>[1]; + } +}; +CATCH_REGISTER_LISTENER(HostDBListener); + struct Client : Continuation { int callbacks = 0; @@ -70,11 +94,6 @@ TEST_CASE("A pending DNS waiter calls back one time on a timeout", "[hostdb]") { - if (hostDB.refcountcache == nullptr) { - hostDB.refcountcache = new RefCountCache<HostDBRecord>(1); - hostDB.pending_dns = new Queue<HostDBContinuation, Continuation::Link_link>[1]; - } - Client owner_client; Client client; HostDBContinuation *owner = queue_lookup(&owner_client);
diff --git a/src/proxy/http/unit_tests/CMakeLists.txt b/src/proxy/http/unit_tests/CMakeLists.txt index ae784d8..4e799bc 100644 --- a/src/proxy/http/unit_tests/CMakeLists.txt +++ b/src/proxy/http/unit_tests/CMakeLists.txt
@@ -19,7 +19,6 @@ test_http main.cc "${PROJECT_SOURCE_DIR}/src/iocore/cache/unit_tests/stub.cc" - "${PROJECT_SOURCE_DIR}/src/iocore/hostdb/unit_tests/test_HostDBPending.cc" test_ChunkedHandler.cc test_ConnectingEntry.cc test_error_page_selection.cc @@ -33,8 +32,6 @@ test_ServerSessionPool.cc ) -target_include_directories(test_http PRIVATE "${PROJECT_SOURCE_DIR}/src/iocore/hostdb") - target_link_libraries( test_http PRIVATE