Skip to content

Commit 5049762

Browse files
committed
[fix] WebSocket IdleTimeout 测试: 修复 Clang sanitizer 构建下的竞态失败
客户端 read() 收到 EOF 后立即 server.stop() 会终止 io_context, 导致服务端 onDisconnect 协程被丢弃、disconnected 永远为 false。 在 stop() 前加入轮询等待,给回调足够时间完成。
1 parent 04e0485 commit 5049762

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

tests/test_websocket.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,13 @@ TEST(WebSocketTest, IdleTimeoutClosesCleanly)
215215
EXPECT_TRUE(ec == boost::asio::error::eof || ec == ws::error::closed || ec == boost::asio::error::connection_reset
216216
|| ec == boost::asio::error::operation_aborted);
217217

218+
// 等待 onDisconnect 回调在 io_context 中完成
219+
// sanitizer 构建下(ASan/UBSan ~2-5x 性能惩罚),回调链需要更多时间
220+
for (int i = 0; i < 200 && !disconnected.load(); ++i)
221+
{
222+
std::this_thread::sleep_for(std::chrono::milliseconds(10));
223+
}
224+
218225
server.stop();
219226
serverThread.join();
220227

0 commit comments

Comments
 (0)