Skip to content

Commit 66356c5

Browse files
committed
wake background thread before quit
1 parent 9820b8e commit 66356c5

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

ext/src/http/client/curl/http_client_curl.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ HttpClient::~HttpClient()
215215
}
216216
if (background_thread->joinable())
217217
{
218+
wakeupBackgroundThread(); // if delay quit, wake up first
218219
background_thread->join();
219220
}
220221
}

ext/test/http/curl_http_test.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,20 +533,21 @@ TEST_F(BasicCurlHttpTests, ElegantQuitQuick)
533533
{
534534
auto http_client = http_client::HttpClientFactory::Create();
535535
std::static_pointer_cast<curl::HttpClient>(http_client)->MaybeSpawnBackgroundThread();
536-
auto beg = std::chrono::system_clock::now();
537536
// start background first, then test it could wakeup
538537
auto session = http_client->CreateSession("http://127.0.0.1:19000/get/");
539538
auto request = session->CreateRequest();
540539
request->SetUri("get/");
541540
auto handler = std::make_shared<GetEventHandler>();
542541
session->SendRequest(handler);
542+
std::this_thread::sleep_for(std::chrono::milliseconds{10}); // let it enter poll state
543+
auto beg = std::chrono::system_clock::now();
543544
http_client->FinishAllSessions();
544545
http_client.reset();
545546
// when use background_thread_wait_for_ should have no side effort on elegant quit
546-
// because ci machine may slow, so we assert it cost should less than
547-
// scheduled_delay_milliseconds_
547+
// it shoule less than scheduled_delay_milliseconds_
548+
// because ci machine may slow, some take 10ms, so we assert it less than 20ms
548549
auto cost = std::chrono::system_clock::now() - beg;
549-
ASSERT_TRUE(cost < std::chrono::milliseconds{10})
550+
ASSERT_TRUE(cost < std::chrono::milliseconds{20})
550551
<< "cost ms: " << std::chrono::duration_cast<std::chrono::milliseconds>(cost).count()
551552
<< " libcurl version: 0x" << std::hex << LIBCURL_VERSION_NUM;
552553
ASSERT_TRUE(handler->is_called_);

0 commit comments

Comments
 (0)