From c749e91aadda632776d5149b825204ff5c09f013 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Thu, 20 Jun 2024 21:27:54 +0800 Subject: [PATCH 1/7] feat update workflows --- .gitea/workflows/linux-aarch64-gcc.yml | 4 ++-- .gitea/workflows/linux-arm-gcc.yml | 8 ++++---- .gitea/workflows/linux-mips-gcc.yml | 4 ++-- .gitea/workflows/linux-mips64-gcc.yml | 4 ++-- .gitea/workflows/linux-riscv64-gcc.yml | 4 ++-- tile/init.cc | 4 +++- 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/.gitea/workflows/linux-aarch64-gcc.yml b/.gitea/workflows/linux-aarch64-gcc.yml index 3676172..cb9514b 100644 --- a/.gitea/workflows/linux-aarch64-gcc.yml +++ b/.gitea/workflows/linux-aarch64-gcc.yml @@ -53,6 +53,6 @@ jobs: - name: test run: |- cd build - sudo ln -sf /usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.1 /lib/ld-linux-aarch64.so.1 - export LD_LIBRARY_PATH=/usr/aarch64-linux-gnu/lib + # sudo ln -sf /usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.1 /lib/ld-linux-aarch64.so.1 + # export LD_LIBRARY_PATH=/usr/aarch64-linux-gnu/lib ctest --output-on-failure -j $(nproc) diff --git a/.gitea/workflows/linux-arm-gcc.yml b/.gitea/workflows/linux-arm-gcc.yml index 28ace26..24506b0 100644 --- a/.gitea/workflows/linux-arm-gcc.yml +++ b/.gitea/workflows/linux-arm-gcc.yml @@ -51,8 +51,8 @@ jobs: - name: test run: | cd build - sudo ln -sf /usr/arm-linux-gnueabi/lib/ld-linux.so.3 /lib/ld-linux.so.3 - export LD_LIBRARY_PATH=/usr/arm-linux-gnueabi/lib + #sudo ln -sf /usr/arm-linux-gnueabi/lib/ld-linux.so.3 /lib/ld-linux.so.3 + #export LD_LIBRARY_PATH=/usr/arm-linux-gnueabi/lib ctest --output-on-failure -j $(nproc) linux-gcc-armhf: @@ -79,6 +79,6 @@ jobs: - name: test run: |- cd build - sudo ln -sf /usr/arm-linux-gnueabihf/lib/ld-linux-armhf.so.3 /lib/ld-linux-armhf.so.3 - export LD_LIBRARY_PATH=/usr/arm-linux-gnueabihf/lib/ + # sudo ln -sf /usr/arm-linux-gnueabihf/lib/ld-linux-armhf.so.3 /lib/ld-linux-armhf.so.3 + #export LD_LIBRARY_PATH=/usr/arm-linux-gnueabihf/lib/ ctest --output-on-failure -j $(nproc) diff --git a/.gitea/workflows/linux-mips-gcc.yml b/.gitea/workflows/linux-mips-gcc.yml index e1ee3a0..3b191b3 100644 --- a/.gitea/workflows/linux-mips-gcc.yml +++ b/.gitea/workflows/linux-mips-gcc.yml @@ -48,6 +48,6 @@ jobs: - name: test run: |- cd build - sudo ln -sf /usr/mipsel-linux-gnu/lib/ld.so.1 /lib/ld.so.1 - export LD_LIBRARY_PATH=/usr/mipsel-linux-gnu/lib/ + # sudo ln -sf /usr/mipsel-linux-gnu/lib/ld.so.1 /lib/ld.so.1 + # export LD_LIBRARY_PATH=/usr/mipsel-linux-gnu/lib/ ctest --output-on-failure -j $(nproc) diff --git a/.gitea/workflows/linux-mips64-gcc.yml b/.gitea/workflows/linux-mips64-gcc.yml index 23a500f..96d82c5 100644 --- a/.gitea/workflows/linux-mips64-gcc.yml +++ b/.gitea/workflows/linux-mips64-gcc.yml @@ -49,6 +49,6 @@ jobs: - name: test run: |- cd build - sudo ln -sf /usr/mips64el-linux-gnuabi64/lib64/ld.so.1 /lib64/ld.so.1 - export LD_LIBRARY_PATH=/usr/mips64el-linux-gnuabi64/lib + # sudo ln -sf /usr/mips64el-linux-gnuabi64/lib64/ld.so.1 /lib64/ld.so.1 + # export LD_LIBRARY_PATH=/usr/mips64el-linux-gnuabi64/lib ctest --output-on-failure -j $(nproc) diff --git a/.gitea/workflows/linux-riscv64-gcc.yml b/.gitea/workflows/linux-riscv64-gcc.yml index 1c6566a..61a829b 100644 --- a/.gitea/workflows/linux-riscv64-gcc.yml +++ b/.gitea/workflows/linux-riscv64-gcc.yml @@ -50,6 +50,6 @@ jobs: - name: test run: |- cd build - sudo ln -sf /usr/riscv64-linux-gnu/lib/ld-linux-riscv64-lp64d.so.1 /lib/ld-linux-riscv64-lp64d.so.1 - export LD_LIBRARY_PATH=/usr/riscv64-linux-gnu/lib + # sudo ln -sf /usr/riscv64-linux-gnu/lib/ld-linux-riscv64-lp64d.so.1 /lib/ld-linux-riscv64-lp64d.so.1 + # export LD_LIBRARY_PATH=/usr/riscv64-linux-gnu/lib ctest --output-on-failure -j $(nproc) diff --git a/tile/init.cc b/tile/init.cc index e09ebb7..4afaccf 100644 --- a/tile/init.cc +++ b/tile/init.cc @@ -53,6 +53,7 @@ int Start(int argc, char **argv, std::function cb, google::InstallFailureSignalHandler(); } + gflags::SetVersionString("0.1.0"); gflags::ParseCommandLineFlags(&argc, &argv, true); detail::ApplyFlagOverrider(); @@ -88,8 +89,9 @@ int Start(int argc, char **argv, std::function cb, detail::RunAllFinalizers(); TerminateBasicRuntime(); - + gflags::ShutDownCommandLineFlags(); TILE_LOG_INFO("Exited"); + return rc; } -- 2.45.2 From 0c136e9e0c64584d8c44bfa19130ca59252d00b6 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Fri, 21 Jun 2024 00:23:31 +0800 Subject: [PATCH 2/7] feat update benchmark --- tile/fiber/detail/fiber_benchmark.cc | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/tile/fiber/detail/fiber_benchmark.cc b/tile/fiber/detail/fiber_benchmark.cc index 1b053a2..659b22e 100644 --- a/tile/fiber/detail/fiber_benchmark.cc +++ b/tile/fiber/detail/fiber_benchmark.cc @@ -1,3 +1,4 @@ +#include "tile/base/chrono.h" #include "tile/base/random.h" #include "tile/fiber/detail/fiber.h" @@ -7,7 +8,7 @@ namespace fiber { namespace detail { void Benchmark_FiberSwitch(benchmark::State &state) { - constexpr int kFiberCount = 10000; + constexpr int kFiberCount = 2 * 10000; std::unique_ptr master; std::unique_ptr worker[kFiberCount]; @@ -16,7 +17,22 @@ void Benchmark_FiberSwitch(benchmark::State &state) { master = Fiber::Create([&]() { while (state.KeepRunning()) { ++cnt; - worker[Random(kFiberCount - 1)]->Resume(); + auto &w1 = worker[Random(kFiberCount - 1)]; + auto &w2 = worker[Random(kFiberCount - 1)]; + auto start = ReadSteadyClock(); + w1->Resume(); + w2->Resume(); + w1->Resume(); + w2->Resume(); + w1->Resume(); + w2->Resume(); + w1->Resume(); + w2->Resume(); + auto end = ReadSteadyClock(); + auto duration = std::chrono::duration_cast>( + end - start) / + 8; + state.SetIterationTime(duration.count()); } cnt = -1; @@ -29,6 +45,9 @@ void Benchmark_FiberSwitch(benchmark::State &state) { worker[i] = Fiber::Create([&, i]() { while (cnt != -1) { master->Resume(); + master->Resume(); + master->Resume(); + master->Resume(); } }); } @@ -39,7 +58,7 @@ void Benchmark_FiberSwitch(benchmark::State &state) { master->Resume(); } -BENCHMARK(Benchmark_FiberSwitch); +BENCHMARK(Benchmark_FiberSwitch)->UseManualTime(); } // namespace detail } // namespace fiber } // namespace tile -- 2.45.2 From 2b69c377f7f37fc848e08dfb098a3e909276b2d0 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Fri, 28 Jun 2024 10:33:11 +0800 Subject: [PATCH 3/7] feat make_unique support deleter --- tile/base/make_unique.h | 25 ++++++++++++++++++++++++- tile/init.cc | 19 ++++++++++++++++--- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/tile/base/make_unique.h b/tile/base/make_unique.h index 6f1eaac..d6d270b 100644 --- a/tile/base/make_unique.h +++ b/tile/base/make_unique.h @@ -21,7 +21,7 @@ make_unique(Args &&...args) { template inline enable_if_t::value && std::extent::value == 0, std::unique_ptr> -make_unique(size_t size) { +make_unique(std::size_t size) { TILE_DCHECK(size > 0); using U = typename std::remove_extent::type; return std::unique_ptr(new U[size]()); @@ -34,6 +34,29 @@ enable_if_t::value && std::extent::value != 0, std::unique_ptr> make_unique(Args &&...) = delete; +// == With Deleter + +template +inline enable_if_t::value, std::unique_ptr> +make_unique_with_deleter(D &&deleter, Args &&...args) { + return std::unique_ptr(new T(std::forward(args)...), + std::forward(deleter)); +} + +template +inline enable_if_t::value && std::extent::value == 0, + std::unique_ptr> +make_unique_with_deleter(D &&deleter, std::size_t size) { + TILE_DCHECK(size > 0); + using U = typename std::remove_extent::type; + return std::unique_ptr(new U[size](), std::forward(deleter)); +} + +template +enable_if_t::value && std::extent::value != 0, + std::unique_ptr> +make_unique_with_deleter(D &&deleter, Args &&...) = delete; + } // namespace tile #endif // TILE_BASE_MAKE_UNIQUE_H diff --git a/tile/init.cc b/tile/init.cc index 4afaccf..e280072 100644 --- a/tile/init.cc +++ b/tile/init.cc @@ -53,18 +53,31 @@ int Start(int argc, char **argv, std::function cb, google::InstallFailureSignalHandler(); } + // Init gflags gflags::SetVersionString("0.1.0"); gflags::ParseCommandLineFlags(&argc, &argv, true); detail::ApplyFlagOverrider(); + auto gflags_handler = tile::make_unique_with_deleter( + [](void *) { gflags::ShutDownCommandLineFlags(); }); + // Init Glog google::InitGoogleLogging(argv[0]); + auto glog_handler = tile::make_unique_with_deleter( + [](void *) { google::ShutdownGoogleLogging(); }); TILE_LOG_INFO("Tile started."); TILE_PCHECK(signal(SIGPIPE, SIG_IGN) != SIG_ERR); + // Init BasicRuntime InitializeBasicRuntime(); + auto basic_runtime_handler = tile::make_unique_with_deleter( + [](void *) { TerminateBasicRuntime(); }); + + // Run all initializers detail::RunAllInitializers(); + auto initializers_handler = tile::make_unique_with_deleter( + [](void *) { detail::RunAllInitializers(); }); int rc = 0; @@ -87,9 +100,9 @@ int Start(int argc, char **argv, std::function cb, worker.join(); } - detail::RunAllFinalizers(); - TerminateBasicRuntime(); - gflags::ShutDownCommandLineFlags(); + // detail::RunAllFinalizers(); + // TerminateBasicRuntime(); + // gflags::ShutDownCommandLineFlags(); TILE_LOG_INFO("Exited"); return rc; -- 2.45.2 From 2780b81406991e36ab3713f61364b5f6b95f1baf Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Sat, 29 Jun 2024 16:03:42 +0800 Subject: [PATCH 4/7] feat add custom test --- CMakeLists.txt | 1 + tests/http_client_test.cc | 47 ++++++++++++++++++++++++++++++++++++ tests/http_server.py | 24 ++++++++++++++++++ tile/init.cc | 19 +++------------ tile/init/on_init.cc | 1 + tile/net/http/http_client.cc | 11 +++++++-- tile/net/http/http_client.h | 3 +++ tile/net/http/types.h | 22 +++++++++++++++++ 8 files changed, 110 insertions(+), 18 deletions(-) create mode 100644 tests/http_client_test.cc create mode 100644 tests/http_server.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a83176..9ccb6ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -348,6 +348,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_test(base_internal_time_keeper_test # "tile/base/internal/time_keeper_test.cc") endif(TILE_BUILD_TESTS) diff --git a/tests/http_client_test.cc b/tests/http_client_test.cc new file mode 100644 index 0000000..985050e --- /dev/null +++ b/tests/http_client_test.cc @@ -0,0 +1,47 @@ +#include "tile/net/http/http_client.h" + +#include "gtest/gtest.h" + +const std::string url = "http://127.0.0.1:8000/"; + +TEST(HttpClient, Request) { + tile::HttpClient client; + std::vector>> + v; + tile::HttpClient::RequestOptions options; + options.timeout = std::chrono::seconds(20); + + std::atomic count{0}; + + for (int i = 0; i != 1000; ++i) { + for (auto code : tile::AllHttpStatus) { + if (static_cast(code) < 200) { + continue; + } + + v.emplace_back( + client.AsyncGet(url + std::to_string(static_cast(code)), options) + .Then([&](std::expected &&res) { + int cnt = count.fetch_add(1) + 1; + TILE_LOG_INFO_EVERY_SECOND("complete {}", cnt); + return res; + })); + } + } + + int j = 0; + for (int i = 0; i != 1000; ++i) { + for (auto &code : tile::AllHttpStatus) { + if (static_cast(code) < 200) { + continue; + } + + auto resp = tile::future::BlockingGet(std::move(v[j++])); + + EXPECT_TRUE(resp) << tile::HttpClient::ErrorCodeToString(resp.error()); + EXPECT_EQ(resp->status(), code); + } + } +} diff --git a/tests/http_server.py b/tests/http_server.py new file mode 100644 index 0000000..446730c --- /dev/null +++ b/tests/http_server.py @@ -0,0 +1,24 @@ +#!/usr/bin/python3 +import http.server +import socket +import socketserver +from http.server import HTTPServer, BaseHTTPRequestHandler + +PORT = 8000 + +class Request(BaseHTTPRequestHandler): + def do_GET(self): + code = int(self.path.split("/")[1]) + + self.send_response(code) + self.send_header('Content-type', 'text/plain') + self.end_headers() + +class HTTPServer(socketserver.TCPServer): + def server_bind(self): + self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + self.socket.bind(self.server_address) + +Handler = http.server.SimpleHTTPRequestHandler +with HTTPServer(("", PORT), Request) as httpd: + httpd.serve_forever() diff --git a/tile/init.cc b/tile/init.cc index e280072..4afaccf 100644 --- a/tile/init.cc +++ b/tile/init.cc @@ -53,31 +53,18 @@ int Start(int argc, char **argv, std::function cb, google::InstallFailureSignalHandler(); } - // Init gflags gflags::SetVersionString("0.1.0"); gflags::ParseCommandLineFlags(&argc, &argv, true); detail::ApplyFlagOverrider(); - auto gflags_handler = tile::make_unique_with_deleter( - [](void *) { gflags::ShutDownCommandLineFlags(); }); - // Init Glog google::InitGoogleLogging(argv[0]); - auto glog_handler = tile::make_unique_with_deleter( - [](void *) { google::ShutdownGoogleLogging(); }); TILE_LOG_INFO("Tile started."); TILE_PCHECK(signal(SIGPIPE, SIG_IGN) != SIG_ERR); - // Init BasicRuntime InitializeBasicRuntime(); - auto basic_runtime_handler = tile::make_unique_with_deleter( - [](void *) { TerminateBasicRuntime(); }); - - // Run all initializers detail::RunAllInitializers(); - auto initializers_handler = tile::make_unique_with_deleter( - [](void *) { detail::RunAllInitializers(); }); int rc = 0; @@ -100,9 +87,9 @@ int Start(int argc, char **argv, std::function cb, worker.join(); } - // detail::RunAllFinalizers(); - // TerminateBasicRuntime(); - // gflags::ShutDownCommandLineFlags(); + detail::RunAllFinalizers(); + TerminateBasicRuntime(); + gflags::ShutDownCommandLineFlags(); TILE_LOG_INFO("Exited"); return rc; diff --git a/tile/init/on_init.cc b/tile/init/on_init.cc index 7f0fbfa..3ad04b0 100644 --- a/tile/init/on_init.cc +++ b/tile/init/on_init.cc @@ -83,6 +83,7 @@ void RegisterOnInitCallback(std::int32_t priority, std::function init, !registry_prepared.load(std::memory_order_relaxed), "Callbacks may only be registered before `tile::Start()` is called"); auto &®istry = *GetStagingRegistry(); + TILE_CHECK(init != nullptr, "Initializer must be provided"); registry[priority].push_back({std::move(init), std::move(fini)}); } diff --git a/tile/net/http/http_client.cc b/tile/net/http/http_client.cc index 924500a..ade386f 100644 --- a/tile/net/http/http_client.cc +++ b/tile/net/http/http_client.cc @@ -49,10 +49,15 @@ HttpClient::ErrorCode GetErrorCodeFromCurlCode(int c) { return HttpClient::ERROR_IO; case CURLE_TOO_MANY_REDIRECTS: return HttpClient::ERROR_TOO_MANY_REDIRECTS; - default: - TILE_LOG_WARNING_EVERY_SECOND("ERROR_UNKNOWN CURLcode {}", c); + case CURLE_GOT_NOTHING: + return HttpClient::ERROR_GET_NOTHING; + + default: { + TILE_LOG_WARNING_EVERY_SECOND("ERROR_UNKNOWN CURLcode {}, curl msg: ", c, + curl_easy_strerror(static_cast(c))); return HttpClient::ERROR_UNKNOWN; } + } } long TileHttpVersionToCurlHttpVersion(HttpVersion v, @@ -446,6 +451,8 @@ const char *HttpClient::ErrorCodeToString(int error_code) { return "ERROR_INTERNAL_ERROR"; case ERROR_DRY_RUN: return "ERROR_DRY_RUN"; + case ERROR_GET_NOTHING: + return "ERROR_GET_NOTHING"; case ERROR_UNKNOWN: return ""; } diff --git a/tile/net/http/http_client.h b/tile/net/http/http_client.h index f9057f7..77eea63 100644 --- a/tile/net/http/http_client.h +++ b/tile/net/http/http_client.h @@ -11,6 +11,8 @@ #include "gflags/gflags_declare.h" +#include + DECLARE_int32(tile_http_client_default_timeout_ms); namespace tile { @@ -45,6 +47,7 @@ public: ERROR_IO, ERROR_INTERNAL_ERROR, ERROR_DRY_RUN, + ERROR_GET_NOTHING, ERROR_UNKNOWN = 100, }; diff --git a/tile/net/http/types.h b/tile/net/http/types.h index 7a9aa91..317181e 100644 --- a/tile/net/http/types.h +++ b/tile/net/http/types.h @@ -79,6 +79,28 @@ enum class HttpStatus { // `HttpStatusCode`? NetworkAuthenticationRequired = 511 }; +// AllHttpStatus for for_each +static HttpStatus AllHttpStatus[] = { + HttpStatus::Continue, + HttpStatus::SwitchingProtocols, + HttpStatus::EarlyHints, + HttpStatus::OK, + HttpStatus::Created, + HttpStatus::Accepted, + HttpStatus::NonAuthoritativeInformation, + HttpStatus::NoContent, + HttpStatus::ResetContent, + HttpStatus::PartialContent, + HttpStatus::MultipleChoices, + HttpStatus::MovedPermanently, + HttpStatus::Found, + HttpStatus::SeeOther, + HttpStatus::NotModified, + HttpStatus::TemporaryRedirect, + HttpStatus::PermanentRedirect, + HttpStatus::BadRequest, +}; + Slice ToSlice(HttpVersion method) noexcept; Slice ToSlice(HttpMethod) noexcept; Slice ToSlice(HttpStatus status) noexcept; -- 2.45.2 From 8238c310f6a4a2a501686432ab4b930779db0514 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Sat, 29 Jun 2024 16:13:22 +0800 Subject: [PATCH 5/7] feat add test for future --- CMakeLists.txt | 12 ++++++++---- tests/http_client_test.cc | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ccb6ab..19836bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/tests/http_client_test.cc b/tests/http_client_test.cc index 985050e..d9407cf 100644 --- a/tests/http_client_test.cc +++ b/tests/http_client_test.cc @@ -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(code) < 200) { + continue; + } + ++cnt; + } + } + + tile::Latch latch(cnt); + std::atomic count{0}; + + for (int i = 0; i != 1000; ++i) { + for (auto code : tile::AllHttpStatus) { + if (static_cast(code) < 200) { + continue; + } + + client.AsyncGet(url + std::to_string(static_cast(code)), options) + .Then([&](std::expected &&) { + int cnt = count.fetch_add(1) + 1; + TILE_LOG_INFO_EVERY_SECOND("complete {}", cnt); + latch.CountDown(); + }); + } + } + latch.Wait(); +} -- 2.45.2 From 32bda0835a1d1e8dfeeb1b5c06ca7f43a9f04f9c Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Sat, 29 Jun 2024 16:25:04 +0800 Subject: [PATCH 6/7] feat use baidu.com for test --- tile/net/http/http_client_test.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tile/net/http/http_client_test.cc b/tile/net/http/http_client_test.cc index 9a8fef3..fa56d23 100644 --- a/tile/net/http/http_client_test.cc +++ b/tile/net/http/http_client_test.cc @@ -24,7 +24,7 @@ Get(const std::string &url, std::chrono::nanoseconds timeout = 20 * one_s) { bool IsWanAccessible() { static const auto kResult = /*!!Get("http://baidu.com") && !!Get("http://qq.com") &&*/ - !!Get("http://example.com"); + !!Get("http://www.baidu.com"); return kResult; } @@ -43,7 +43,7 @@ TEST(HttpClient, TestDomain) { TILE_LOG_INFO("WAN is not accessible, skip this test"); return; } - auto resp = Get("http://example.com"); + auto resp = Get("http://www.baidu.com"); ASSERT_TRUE(resp); EXPECT_EQ(HttpStatus(200), resp->status()); } @@ -53,7 +53,7 @@ TEST(HttpClient, TestNotFound) { TILE_LOG_INFO("WAN is not accessible, skip this test"); return; } - auto resp = Get("http://example.com/404"); + auto resp = Get("http://www.baidu.com/404"); ASSERT_TRUE(resp); EXPECT_EQ(HttpStatus(404), resp->status()); } -- 2.45.2 From dc88d60c1617b92bfa1d22f3e6f4873b3c1d012a Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Sat, 29 Jun 2024 17:47:47 +0800 Subject: [PATCH 7/7] fix http_engine crash --- tile/net/internal/http_engine.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tile/net/internal/http_engine.cc b/tile/net/internal/http_engine.cc index 4192f32..2b12a2c 100644 --- a/tile/net/internal/http_engine.cc +++ b/tile/net/internal/http_engine.cc @@ -267,6 +267,10 @@ public: for (auto &&c : clients_) { c->Stop(); } + + for (auto &&c : clients_) { + c.reset(); + } } private: -- 2.45.2