fix(provisioning): fast-fail wifi on bad PSK / missing SSID
Match the failure path's latency to the happy path. Before: a wrong password meant the user stared at the yellow Step 1/2 screen for the full 30 s WIFI_TIMEOUT_MS before the red retry repaint started — total ~50 s to "Connection Failed" visible. After: WL_CONNECT_FAILED and WL_NO_SSID_AVAIL bail attempt_wifi() immediately, so the red repaint starts within a few seconds of the radio giving up — total ~25 s, matching the happy-path-to-Step-2/2 timing. Also collapse the duplicate boot-time poll loop in main.cpp onto the shared attempt_wifi() so the same fast-fail covers boot-with-stored- creds, not just captive-portal submission. Tests: FW-15a (auth fail) and FW-15b (no SSID) assert millis() never reaches WIFI_TIMEOUT_MS on those statuses. Existing FW-15 tightened to use WL_DISCONNECTED so it actually exercises the timeout path. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -40,10 +40,32 @@ void test_fw14_attempt_wifi_returns_true_on_connect() {
|
||||
// millis() auto-increments by 10 on each call; after enough iterations the
|
||||
// elapsed time exceeds WIFI_TIMEOUT_MS (30000 ms).
|
||||
void test_fw15_attempt_wifi_returns_false_on_timeout() {
|
||||
g_wifi_status = 0; // never WL_CONNECTED
|
||||
g_wifi_status = 6; // WL_DISCONNECTED — never connects, never terminal-fails
|
||||
g_millis_value = 0;
|
||||
bool result = attempt_wifi("myssid", "mypass");
|
||||
TEST_ASSERT_FALSE(result);
|
||||
// Sanity: we actually waited the full timeout, not bailed early
|
||||
TEST_ASSERT_GREATER_THAN(WIFI_TIMEOUT_MS, g_millis_value);
|
||||
}
|
||||
|
||||
// ── FW-15a: attempt_wifi bails fast on WL_CONNECT_FAILED (bad PSK) ────────────
|
||||
// Without fast-fail the user would wait the full 30 s before the red retry
|
||||
// screen repaints; with it, failure surfaces in seconds.
|
||||
void test_fw15a_attempt_wifi_returns_false_on_auth_fail() {
|
||||
g_wifi_status = WL_CONNECT_FAILED;
|
||||
g_millis_value = 0;
|
||||
bool result = attempt_wifi("myssid", "wrongpass");
|
||||
TEST_ASSERT_FALSE(result);
|
||||
TEST_ASSERT_LESS_THAN(WIFI_TIMEOUT_MS, g_millis_value);
|
||||
}
|
||||
|
||||
// ── FW-15b: attempt_wifi bails fast on WL_NO_SSID_AVAIL (network not visible) ─
|
||||
void test_fw15b_attempt_wifi_returns_false_on_no_ssid() {
|
||||
g_wifi_status = WL_NO_SSID_AVAIL;
|
||||
g_millis_value = 0;
|
||||
bool result = attempt_wifi("notthere", "anypass");
|
||||
TEST_ASSERT_FALSE(result);
|
||||
TEST_ASSERT_LESS_THAN(WIFI_TIMEOUT_MS, g_millis_value);
|
||||
}
|
||||
|
||||
// ── FW-16: loop() state-machine (WiFi-credential submission path) ─────────────
|
||||
@@ -77,6 +99,8 @@ int main(int argc, char** argv) {
|
||||
UNITY_BEGIN();
|
||||
RUN_TEST(test_fw14_attempt_wifi_returns_true_on_connect);
|
||||
RUN_TEST(test_fw15_attempt_wifi_returns_false_on_timeout);
|
||||
RUN_TEST(test_fw15a_attempt_wifi_returns_false_on_auth_fail);
|
||||
RUN_TEST(test_fw15b_attempt_wifi_returns_false_on_no_ssid);
|
||||
RUN_TEST(test_fw16_loop_state_machine_deferred);
|
||||
RUN_TEST(test_fw17_reset_button_held_returns_true);
|
||||
RUN_TEST(test_fw18_reset_button_not_pressed_returns_false);
|
||||
|
||||
Reference in New Issue
Block a user