eliminate test harness and SSE race conditions

This commit is contained in:
kami
2026-07-26 20:51:58 +04:00
parent 076c3de6dd
commit 325c684eb0
2 changed files with 16 additions and 9 deletions
+2 -2
View File
@@ -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") {
+14 -7
View File
@@ -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())
}
}