fix compile error #4

Merged
tqcq merged 13 commits from feat/support_fiber into master 2024-07-08 17:53:24 +08:00
2 changed files with 46 additions and 4 deletions
Showing only changes of commit 8238c310f6 - Show all commits

View File

@ -268,17 +268,21 @@ if(TILE_BUILD_TESTS)
add_executable(tile_test_all "tile/testing/main.cc")
target_link_libraries(tile_test_all PRIVATE gtest gmock tile::tile)
macro(tile_add_test test_name test_file)
macro(tile_add_custom_test test_name test_file)
add_executable(${test_name} ${test_file} "tile/testing/main.cc")
target_link_libraries(
${test_name} PUBLIC gtest gmock ${WHOLE_ARCHIVE_PREFIX} tile::tile
${WHOLE_ARCHIVE_SUFFIX})
add_test(NAME ${test_name} COMMAND ${test_name})
target_sources(${PROJECT_NAME}_test_all PRIVATE ${test_file})
endmacro()
macro(tile_add_test test_name test_file)
tile_add_custom_test(${test_name} ${test_file})
add_test(NAME ${test_name} COMMAND ${test_name})
endmacro()
tile_add_test(fiber_detail_scheduler_test "tile/fiber/detail/scheduler_test.cc")
tile_add_test(base_internal_meta_test "tile/base/internal/meta_test.cc")
# tile_add_test(net_internal_http_engine_test
@ -348,7 +352,7 @@ tile_add_test(fiber_detail_scheduler_test "tile/fiber/detail/scheduler_test.cc")
tile_add_test(base_internal_logging_test "tile/base/internal/logging_test.cc")
tile_add_test(base_chrono_test "tile/base/chrono_test.cc")
tile_add_test(init_override_flag_test "tile/init/override_flag_test.cc")
# tile_add_test("custom_http_client_test" "tests/http_client_test.cc")
tile_add_custom_test("custom_http_client_test" "tests/http_client_test.cc")
# tile_add_test(base_internal_time_keeper_test
# "tile/base/internal/time_keeper_test.cc")
endif(TILE_BUILD_TESTS)

View File

@ -2,6 +2,8 @@
#include "gtest/gtest.h"
#include "tile/base/thread/latch.h"
const std::string url = "http://127.0.0.1:8000/";
TEST(HttpClient, Request) {
@ -45,3 +47,39 @@ TEST(HttpClient, Request) {
}
}
}
TEST(HttpClient, RequestNoWait) {
tile::HttpClient client;
tile::HttpClient::RequestOptions options;
options.timeout = std::chrono::seconds(20);
int cnt = 0;
for (int i = 0; i != 1000; ++i) {
for (auto code : tile::AllHttpStatus) {
if (static_cast<int>(code) < 200) {
continue;
}
++cnt;
}
}
tile::Latch latch(cnt);
std::atomic<int> count{0};
for (int i = 0; i != 1000; ++i) {
for (auto code : tile::AllHttpStatus) {
if (static_cast<int>(code) < 200) {
continue;
}
client.AsyncGet(url + std::to_string(static_cast<int>(code)), options)
.Then([&](std::expected<tile::HttpResponse,
tile::HttpClient::ErrorCode> &&) {
int cnt = count.fetch_add(1) + 1;
TILE_LOG_INFO_EVERY_SECOND("complete {}", cnt);
latch.CountDown();
});
}
}
latch.Wait();
}