-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f560dc8
commit 2c30dd5
Showing
5 changed files
with
107 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace tests; | ||
|
||
|
||
/** | ||
* 路由节流器单元测试 | ||
* Class ResidentMemoryTest | ||
* @package tests | ||
*/ | ||
class RouteThrottleTest extends Base | ||
{ | ||
public function __construct(?string $name = null, array $data = [], $dataName = '') | ||
{ | ||
parent::__construct($name, $data, $dataName); | ||
$config = $this->get_default_throttle_config(); | ||
$config['key'] = '__CONTROLLER__/__ACTION__/__IP__'; | ||
$this->set_throttle_config($config); | ||
} | ||
|
||
public function test_route_middleware_type() | ||
{ | ||
$this->middleware_type = 'route'; // 路由中间件 | ||
$allowCount1 = 0; | ||
$allowCount2 = 0; | ||
for ($i = 0; $i < 200; $i++) { | ||
$request = $this->create_request('/hello/name'); | ||
if ($this->visit_with_http_code($request)) { | ||
$allowCount1++; | ||
} | ||
$request = $this->create_request('/'); | ||
if ($this->visit_with_http_code($request)) { | ||
$allowCount2++; | ||
} | ||
} | ||
$this->assertEquals(100, $allowCount1); | ||
$this->assertEquals(100, $allowCount2); | ||
} | ||
|
||
public function test_global_middleware_type() | ||
{ | ||
$this->middleware_type = 'global'; // 全局中间件 | ||
$allowCount1 = 0; | ||
$allowCount2 = 0; | ||
// 默认 100/m ,所以两个路由都是 50 次成功 | ||
for ($i = 0; $i < 200; $i++) { | ||
$request = $this->create_request('/hello/name'); | ||
if ($this->visit_with_http_code($request)) { | ||
$allowCount1++; | ||
} | ||
$request = $this->create_request('/'); | ||
if ($this->visit_with_http_code($request)) { | ||
$allowCount2++; | ||
} | ||
} | ||
$this->assertEquals(50, $allowCount1); | ||
$this->assertEquals(50, $allowCount2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters