Skip to content

Commit 17953cb

Browse files
committed
refactor: remove retries from test workflow and update documentation; fix middleware tests
1 parent d3876bc commit 17953cb

5 files changed

Lines changed: 13 additions & 18 deletions

File tree

.github/workflows/test.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ jobs:
1111
matrix: # 会分开成两个任务分别执行
1212
os: [ubuntu-latest, macos-latest, windows-latest]
1313
fail-fast: false # 一个系统失败不终止其他系统的任务
14-
retries:
15-
max_attempts: 3 # 每个失败的任务重试3次
1614
runs-on: ${{ matrix.os }}
1715
steps:
1816
- name: Checkout code #这部分是为了从github自动clone代码

README.en.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
![](https://chenxuanweb.top/cppnet/cppnet.png)
55
## Author
66
- **chenxuan**
7-
> ![](http://cdn.androidftp.top/test/2025101017224732pasteboard.paste)
87
## Repository Address
98
- [github](https://github.com/chenxuan520/cppnet)
109
- [gitee](https://gitee.com/chenxuan520/cppnet)

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
![](https://chenxuanweb.top/cppnet/cppnet.png)
66
## Author
77
- **chenxuan**
8-
> ![](http://cdn.androidftp.top/test/2025101017224732pasteboard.paste)
98
## 仓库地址
109
- [github](https://github.com/chenxuan520/cppnet)
1110
- [gitee](https://gitee.com/chenxuan520/cppnet)

docs/cppnet/http/server/http_server.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@
99
## Next()
1010
- 参数:无
1111
- 返回值:无
12-
- 作用:设置继续执行的标志,在中间件中使用。
12+
- 作用:设置继续执行的标志,在中间件中使用,整体和 gin 用法类似
1313
## Abort()
1414
- 参数:无
1515
- 返回值:无
16-
- 作用:设置停止执行的标志,在中间件中使用。
17-
## is_continue()
18-
- 参数:无
19-
- 返回值:`bool`类型,表示是否继续执行。
20-
- 作用:获取当前的执行状态标志。
16+
- 作用:设置停止执行的标志,在中间件中使用,整体和 gin 用法类似。
2117
## T Get(const std::string &key)
2218
- 参数:
2319
- `key`:字符串类型,用于查找内联数据的键。

src/test/http/server/http_server_test.hpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "test.h"
55
#include "utils/file.hpp"
66
#include <atomic>
7+
#include <string>
78

89
using namespace cppnet;
910
using namespace std;
@@ -224,13 +225,14 @@ TEST(HttpServer, Middleware) {
224225
auto rc = server.Init(addr);
225226
MUST_TRUE(rc == 0, server.err_msg());
226227

228+
int temp_var = 10;
227229
atomic<int> count = 0;
228-
auto count_func = [&count](HttpContext &ctx) {
230+
auto count_func = [&count, &temp_var](HttpContext &ctx) {
229231
DEBUG("use count");
230232
count++;
231-
int temp = 10;
232-
ctx.Set("temp", temp);
233+
ctx.Set("temp", temp_var);
233234
ctx.Next();
235+
temp_var = ctx.Get<int>("temp");
234236
};
235237
atomic<int> abort_count = 0;
236238
auto abort_func = [&abort_count](HttpContext &ctx) {
@@ -242,16 +244,16 @@ TEST(HttpServer, Middleware) {
242244
server.Use(count_func);
243245

244246
server.GET("/hello",
245-
{count_func,
246-
[&](HttpContext &ctx) {
247+
{count_func, [&](HttpContext &ctx) {
247248
ctx.resp().Text(HttpStatusCode::OK, "hello world");
248249
auto val = ctx.Get<int>("temp");
249250
MUST_TRUE(val == 10, "get wrong value " + to_string(val));
250251
auto str_tmp = ctx.Get<std::string>("temp");
251252
MUST_TRUE(str_tmp == "", "get wrong value " + str_tmp);
253+
ctx.Set("temp", 20);
254+
DEBUG("temp: " << ctx.Get<int>("temp"));
252255
server.Stop();
253-
},
254-
count_func});
256+
}});
255257

256258
server.GET("/abort", {[&](HttpContext &ctx) {
257259
ctx.resp().Text(HttpStatusCode::OK, "hello world");
@@ -286,9 +288,10 @@ TEST(HttpServer, Middleware) {
286288
MUST_TRUE(resp.body() == "hello world", "get wrong body " + resp.body());
287289
DEBUG("resp: " << resp.body());
288290

289-
MUST_TRUE(count == 4, "get wrong count " + to_string(count));
291+
MUST_TRUE(count == 3, "get wrong count " + to_string(count));
290292
MUST_TRUE(abort_count == 1,
291293
"get wrong abort count " + to_string(abort_count));
294+
MUST_TRUE(temp_var == 20, "temp_var is " + to_string(temp_var) + " not 20");
292295
}
293296

294297
#ifdef CPPNET_OPENSSL

0 commit comments

Comments
 (0)