Release extraction intermediates after their last consumers
This commit is contained in:
77
internal/framework/pipeline/runner_lifetime_test.go
Normal file
77
internal/framework/pipeline/runner_lifetime_test.go
Normal file
@@ -0,0 +1,77 @@
|
||||
package pipeline
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"testing/synctest"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
)
|
||||
|
||||
func TestLaneReleasesExtractValuesWhileSiblingRuns(t *testing.T) {
|
||||
synctest.Test(t, func(t *testing.T) {
|
||||
prepared := preparedConcurrentPipeline(t, 1)
|
||||
doc := typedTestDocumentWithUnits(1)
|
||||
_, chunks, err := validateAndMaterializeChunkPlan(doc, typedTestPlan(doc))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
input := RunInput{Prepared: prepared, Workers: 2, pipeline: prepared.resolved}
|
||||
states, err := initializeLaneStates(input, prepared.Steps[0], chunks)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
release := make(chan struct{})
|
||||
installExtractOperation(prepared, 1, func(ctx context.Context, request contracts.ExtractionInput) (erasedTypedResult, error) {
|
||||
select {
|
||||
case <-release:
|
||||
case <-ctx.Done():
|
||||
return erasedTypedResult{}, ctx.Err()
|
||||
}
|
||||
return erasedTypedResult{Value: typedValueForLane(1, request.Chunk.Index)}, nil
|
||||
})
|
||||
completed := make(chan struct{})
|
||||
original := prepared.Steps[0].lanes[0].typed.normalize
|
||||
prepared.Steps[0].lanes[0].typed.normalize = func(ctx context.Context, implementation any, request contracts.NormalizeInput[any], execution ExecutionContext[any]) (erasedTypedResult, error) {
|
||||
result, err := original(ctx, implementation, request, execution)
|
||||
close(completed)
|
||||
return result, err
|
||||
}
|
||||
type result struct {
|
||||
outputs []laneOutput
|
||||
errors []orderedRunError
|
||||
}
|
||||
done := make(chan result, 1)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
go func() {
|
||||
outputs, failures := New().runLaneEngine(ctx, laneEngineConfig{input: input, doc: doc, chunks: chunks, states: states})
|
||||
done <- result{outputs, failures}
|
||||
}()
|
||||
<-completed
|
||||
synctest.Wait()
|
||||
if states[0].results != nil || states[0].values != nil {
|
||||
t.Fatal("completed lane retains extraction intermediates")
|
||||
}
|
||||
close(release)
|
||||
got := <-done
|
||||
if len(got.errors) != 0 {
|
||||
t.Fatalf("lane errors = %v", got.errors)
|
||||
}
|
||||
if len(got.outputs[0].normalizeOutputs) != 1 || len(got.outputs[1].normalizeOutputs) != 1 {
|
||||
t.Fatalf("normalized outputs were retired early: %#v", got.outputs)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestFinalizeLaneExtractReleasesReorderMapWithoutMutatingArtifacts(t *testing.T) {
|
||||
value := erasedExtractArtifact{Value: codecNotes{Items: []string{"kept"}}}
|
||||
state := &laneExtractState{results: map[int]extractJobResult{0: {value: value}}}
|
||||
finalizeLaneExtract(state)
|
||||
if state.results != nil || len(state.values) != 1 {
|
||||
t.Fatalf("finalized state = %#v", state)
|
||||
}
|
||||
if got := state.values[0].Value.(codecNotes).Items[0]; got != "kept" {
|
||||
t.Fatalf("artifact value = %q", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user