Fix ServerTest.ClientStop test case (#1542)

This commit is contained in:
Jiwoo Park 2023-03-30 22:50:51 +09:00 committed by GitHub
parent b33aa52dc2
commit 3956a2b790
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2867,11 +2867,16 @@ TEST_F(ServerTest, GetStreamedEndless) {
} }
TEST_F(ServerTest, ClientStop) { TEST_F(ServerTest, ClientStop) {
std::atomic_size_t count{4};
std::vector<std::thread> threads; std::vector<std::thread> threads;
for (auto i = 0; i < 3; i++) {
for (auto i = count.load(); i != 0; --i) {
threads.emplace_back([&]() { threads.emplace_back([&]() {
auto res = cli_.Get("/streamed-cancel", auto res = cli_.Get("/streamed-cancel",
[&](const char *, uint64_t) { return true; }); [&](const char *, uint64_t) { return true; });
--count;
ASSERT_TRUE(!res); ASSERT_TRUE(!res);
EXPECT_TRUE(res.error() == Error::Canceled || EXPECT_TRUE(res.error() == Error::Canceled ||
res.error() == Error::Read || res.error() == Error::Write); res.error() == Error::Read || res.error() == Error::Write);
@ -2879,7 +2884,7 @@ TEST_F(ServerTest, ClientStop) {
} }
std::this_thread::sleep_for(std::chrono::seconds(2)); std::this_thread::sleep_for(std::chrono::seconds(2));
while (cli_.is_socket_open()) { while (count != 0) {
cli_.stop(); cli_.stop();
std::this_thread::sleep_for(std::chrono::milliseconds(10)); std::this_thread::sleep_for(std::chrono::milliseconds(10));
} }