From 6e0cb1f9aaf8b1740f309e1dc10ca2eee6b05c08 Mon Sep 17 00:00:00 2001 From: zhuweiye Date: Sun, 22 Nov 2026 13:35:16 +0800 Subject: [PATCH] =?UTF-8?q?test(session):=20ttl=20=E6=94=BE=E5=AE=BD?= =?UTF-8?q?=E5=88=B0=203s=E3=80=81=E7=AD=89=E5=BE=85=203.3s=EF=BC=88MSVC?= =?UTF-8?q?=20runner=20=E4=B8=8A=201s=20=E5=A4=AA=E7=B4=A7=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/functional/web_app_session_func.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/functional/web_app_session_func.cpp b/tests/functional/web_app_session_func.cpp index 599dcc5f..e0dd291c 100644 --- a/tests/functional/web_app_session_func.cpp +++ b/tests/functional/web_app_session_func.cpp @@ -219,8 +219,7 @@ void test_session_flow() { const reply out = call(port, "/logout", true, sid); check(out.status == 200 && out.body == "bye", "注销 200"); - check(out.cookie_has("Max-Age=0") != std::string::npos, - "注销响应让 Cookie 过期"); + check(out.cookie_has("Max-Age=0"), "注销响应让 Cookie 过期"); const reply after = call(port, "/me", false, sid); check(after.status == 401, "旧 Cookie 注销后失效"); check(t.store->size() == 1, "store 里旧会话已删(当前只剩新请求建的)"); @@ -230,7 +229,9 @@ void test_session_flow() { void test_expiry() { std::cout << "-- 过期 --" << std::endl; - TestApp t(1); + // ttl 给 3 秒:MSVC runner 上"建会话→登录→读"可能就要 1 秒以上, + // ttl=1 会把"过期前可读"偶发判成过期(实测整条用例 1.9s)。 + TestApp t(3); const int port = t.start(); if (port <= 0) { check(false, "app 起来了"); @@ -240,8 +241,8 @@ void test_expiry() { const std::string sid = sid_of(call(port, "/me", false).first_cookie()); check(call(port, "/login", true, sid).status == 200, "登录"); check(call(port, "/me", false, sid).body == "uid=42", "过期前可读"); - std::this_thread::sleep_for(std::chrono::milliseconds(1200)); - check(call(port, "/me", false, sid).status == 401, "ttl=1 过期后被拒"); + std::this_thread::sleep_for(std::chrono::milliseconds(3300)); + check(call(port, "/me", false, sid).status == 401, "ttl=3 过期后被拒"); t.shutdown(); }