应用弱网测试方案设计
围绕断网、延迟与丢包设计测试矩阵,检查重试、重复提交和恢复行为,并给出自动化示例。
完整提示词
<context>
The user's app ({{platform}}) is used on trains, in basements, on congested mobile networks and behind hotel Wi-Fi login pages, but is tested on office Wi-Fi. The bugs that appear are predictable: spinners that never end because there is no timeout; retries of non-idempotent requests that create duplicate orders or payments; double taps while a slow request is in flight; an offline queue that replays in the wrong order or never; captive portals returning a 200 HTML page the app tries to parse as JSON; stale data shown as current; and errors that blame the user ("Something went wrong") with no way to retry.
</context>
<task>
<app>
{{app_description}}
</app>
1. Define network profiles with numbers: offline; high latency (about 500-800 ms round trip); slow 3G-like (roughly 400 kbps down, 400 ms latency); lossy (5-10% packet loss); flapping (connection drops for 5-30 s every minute); captive portal (all requests answered with an HTML login page or redirect); DNS failure; and server slow (responses delayed 10-30 s). Say which tool applies each on {{platform}}: browser DevTools throttling and request blocking, Network Link Conditioner on iOS and macOS, the Android emulator's network settings, a proxy such as Charles, mitmproxy or Toxiproxy for loss and latency injection, and airplane mode on a real device.
2. Rank the app's flows by harm if the network fails mid-request: payments and orders first, then other writes, then reads.
3. For each risky flow and profile, list what to check:
- Timeouts exist and fit the action (connect and read timeouts, not infinite).
- Retries: only for idempotent requests or with an idempotency key; exponential backoff with jitter; a cap.
- Duplicate submission: the button disables or the request is deduplicated; the server rejects a repeated idempotency key.
- Offline: queued writes persist across app restart, replay in order, and resolve conflicts as designed; the user can see what is pending.
- What the user sees: loading state within 100-300 ms, a clear offline or slow message, a retry action, no lost form input, and stale data labelled as such.
- Recovery: when the network returns, the app resumes without a restart and without duplicates.
- Captive portal and non-JSON responses do not crash or log users out.
4. Automate the highest-value checks: stub or proxy-based tests that inject delay, drop and errors at the network layer (for example route interception in a browser test tool, a fault-injecting proxy in CI, or an injected HTTP client in unit tests), with timeouts and retry counts asserted. Keep real-device manual checks for radio-level behaviour.
5. From the code given, list specific places that look risky (missing timeout, retry on POST, no idempotency key) as findings to verify.
If the description does not say which flows write data or how requests are made, ask for those and stop.
</task>
<constraints>
- Test against test environments and test accounts; never run fault injection against production or real payments.
- Do not invent the app's behaviour; label assumptions [ASSUMED].
- Findings from code are hypotheses until a test confirms them; say so.
{{> output/uncertainty}}
</constraints>
<output_format>
## Network profiles
Table: profile | parameters | tool on this platform.
## Risky flows
Ranked list with the harm if interrupted.
## Test checklist
Table: flow | profile | check | expected behaviour | manual or automated.
## Automation
Code or config for the top automated checks.
## Findings to check in code
Bullets with file or function, the risk and the test that would confirm it.
</output_format>可替换内容
- {{platform}}
- {{app_description}}
- {{> output/uncertainty}}
- [ASSUMED]
分类与标签
编程开发、弱网测试、故障注入、幂等校验、离线恢复、测试自动化