模拟普通用户提交传输请求。 等待时间 0.1-1.0 秒,模拟真实用户操作间隔。
| 69 | # --------------------------------------------------------------------------- |
| 70 | |
| 71 | class SmartNodeUser(HttpUser): |
| 72 | """模拟普通用户提交传输请求。 |
| 73 | |
| 74 | 等待时间 0.1-1.0 秒,模拟真实用户操作间隔。 |
| 75 | """ |
| 76 | |
| 77 | wait_time = between(0.1, 1.0) |
| 78 | |
| 79 | @task(5) |
| 80 | def submit_fixed_request(self): |
| 81 | """高权重:提交固定类型(TASK_CMD/高优先级)的请求。""" |
| 82 | payload = _fixed_payload() |
| 83 | with self.client.post( |
| 84 | "/api/request", |
| 85 | json=payload, |
| 86 | catch_response=True, |
| 87 | name="/api/request[fixed]", |
| 88 | ) as resp: |
| 89 | if resp.status_code not in (200, 400, 429): |
| 90 | resp.failure(f"Unexpected status: {resp.status_code}") |
| 91 | else: |
| 92 | resp.success() |
| 93 | |
| 94 | @task(3) |
| 95 | def submit_random_request(self): |
| 96 | """中权重:提交随机类型请求,覆盖多种数据类型。""" |
| 97 | payload = _random_payload() |
| 98 | with self.client.post( |
| 99 | "/api/request", |
| 100 | json=payload, |
| 101 | catch_response=True, |
| 102 | name="/api/request[random]", |
| 103 | ) as resp: |
| 104 | if resp.status_code not in (200, 400, 429): |
| 105 | resp.failure(f"Unexpected status: {resp.status_code}") |
| 106 | else: |
| 107 | resp.success() |
| 108 | |
| 109 | @task(1) |
| 110 | def submit_low_priority_request(self): |
| 111 | """低权重:提交低优先级请求,压力测试下预期会被拒绝。""" |
| 112 | payload = _fixed_payload(data_type="DATA_SLICE", priority=1) |
| 113 | with self.client.post( |
| 114 | "/api/request", |
| 115 | json=payload, |
| 116 | catch_response=True, |
| 117 | name="/api/request[low_priority]", |
| 118 | ) as resp: |
| 119 | if resp.status_code not in (200, 400, 429): |
| 120 | resp.failure(f"Unexpected status: {resp.status_code}") |
| 121 | else: |
| 122 | resp.success() |
| 123 | |
| 124 | @task(1) |
| 125 | def check_health(self): |
| 126 | """轮询健康检查接口,监控系统在高负载下的响应能力。""" |
| 127 | with self.client.get("/api/health", catch_response=True) as resp: |
| 128 | if resp.status_code != 200: |
nothing calls this directly
no outgoing calls
no test coverage detected