File tree Expand file tree Collapse file tree 2 files changed +52
-1
lines changed Expand file tree Collapse file tree 2 files changed +52
-1
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ function get_response(\think\Request $request): \think\Response {
27
27
// 设置 throttle 配置
28
28
$ app ->config ->set ($ this ->throttle_config , 'throttle ' );
29
29
30
- $ response = $ app ->http ->run ($ request );
30
+ $ response = $ app ->http ->run ($ request );
31
31
$ app ->refClear ();
32
32
return $ response ;
33
33
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+
4
+ namespace tests ;
5
+
6
+
7
+ /**
8
+ * 常驻内存型的单元测试,当 TP 运行在常驻内存型的时候。
9
+ * 一个 App 实例,处理多次请求
10
+ * Class ResidentMemoryTest
11
+ * @package tests
12
+ */
13
+ class ResidentMemoryTest extends BaseTest
14
+ {
15
+ public function test_resident_memory ()
16
+ {
17
+ $ app = new GCApp (static ::$ ROOT_PATH );
18
+ $ app ->setRuntimePath (static ::$ RUNTIME_PATH );
19
+ $ app ->middleware ->import (include $ this ->middleware_file , $ this ->middleware_type );
20
+ $ app ->config ->set ($ this ->get_default_throttle_config (), 'throttle ' );
21
+
22
+ // 处理多个请求
23
+ $ allowCount1 = 0 ;
24
+ $ allowCount2 = 0 ;
25
+
26
+ for ($ i = 0 ; $ i < 200 ; $ i ++) {
27
+ // 受访问频率限制
28
+ $ request = new \think \Request ();
29
+ $ request ->setMethod ('GET ' );
30
+ $ request ->setUrl ('/ ' );
31
+ $ response = $ app ->http ->run ($ request );
32
+ if ($ response ->getCode () == 200 ) {
33
+ $ allowCount1 ++;
34
+ }
35
+
36
+ // 不受访问频率限制
37
+ $ request = new \think \Request ();
38
+ $ request ->setMethod ('POST ' );
39
+ $ request ->setUrl ('/ ' );
40
+
41
+ $ response = $ app ->http ->run ($ request );
42
+ if ($ response ->getCode () == 200 ) {
43
+ $ allowCount2 ++;
44
+ }
45
+ }
46
+
47
+ $ app ->refClear ();
48
+ $ this ->assertEquals (100 , $ allowCount1 );
49
+ $ this ->assertEquals (200 , $ allowCount2 );
50
+ }
51
+ }
You can’t perform that action at this time.
0 commit comments