diff --git a/internal/admin/admin_test.go b/internal/admin/admin_test.go index 56939af..789c847 100644 --- a/internal/admin/admin_test.go +++ b/internal/admin/admin_test.go @@ -10,6 +10,7 @@ import ( "orchestra/internal/store" "strings" "testing" + "time" ) func TestReadinessRequiresRouterAndReturnsJSON(t *testing.T) { @@ -82,8 +83,7 @@ func TestSubscribeEmitsCursorAndEvent(t *testing.T) { w := httptest.NewRecorder() done := make(chan struct{}) go func() { h(w, r); close(done) }() - for !strings.Contains(w.Body.String(), "id: 1") { - } + time.Sleep(150 * time.Millisecond) cancel() <-done if !strings.Contains(w.Body.String(), "id: 1") { diff --git a/internal/integration/end_to_end_test.go b/internal/integration/end_to_end_test.go index 19d42fc..b9b8a46 100644 --- a/internal/integration/end_to_end_test.go +++ b/internal/integration/end_to_end_test.go @@ -13,6 +13,7 @@ import ( "orchestra/internal/store" "strings" "sync" + "sync/atomic" "testing" "time" ) @@ -117,7 +118,10 @@ func TestEndToEndIngestRouteLeaseRotateAndComplete(t *testing.T) { go c.Monitor(ctx, .8, time.Millisecond) deadline := time.Now().Add(time.Second) for time.Now().Before(deadline) { - if h.releases == 1 { + h.mu.Lock() + released := h.releases == 1 + h.mu.Unlock() + if released { break } time.Sleep(time.Millisecond) @@ -132,8 +136,11 @@ func TestEndToEndIngestRouteLeaseRotateAndComplete(t *testing.T) { } got, _ = s.Task(task.ID) } - if got.State != domain.StateQueued || h.releases != 1 { - t.Fatalf("rotation state=%s releases=%d", got.State, h.releases) + h.mu.Lock() + releases := h.releases + h.mu.Unlock() + if got.State != domain.StateQueued || releases != 1 { + t.Fatalf("rotation state=%s releases=%d", got.State, releases) } if _, err := rt.AssignPending(); err != nil { t.Fatal(err) @@ -227,14 +234,14 @@ func TestProviderRetryReflectionQuotaAndVersionConflict(t *testing.T) { if reflector.events != 1 { t.Fatalf("reflections=%d", reflector.events) } - var calls int - sup := provider.Supervisor{Name: "fake", Backoff: time.Millisecond, Run: func(context.Context) error { calls++; return errors.New("retry") }} + var calls atomic.Int32 + sup := provider.Supervisor{Name: "fake", Backoff: time.Millisecond, Run: func(context.Context) error { calls.Add(1); return errors.New("retry") }} ctx, cancel := context.WithCancel(context.Background()) sup.Start(ctx) time.Sleep(5 * time.Millisecond) cancel() - if calls < 2 || sup.Health().LastError != "retry" { - t.Fatalf("calls=%d health=%+v", calls, sup.Health()) + if calls.Load() < 2 || sup.Health().LastError != "retry" { + t.Fatalf("calls=%d health=%+v", calls.Load(), sup.Health()) } }