From fe47cb486aa5e63d001836838d6ce923d78a15b1 Mon Sep 17 00:00:00 2001 From: Stephen Adamson Date: Fri, 10 Jul 2026 20:53:42 +0100 Subject: [PATCH] fix: replace 3.5s sleep with poll loop in till checkout test --- backend/handlers/payments/till_test.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/backend/handlers/payments/till_test.go b/backend/handlers/payments/till_test.go index e887fe3..a204a80 100644 --- a/backend/handlers/payments/till_test.go +++ b/backend/handlers/payments/till_test.go @@ -540,10 +540,18 @@ func TestGetTillCheckoutStatus_Completed(t *testing.T) { t.Fatal("expected checkout_id to be set for card_machine payment") } - // Wait for the mock goroutine to complete. The mock's goroutine sleeps 3s - // by default (mockSleep is only skipped when isTesting is set before the - // square package initializes, which depends on init ordering with db). - time.Sleep(3500 * time.Millisecond) + // Wait for the mock goroutine to complete the checkout with polling. + deadline := time.Now().Add(5 * time.Second) + for { + _, err := SquareClient.GetCheckout(context.Background(), *createResp.CheckoutID) + if err == nil { + break + } + if time.Now().After(deadline) { + t.Fatalf("timed out waiting for checkout to complete: %v", err) + } + time.Sleep(100 * time.Millisecond) + } // Now call GetTillCheckoutStatus — should return COMPLETED. statusReq := httptest.NewRequest("GET", "/api/admin/till/checkout/"+*createResp.CheckoutID+"/status", nil)