From 609a099677a947325131b43c1e1741affa92075b Mon Sep 17 00:00:00 2001 From: Stephen Adamson Date: Fri, 10 Jul 2026 19:10:31 +0100 Subject: [PATCH] fix: data races in Square mock and scheduler hostname tests - square_dev.go: return a copy of CheckoutResult to the caller instead of sharing the map-stored pointer, preventing the goroutine from racing with the caller on Status field reads - scheduler_test.go: remove t.Parallel from TestInitHostname_* tests which modify a shared package-level hostname variable --- backend/internal/jobs/scheduler_test.go | 6 ------ backend/internal/square/square_dev.go | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/backend/internal/jobs/scheduler_test.go b/backend/internal/jobs/scheduler_test.go index 15b52f4..ef26211 100644 --- a/backend/internal/jobs/scheduler_test.go +++ b/backend/internal/jobs/scheduler_test.go @@ -554,8 +554,6 @@ func TestHostname_NonEmpty(t *testing.T) { // TestInitHostname_HappyPath verifies initHostname assigns the value from // the hostname resolver when it returns a valid name. func TestInitHostname_HappyPath(t *testing.T) { - t.Parallel() - orig := hostname defer func() { hostname = orig }() @@ -568,8 +566,6 @@ func TestInitHostname_HappyPath(t *testing.T) { // TestInitHostname_FallbackOnError verifies initHostname falls back to // "localhost" when the resolver returns an error. func TestInitHostname_FallbackOnError(t *testing.T) { - t.Parallel() - orig := hostname defer func() { hostname = orig }() @@ -582,8 +578,6 @@ func TestInitHostname_FallbackOnError(t *testing.T) { // TestInitHostname_FallbackOnEmpty verifies initHostname falls back to // "localhost" when the resolver returns an empty string (no error). func TestInitHostname_FallbackOnEmpty(t *testing.T) { - t.Parallel() - orig := hostname defer func() { hostname = orig }() diff --git a/backend/internal/square/square_dev.go b/backend/internal/square/square_dev.go index f4ca8f3..ed431d0 100644 --- a/backend/internal/square/square_dev.go +++ b/backend/internal/square/square_dev.go @@ -115,7 +115,7 @@ func (m *MockClient) CreateCheckout(ctx context.Context, req CreateCheckoutReq) } m.mu.Lock() - m.checkouts[checkoutID] = result + m.checkouts[checkoutID] = &CheckoutResult{ID: checkoutID, Status: "PENDING"} m.mu.Unlock() if !m.HoldCheckouts {