Make worker concurrency tests deterministic
This commit is contained in:
@@ -20,8 +20,8 @@ The [Core And Integration API Roadmap](../core-integration-api.md) established
|
||||
the core/integration boundary. The reassessment below distinguishes its completed
|
||||
work from the remaining audit remediation.
|
||||
|
||||
The **45 original finding entries** reduce to **23 outstanding catalog entries
|
||||
and eleven resolved entries**. Repeated responsibility findings are
|
||||
The **45 original finding entries** reduce to **22 outstanding catalog entries
|
||||
and twelve resolved entries**. Repeated responsibility findings are
|
||||
merged. Regression gaps are attached to the defects they protect rather than
|
||||
counted as additional runtime bugs. In particular, TEST-001, TEST-002, and
|
||||
TEST-004 each cover several distinct defects; TEST-003's native-fixture oracle
|
||||
@@ -66,7 +66,7 @@ context; they are not one universal severity scale. No audit establishes a P1
|
||||
incident or a measured end-to-end production speedup.
|
||||
|
||||
CAT-001, CAT-002, CAT-004, CAT-005, CAT-007, CAT-011, CAT-012, CAT-013, CAT-015,
|
||||
CAT-016, and CAT-034 are resolved;
|
||||
CAT-016, CAT-027, and CAT-034 are resolved;
|
||||
the other entries remain outstanding. The original reports and their baseline
|
||||
observations are historical.
|
||||
"Refactoring" denotes a maintenance opportunity, not a confirmed runtime
|
||||
@@ -528,6 +528,10 @@ all string assertions; authored prompt quality still needs review.
|
||||
**Assessment:** Static reliability/diagnosability risk; original P3;
|
||||
no failure was observed in the audit's repeated runs.
|
||||
|
||||
**Status:** Resolved. Controlled gates establish continuation overlap and reverse
|
||||
completion; bounded handshakes cancel and join work on failure. Repeated focused
|
||||
tests and affected race tests pass.
|
||||
|
||||
**Source:** [TEST-007](08-testing.md#test-007--concurrency-tests-need-controlled-overlap-and-better-failure-bounds).
|
||||
|
||||
A continuation test uses a five-millisecond sleep to induce required overlap;
|
||||
|
||||
@@ -345,6 +345,12 @@ if no recorded migration condition prevents it.
|
||||
|
||||
## Stage 10 — Control Worker-Test Overlap And Bound Handshakes
|
||||
|
||||
**Completed.** Continuation overlap is established by start/release gates;
|
||||
reverse-completion handshakes enforce actual completion order, detect early runner
|
||||
exit, and use bounded cancellation and joining. Both tests check no jobs remain
|
||||
active. The prescribed ten-run focused check and affected race check pass. No
|
||||
runtime timeout guarantee or follow-up was added.
|
||||
|
||||
**Coverage:** CAT-027. **Prerequisites:** none; precedes lifecycle edits.
|
||||
|
||||
Replace continuation sleep in runner_concurrency_test.go with start/release gates.
|
||||
|
||||
@@ -317,6 +317,7 @@ func typedValueForLane(laneIndex int, chunkIndex int) any {
|
||||
func TestRunnerBoundsExtractJobsAndStabilizesReverseCompletion(t *testing.T) {
|
||||
prepared := preparedConcurrentPipeline(t, 3)
|
||||
started := make(chan int, 6)
|
||||
finished := make(chan int, 6)
|
||||
release := make([]chan struct{}, 6)
|
||||
for i := range release {
|
||||
release[i] = make(chan struct{})
|
||||
@@ -327,6 +328,7 @@ func TestRunnerBoundsExtractJobsAndStabilizesReverseCompletion(t *testing.T) {
|
||||
lane := laneIndex
|
||||
installExtractOperation(prepared, lane, func(ctx context.Context, request contracts.ExtractionInput) (erasedTypedResult, error) {
|
||||
jobIndex := request.Chunk.Index*2 + lane
|
||||
defer func() { finished <- jobIndex }()
|
||||
current := active.Add(1)
|
||||
defer active.Add(-1)
|
||||
for {
|
||||
@@ -351,26 +353,68 @@ func TestRunnerBoundsExtractJobsAndStabilizesReverseCompletion(t *testing.T) {
|
||||
err error
|
||||
}
|
||||
done := make(chan outcome, 1)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
joined := false
|
||||
defer func() {
|
||||
cancel()
|
||||
if !joined {
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Error("runner did not stop after cancellation")
|
||||
}
|
||||
}
|
||||
}()
|
||||
go func() {
|
||||
output, err := New().Run(context.Background(), RunInput{Prepared: prepared, RawInput: []byte("input"), Workers: 2})
|
||||
output, err := New().Run(ctx, RunInput{Prepared: prepared, RawInput: []byte("input"), Workers: 2})
|
||||
done <- outcome{output: output, err: err}
|
||||
}()
|
||||
waitJob := func(ch <-chan int) int {
|
||||
t.Helper()
|
||||
select {
|
||||
case job := <-ch:
|
||||
return job
|
||||
case result := <-done:
|
||||
joined = true
|
||||
t.Fatalf("runner stopped before handshake: %v", result.err)
|
||||
case <-ctx.Done():
|
||||
t.Fatal("timed out waiting for worker handshake")
|
||||
}
|
||||
return -1
|
||||
}
|
||||
for pair := 0; pair < 3; pair++ {
|
||||
first, second := <-started, <-started
|
||||
first, second := waitJob(started), waitJob(started)
|
||||
want := map[int]bool{pair * 2: true, pair*2 + 1: true}
|
||||
if !want[first] || !want[second] || first == second {
|
||||
t.Fatalf("started jobs = %d, %d; want round-robin pair %d", first, second, pair)
|
||||
}
|
||||
close(release[second])
|
||||
if got := waitJob(finished); got != second {
|
||||
t.Fatalf("completed job = %d, want %d", got, second)
|
||||
}
|
||||
close(release[first])
|
||||
if pair < 2 {
|
||||
if got := waitJob(finished); got != first {
|
||||
t.Fatalf("completed job = %d, want %d", got, first)
|
||||
}
|
||||
}
|
||||
}
|
||||
var result outcome
|
||||
select {
|
||||
case result = <-done:
|
||||
joined = true
|
||||
case <-ctx.Done():
|
||||
t.Fatal("runner did not finish after worker releases")
|
||||
}
|
||||
result := <-done
|
||||
if result.err != nil {
|
||||
t.Fatalf("Run() error = %v", result.err)
|
||||
}
|
||||
if got := maximum.Load(); got != 2 {
|
||||
t.Fatalf("maximum concurrent extract jobs = %d, want 2", got)
|
||||
}
|
||||
if got := active.Load(); got != 0 {
|
||||
t.Fatalf("active extraction jobs after return = %d", got)
|
||||
}
|
||||
if len(result.output.Diagnostics.Groups) != 2 {
|
||||
t.Fatalf("diagnostic groups = %#v, want one deterministic group per lane", result.output.Diagnostics.Groups)
|
||||
}
|
||||
@@ -399,6 +443,10 @@ func TestRunnerBoundsConcurrentLaneContinuations(t *testing.T) {
|
||||
publicLanes := make([]PreparedArtifactLane, len(lanes))
|
||||
var active atomic.Int32
|
||||
var maximum atomic.Int32
|
||||
started := make(chan struct{}, len(lanes))
|
||||
release := make(chan struct{})
|
||||
var releaseOnce sync.Once
|
||||
unblock := func() { releaseOnce.Do(func() { close(release) }) }
|
||||
for i := range lanes {
|
||||
lane := base
|
||||
lane.resolved.ID = fmt.Sprintf("lane-%02d", i)
|
||||
@@ -409,7 +457,7 @@ func TestRunnerBoundsConcurrentLaneContinuations(t *testing.T) {
|
||||
extract: func(_ context.Context, _ any, request contracts.ExtractionInput, _ ExecutionContext[any]) (erasedTypedResult, error) {
|
||||
return erasedTypedResult{Value: codecNotes{Items: []string{request.Chunk.ID}}}, nil
|
||||
},
|
||||
merge: func(_ context.Context, _ any, _ contracts.MergeInput[any], _ ExecutionContext[any]) (erasedTypedResult, error) {
|
||||
merge: func(ctx context.Context, _ any, _ contracts.MergeInput[any], _ ExecutionContext[any]) (erasedTypedResult, error) {
|
||||
current := active.Add(1)
|
||||
defer active.Add(-1)
|
||||
for {
|
||||
@@ -418,7 +466,12 @@ func TestRunnerBoundsConcurrentLaneContinuations(t *testing.T) {
|
||||
break
|
||||
}
|
||||
}
|
||||
time.Sleep(5 * time.Millisecond)
|
||||
started <- struct{}{}
|
||||
select {
|
||||
case <-release:
|
||||
case <-ctx.Done():
|
||||
return erasedTypedResult{}, ctx.Err()
|
||||
}
|
||||
return erasedTypedResult{Value: codecNotes{}}, nil
|
||||
},
|
||||
normalize: base.typed.normalize,
|
||||
@@ -432,16 +485,58 @@ func TestRunnerBoundsConcurrentLaneContinuations(t *testing.T) {
|
||||
prepared.resolved.Steps[0].ArtifactLanes = resolvedLanes
|
||||
prepared.Steps[0].ArtifactLanes = publicLanes
|
||||
|
||||
output, err := New().Run(context.Background(), RunInput{Prepared: prepared, RawInput: []byte("input"), Workers: 2})
|
||||
if err != nil {
|
||||
t.Fatalf("Run() error = %v", err)
|
||||
type outcome struct {
|
||||
output RunOutput
|
||||
err error
|
||||
}
|
||||
if len(output.normalizeOutputs) != len(lanes) {
|
||||
t.Fatalf("normalize outputs = %d, want %d", len(output.normalizeOutputs), len(lanes))
|
||||
done := make(chan outcome, 1)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
joined := false
|
||||
defer func() {
|
||||
cancel()
|
||||
unblock()
|
||||
if !joined {
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Error("runner did not stop after cancellation")
|
||||
}
|
||||
}
|
||||
}()
|
||||
go func() {
|
||||
output, err := New().Run(ctx, RunInput{Prepared: prepared, RawInput: []byte("input"), Workers: 2})
|
||||
done <- outcome{output, err}
|
||||
}()
|
||||
for i := 0; i < 2; i++ {
|
||||
select {
|
||||
case <-started:
|
||||
case result := <-done:
|
||||
joined = true
|
||||
t.Fatalf("runner stopped before continuations overlapped: %v", result.err)
|
||||
case <-ctx.Done():
|
||||
t.Fatal("timed out waiting for overlapping continuations")
|
||||
}
|
||||
}
|
||||
unblock()
|
||||
var result outcome
|
||||
select {
|
||||
case result = <-done:
|
||||
joined = true
|
||||
case <-ctx.Done():
|
||||
t.Fatal("runner did not finish after continuation release")
|
||||
}
|
||||
if result.err != nil {
|
||||
t.Fatalf("Run() error = %v", result.err)
|
||||
}
|
||||
if len(result.output.normalizeOutputs) != len(lanes) {
|
||||
t.Fatalf("normalize outputs = %d, want %d", len(result.output.normalizeOutputs), len(lanes))
|
||||
}
|
||||
if got := maximum.Load(); got != 2 {
|
||||
t.Fatalf("maximum concurrent lane continuations = %d, want 2", got)
|
||||
}
|
||||
if got := active.Load(); got != 0 {
|
||||
t.Fatalf("active continuations after return = %d", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunnerSelectsFrameworkErrorByStableLaneOrder(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user