Verify concurrent core operation isolation
This commit is contained in:
@@ -793,6 +793,11 @@ assembled behavior rather than making compatibility wrappers for failing fixture
|
|||||||
|
|
||||||
## Stage 21 — Verify Cross-Boundary And Concurrent Execution
|
## Stage 21 — Verify Cross-Boundary And Concurrent Execution
|
||||||
|
|
||||||
|
**Status:** Complete. The specified framework, module, CLI, and preflight
|
||||||
|
suite passes, as do focused pipeline and reconciliation race checks. Existing
|
||||||
|
assembled recovery, handoff, capture, admission, and worker tests were reviewed;
|
||||||
|
a synchronized native-operation test covers concurrent evaluation isolation.
|
||||||
|
|
||||||
**Goal:** Establish behavior where correctness spans the new owners.
|
**Goal:** Establish behavior where correctness spans the new owners.
|
||||||
|
|
||||||
**Inspect:** Core executor and stage adapters; existing pipeline worker, operation,
|
**Inspect:** Core executor and stage adapters; existing pipeline worker, operation,
|
||||||
|
|||||||
70
internal/framework/pipeline/concurrent_evaluation_test.go
Normal file
70
internal/framework/pipeline/concurrent_evaluation_test.go
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
package pipeline
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||||
|
"go.maximumdirect.net/promptkit"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestConcurrentNativeOperationsKeepTheirOwnEvaluations(t *testing.T) {
|
||||||
|
engine := nativeProducerEngine(t, producerClientFunc(func(_ context.Context, request promptkit.GenerateRequest) (*promptkit.GenerateResponse, error) {
|
||||||
|
value := 1
|
||||||
|
if request.Prompt.SessionID == "second" {
|
||||||
|
value = 2
|
||||||
|
}
|
||||||
|
return &promptkit.GenerateResponse{Content: fmt.Sprintf(`{"value":%d}`, value)}, nil
|
||||||
|
}))
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
arrived := make(chan struct{}, 2)
|
||||||
|
release := make(chan struct{})
|
||||||
|
type response struct {
|
||||||
|
want int
|
||||||
|
result OperationResult[int]
|
||||||
|
err error
|
||||||
|
}
|
||||||
|
responses := make(chan response, 2)
|
||||||
|
for _, run := range []struct {
|
||||||
|
session string
|
||||||
|
value int
|
||||||
|
}{{"first", 1}, {"second", 2}} {
|
||||||
|
go func(session string, want int) {
|
||||||
|
initial := nativeProducerInitial()
|
||||||
|
initial.SessionID = session
|
||||||
|
execution := ExecutionContext[int]{Engine: engine, Controls: contracts.ProducerControls{Mode: contracts.ModeStrict}, Assess: func(ctx context.Context, value int) (contracts.CandidateAssessment, error) {
|
||||||
|
arrived <- struct{}{}
|
||||||
|
select {
|
||||||
|
case <-release:
|
||||||
|
case <-ctx.Done():
|
||||||
|
return contracts.CandidateAssessment{}, ctx.Err()
|
||||||
|
}
|
||||||
|
if value != want {
|
||||||
|
return contracts.CandidateAssessment{}, fmt.Errorf("assessment received %d, expected %d", value, want)
|
||||||
|
}
|
||||||
|
return contracts.CandidateAssessment{}, nil
|
||||||
|
}}
|
||||||
|
result, err := ExecuteOperation(ctx, execution, func(context.Context) (contracts.PreparedOperation[int], error) {
|
||||||
|
return contracts.NativeOperation[int]{Initial: initial, Interpret: interpretNumberEvaluation}, nil
|
||||||
|
})
|
||||||
|
responses <- response{want: want, result: result, err: err}
|
||||||
|
}(run.session, run.value)
|
||||||
|
}
|
||||||
|
for range 2 {
|
||||||
|
select {
|
||||||
|
case <-arrived:
|
||||||
|
case <-ctx.Done():
|
||||||
|
t.Fatal("concurrent assessments did not arrive")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close(release)
|
||||||
|
for range 2 {
|
||||||
|
got := <-responses
|
||||||
|
if got.err != nil || got.result.Value != got.want || got.result.Evaluation == nil || got.result.Evaluation.View().Candidate == nil || *got.result.Evaluation.View().Candidate != got.want {
|
||||||
|
t.Fatalf("operation want=%d result=%#v error=%v", got.want, got.result, got.err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user