diff --git a/.gitignore b/.gitignore index 0e7dffa5d..2b742bc74 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,6 @@ iOS_SDK/Carthage/Build .build/ examples/demo/App/Secrets.plist -examples/demo/Local.xcconfig \ No newline at end of file +examples/demo/Local.xcconfig +examples/demo/scripts/retry/.state/ +examples/demo/scripts/retry/__pycache__/ diff --git a/examples/demo/scripts/retry/README.md b/examples/demo/scripts/retry/README.md new file mode 100644 index 000000000..c368f3456 --- /dev/null +++ b/examples/demo/scripts/retry/README.md @@ -0,0 +1,128 @@ +# Retry test harness + +Injects failures into the SDK's requests from the demo app, so executor retries and backoff can be +watched and checked. A [mitmproxy](https://mitmproxy.org) addon fails only requests that carry the +SDK's `SDK-Version` header. The demo's own REST calls and all other traffic pass through. Only +`onesignal.com` traffic is decrypted. + +```bash +brew install mitmproxy mobile-dev-inc/tap/maestro +cd examples/demo/scripts/retry +./retry-test.sh help +``` + +[Maestro](https://maestro.mobile.dev) drives the demo's UI (`tap`) through the flows in `flows/`. + +## Setup + +1. `xcrun simctl create "OneSignal Retry Test" "iPhone 17"`. The harness uses its own simulator + (`RETRY_TEST_DEVICE`, by name or UDID) because the other OneSignal demos share the bundle ID. +2. `./retry-test.sh install` builds the demo and installs it there. +3. `./retry-test.sh start` starts mitmproxy on port 8899, points the Mac's Wi-Fi/Ethernet HTTP(S) + proxy at it (the simulator uses the Mac's proxy), and trusts its CA on the simulator. +4. `./retry-test.sh fresh`, then `./retry-test.sh tap allow-notifications`. The permission prompt + holds the app inactive, so foreground retries never fire while it is showing. `fresh` wipes the + demo's data without reinstalling, so the permission is kept from then on. +5. In another terminal, `./retry-test.sh watch` follows each SDK request. +6. When done, **`./retry-test.sh stop`** restores the Mac's proxy settings. + +Leave the Mac's proxy alone with `RETRY_TEST_PROXY_MODE=local` (mitmproxy captures the `App` +process, which needs its network extension approved once). For a physical device, use +`RETRY_TEST_PROXY_MODE=manual` and set the device's Wi-Fi proxy to the Mac, as `start` explains. + +## Commands + +| Command | Does | +| --- | --- | +| `fail [--times N] [--retry-after S] [--add]` | Fail matching requests. Status `0` drops the connection, like being offline. Without `--times` it fails until `clear`. `--add` keeps earlier rules. Applies right away. | +| `clear` / `rules` | Remove or show the rules | +| `report [regex]` | Per route: each attempt, the gap since the previous one, and the gap expected | +| `reset-log` | Forget recorded attempts, for example between scenarios | +| `tap [args]` | Use the demo: `add-tag `, `add-alias