Best-effort cleanup: disconnect any connected peripherals. This prevents state leakage between tests when running in a shared process (Android). The background scan is intentionally kept running to avoid Android scan throttling.
(adapter: &Adapter)
| 63 | /// This prevents state leakage between tests when running in a shared process (Android). |
| 64 | /// The background scan is intentionally kept running to avoid Android scan throttling. |
| 65 | async fn ensure_clean_state(adapter: &Adapter) { |
| 66 | // Use timeouts on all operations — a hung disconnect from a prior test |
| 67 | // must not block subsequent tests forever. |
| 68 | if let Ok(Ok(peripherals)) = |
| 69 | tokio::time::timeout(Duration::from_secs(2), adapter.peripherals()).await |
| 70 | { |
| 71 | for p in peripherals { |
| 72 | if let Ok(Ok(true)) = |
| 73 | tokio::time::timeout(Duration::from_secs(1), p.is_connected()).await |
| 74 | { |
| 75 | let _ = tokio::time::timeout(Duration::from_secs(5), p.disconnect()).await; |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | // Give the BLE stack time to settle after disconnection. |
| 80 | tokio::time::sleep(Duration::from_secs(2)).await; |
| 81 | } |
| 82 | |
| 83 | /// Discover the test peripheral by name, connect to it, and discover its services. |
| 84 | /// |
no test coverage detected