Bound concurrent section work and finalize proposal identities in order
This commit is contained in:
@@ -176,27 +176,26 @@ func TestCanceledEmptyPipelineReturnsCancellation(t *testing.T) {
|
||||
|
||||
func TestRunnerRetainsLaterProposalEvidenceWhenEarlierSectionFails(t *testing.T) {
|
||||
origin := errors.New("earlier proposal failed")
|
||||
laterCompleted := make(chan struct{})
|
||||
laterValidationStarted := make(chan struct{})
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
var validations atomic.Int32
|
||||
module := outcomeModule{
|
||||
fakeModule: fakeModule{key: "grammar", policy: proposals.ReplacementPolicyRequireUnique, validators: []validators.Validator{
|
||||
contextValidator{validate: func(context.Context, validators.Request) (validators.Result, error) {
|
||||
validations.Add(1)
|
||||
return validators.Result{}, errors.New("validation should not be submitted")
|
||||
contextValidator{validate: func(ctx context.Context, req validators.Request) (validators.Result, error) {
|
||||
close(laterValidationStarted)
|
||||
<-ctx.Done()
|
||||
return validators.Result{}, ctx.Err()
|
||||
}},
|
||||
}},
|
||||
proposeResult: func(req contracts.ProposalRequest) (contracts.ProposalResult, error) {
|
||||
if req.Section.Index == 0 {
|
||||
select {
|
||||
case <-laterCompleted:
|
||||
case <-laterValidationStarted:
|
||||
return contracts.ProposalResult{}, origin
|
||||
case <-ctx.Done():
|
||||
return contracts.ProposalResult{}, ctx.Err()
|
||||
}
|
||||
}
|
||||
close(laterCompleted)
|
||||
return contracts.ProposalResult{
|
||||
Proposals: []proposals.CorrectionProposal{{TargetSegmentID: 93, OriginalText: "other", CorrectedText: "Other"}},
|
||||
SegmentReferences: []int{1},
|
||||
@@ -212,8 +211,8 @@ func TestRunnerRetainsLaterProposalEvidenceWhenEarlierSectionFails(t *testing.T)
|
||||
Transcript: &schema.Transcript{Segments: []schema.Segment{{ID: 71, Text: "original text"}, {ID: 93, Text: "other text"}}},
|
||||
ModuleSpecs: []contracts.ModuleRunSpec{{ModuleKey: "grammar", InstanceName: "grammar"}},
|
||||
})
|
||||
if !errors.Is(err, origin) || validations.Load() != 0 || len(out.Candidates) != 1 || len(out.WorkUnits) != 2 {
|
||||
t.Fatalf("interrupted evidence: candidates=%+v work=%+v validations=%d error=%v", out.Candidates, out.WorkUnits, validations.Load(), err)
|
||||
if !errors.Is(err, origin) || len(out.Candidates) != 1 || len(out.WorkUnits) != 2 {
|
||||
t.Fatalf("interrupted evidence: candidates=%+v work=%+v error=%v", out.Candidates, out.WorkUnits, err)
|
||||
}
|
||||
var failure *ExecutionFailure
|
||||
if !errors.As(err, &failure) || failure.Phase != "proposal" || !failure.HasSection ||
|
||||
@@ -222,7 +221,7 @@ func TestRunnerRetainsLaterProposalEvidenceWhenEarlierSectionFails(t *testing.T)
|
||||
}
|
||||
candidate := out.Candidates[0]
|
||||
later := out.WorkUnits[1]
|
||||
if candidate.ProposalIndex != 0 || candidate.TargetSegmentID != 93 || later.State != outcomes.WorkInterrupted ||
|
||||
if candidate.ProposalIndex != 0 || candidate.TargetSegmentID != 93 || later.State != outcomes.WorkInterrupted || later.Failure == nil || !errors.Is(later.Failure, context.Canceled) ||
|
||||
len(later.Operations) != 1 || len(later.Operations[0].ProposalIndices) != 1 || later.Operations[0].ProposalIndices[0] != candidate.ProposalIndex ||
|
||||
out.FinalTranscript.Segments[1].Text != "other text" {
|
||||
t.Fatalf("later candidate or association lost: candidate=%+v work=%+v", candidate, later)
|
||||
|
||||
Reference in New Issue
Block a user