Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Go: fix context (#18291)

Jin Hai2c775d054998
diff --git a/internal/agent/workflowx/loop_example_test.go b/internal/agent/workflowx/loop_example_test.go
index 0dc7c1308d..2b474de6b7 100644
--- a/internal/agent/workflowx/loop_example_test.go
+++ b/internal/agent/workflowx/loop_example_test.go
@@ -44,7 +44,7 @@ import (
// uses the do-while contract via shouldQuit(next >= 3), so iterations
// run as: in=0 -> 1, in=1 -> 2, in=2 -> 3 (quit). Final output: 3.
func TestExample_AddLoopNode(t *testing.T) {
- ctx := context.Background()
+ ctx := t.Context()
sub := compose.NewWorkflow[int, int]()
inc := compose.InvokableLambda(func(_ context.Context, in int) (int, error) {
diff --git a/internal/agent/workflowx/loop_integration_test.go b/internal/agent/workflowx/loop_integration_test.go
index 94b4c418d1..b36cc6274f 100644
--- a/internal/agent/workflowx/loop_integration_test.go
+++ b/internal/agent/workflowx/loop_integration_test.go
@@ -153,6 +153,7 @@ func drainStreamUntilError(t *testing.T, sr *schema.StreamReader[int]) ([]int, e
// "Outer callbacks versus inner callbacks" requirement: the
// sub-workflow sees one execution per iteration.
func TestIntegration_OuterVsInnerCallback_Counts(t *testing.T) {
+ ctx := t.Context()
var subCalls atomic.Int64
subStore := newInMemoryStore()
sub := counterSub(t, &subCalls)
@@ -161,7 +162,7 @@ func TestIntegration_OuterVsInnerCallback_Counts(t *testing.T) {
return next >= 3, nil
}
outer := compose.NewWorkflow[int, int]()
- loopNode, err := AddLoopNode(context.Background(), outer, "loop", sub, shouldQuit,
+ loopNode, err := AddLoopNode(ctx, outer, "loop", sub, shouldQuit,
WithLoopMaxIterations(10),
WithLoopCompileOptions(compose.WithCheckPointStore(subStore)),
WithLoopCheckpointIDBuilder(func(_ string, iter int) string {
@@ -173,11 +174,11 @@ func TestIntegration_OuterVsInnerCallback_Counts(t *testing.T) {
}
loopNode.AddInput(compose.START)
outer.End().AddInput("loop")
- compiled, err := outer.Compile(context.Background())
+ compiled, err := outer.Compile(ctx)
if err != nil {
t.Fatalf("compile: %v", err)
}
- if _, err := compiled.Invoke(context.Background(), 0); err != nil {
+ if _, err = compiled.Invoke(ctx, 0); err != nil {
t.Fatalf("invoke: %v", err)
}
if got := subCalls.Load(); got != 3 {
@@ -193,6 +194,7 @@ func TestIntegration_OuterVsInnerCallback_Counts(t *testing.T) {
// the InterruptInfo tree because that is how downstream callers
// distinguish a loop-internal interrupt from a user-level one.
func TestIntegration_SubWorkflowInterrupt_PropagatedAsComposite(t *testing.T) {
+ ctx := t.Context()
outerStore := newInMemoryStore()
subStore := newInMemoryStore()
sub := interruptingSub(t)
@@ -201,7 +203,7 @@ func TestIntegration_SubWorkflowInterrupt_PropagatedAsComposite(t *testing.T) {
return true, nil
}
outer := compose.NewWorkflow[int, int]()
- loopNode, err := AddLoopNode(context.Background(), outer, "loop", sub, shouldQuit,
+ loopNode, err := AddLoopNode(ctx, outer, "loop", sub, shouldQuit,
WithLoopMaxIterations(5),
WithLoopCompileOptions(compose.WithCheckPointStore(subStore)),
WithLoopCheckpointIDBuilder(func(_ string, iter int) string {
@@ -213,14 +215,14 @@ func TestIntegration_SubWorkflowInterrupt_PropagatedAsComposite(t *testing.T) {
}
loopNode.AddInput(compose.START)
outer.End().AddInput("loop")
- compiled, err := outer.Compile(context.Background(),
+ compiled, err := outer.Compile(ctx,
compose.WithCheckPointStore(outerStore),
)
if err != nil {
t.Fatalf("compile: %v", err)
}
- _, err = compiled.Invoke(context.Background(), 0,
+ _, err = compiled.Invoke(ctx, 0,
compose.WithCheckPointID("outer-cp"),
)
if err == nil {
@@ -239,8 +241,8 @@ func TestIntegration_SubWorkflowInterrupt_PropagatedAsComposite(t *testing.T) {
if i == nil {
return
}
- for _, ctx := range i.InterruptContexts {
- if s, ok := ctx.Info.(string); ok && s == "sub-interrupt" {
+ for _, interruptCtx := range i.InterruptContexts {
+ if s, ok := interruptCtx.Info.(string); ok && s == "sub-interrupt" {
foundSubInterrupt = true
}
}
@@ -258,6 +260,7 @@ func TestIntegration_SubWorkflowInterrupt_PropagatedAsComposite(t *testing.T) {
// the sub-workflow interrupts, the outer checkpoint payload
// exists (i.e. the framework has written the loop's state).
func TestIntegration_LoopStatePersistedOnInterrupt(t *testing.T) {
+ ctx := t.Context()
outerStore := newInMemoryStore()
subStore := newInMemoryStore()
sub := interruptingSub(t)
@@ -266,7 +269,7 @@ func TestIntegration_LoopStatePersistedOnInterrupt(t *testing.T) {
return true, nil
}
outer := compose.NewWorkflow[int, int]()
- loopNode, err := AddLoopNode(context.Background(), outer, "loop", sub, shouldQuit,
+ loopNode, err := AddLoopNode(ctx, outer, "loop", sub, shouldQuit,
WithLoopMaxIterations(5),
WithLoopCompileOptions(compose.WithCheckPointStore(subStore)),
WithLoopCheckpointIDBuilder(func(_ string, iter int) string {
@@ -278,7 +281,7 @@ func TestIntegration_LoopStatePersistedOnInterrupt(t *testing.T) {
}
loopNode.AddInput(compose.START)
outer.End().AddInput("loop")
- compiled, err := outer.Compile(context.Background(),
+ compiled, err := outer.Compile(ctx,
compose.WithCheckPointStore(outerStore),
)
if err != nil {
@@ -286,13 +289,13 @@ func TestIntegration_LoopStatePersistedOnInterrupt(t *testing.T) {
}
cpID := "outer-cp-persist"
- _, err = compiled.Invoke(context.Background(), 0,
+ _, err = compiled.Invoke(ctx, 0,
compose.WithCheckPointID(cpID),
)
if err == nil {
t.Fatal("expected interrupt error, got nil")
}
- if _, found, _ := outerStore.Get(context.Background(), cpID); !found {
+ if _, found, _ := outerStore.Get(ctx, cpID); !found {
t.Errorf("outer checkpoint %q not written", cpID)
}
}
@@ -302,6 +305,7 @@ func TestIntegration_LoopStatePersistedOnInterrupt(t *testing.T) {
// cap. This uses a non-interrupting sub-workflow so the loop actually reaches
// the cap.
func TestIntegration_ExplicitMaxIterationsStops_OnInvokePath(t *testing.T) {
+ ctx := t.Context()
var subCalls atomic.Int64
subStore := newInMemoryStore()
sub := counterSub(t, &subCalls)
@@ -310,7 +314,7 @@ func TestIntegration_ExplicitMaxIterationsStops_OnInvokePath(t *testing.T) {
return false, nil // never quits
}
outer := compose.NewWorkflow[int, int]()
- loopNode, err := AddLoopNode(context.Background(), outer, "loop", sub, shouldQuit,
+ loopNode, err := AddLoopNode(ctx, outer, "loop", sub, shouldQuit,
WithLoopMaxIterations(3),
WithLoopCompileOptions(compose.WithCheckPointStore(subStore)),
WithLoopCheckpointIDBuilder(func(_ string, iter int) string {
@@ -322,12 +326,12 @@ func TestIntegration_ExplicitMaxIterationsStops_OnInvokePath(t *testing.T) {
}
loopNode.AddInput(compose.START)
outer.End().AddInput("loop")
- compiled, err := outer.Compile(context.Background())
+ compiled, err := outer.Compile(ctx)
if err != nil {
t.Fatalf("compile: %v", err)
}
- out, err := compiled.Invoke(context.Background(), 0)
+ out, err := compiled.Invoke(ctx, 0)
if err != nil {
t.Fatalf("Invoke: %v", err)
}
@@ -345,6 +349,7 @@ func TestIntegration_ExplicitMaxIterationsStops_OnInvokePath(t *testing.T) {
// in loop_test.go, this exercises the full compile/invoke path
// and confirms the loop survives eino's runner.
func TestIntegration_LoopRunsConcurrentlyWithResumeData(t *testing.T) {
+ ctx := t.Context()
store := newInMemoryStore()
sub := interruptingSub(t)
@@ -352,7 +357,7 @@ func TestIntegration_LoopRunsConcurrentlyWithResumeData(t *testing.T) {
return next >= 2, nil
}
outer := compose.NewWorkflow[int, int]()
- loopNode, err := AddLoopNode(context.Background(), outer, "loop", sub, shouldQuit,
+ loopNode, err := AddLoopNode(ctx, outer, "loop", sub, shouldQuit,
WithLoopMaxIterations(10),
WithLoopCompileOptions(compose.WithCheckPointStore(store)),
WithLoopCheckpointIDBuilder(func(_ string, iter int) string {
@@ -364,7 +369,7 @@ func TestIntegration_LoopRunsConcurrentlyWithResumeData(t *testing.T) {
}
loopNode.AddInput(compose.START)
outer.End().AddInput("loop")
- compiled, err := outer.Compile(context.Background(),
+ compiled, err := outer.Compile(ctx,
compose.WithCheckPointStore(store),
)
if err != nil {
@@ -375,7 +380,7 @@ func TestIntegration_LoopRunsConcurrentlyWithResumeData(t *testing.T) {
// call; the loop must persist state and return an
// interrupt error.
cpID := "outer-cp-e2e"
- _, err = compiled.Invoke(context.Background(), 0,
+ _, err = compiled.Invoke(ctx, 0,
compose.WithCheckPointID(cpID),
)
if err == nil {
@@ -394,6 +399,7 @@ func TestIntegration_LoopRunsConcurrentlyWithResumeData(t *testing.T) {
// fail with "receive checkpoint id but have not set checkpoint
// store".
func TestIntegration_EnableSubCheckpoint_HappyPath(t *testing.T) {
+ ctx := t.Context()
var subCalls atomic.Int64
subStore := newInMemoryStore()
sub := counterSub(t, &subCalls)
@@ -402,7 +408,7 @@ func TestIntegration_EnableSubCheckpoint_HappyPath(t *testing.T) {
return next >= 2, nil
}
outer := compose.NewWorkflow[int, int]()
- loopNode, err := AddLoopNode(context.Background(), outer, "loop", sub, shouldQuit,
+ loopNode, err := AddLoopNode(ctx, outer, "loop", sub, shouldQuit,
WithLoopMaxIterations(5),
WithLoopCompileOptions(compose.WithCheckPointStore(subStore)),
WithLoopEnableSubCheckpoint(true),
@@ -415,11 +421,11 @@ func TestIntegration_EnableSubCheckpoint_HappyPath(t *testing.T) {
}
loopNode.AddInput(compose.START)
outer.End().AddInput("loop")
- compiled, err := outer.Compile(context.Background())
+ compiled, err := outer.Compile(ctx)
if err != nil {
t.Fatalf("compile: %v", err)
}
- if _, err := compiled.Invoke(context.Background(), 0); err != nil {
+ if _, err = compiled.Invoke(ctx, 0); err != nil {
t.Fatalf("invoke: %v", err)
}
if got := subCalls.Load(); got != 2 {
@@ -431,6 +437,7 @@ func TestIntegration_EnableSubCheckpoint_HappyPath(t *testing.T) {
// resume contract: an interrupt during iteration N resumes at
// iteration N rather than restarting from 1.
func TestIntegration_ResumeContinuesSameIteration(t *testing.T) {
+ ctx := t.Context()
store := newInMemoryStore()
sub := compose.NewWorkflow[int, int]()
@@ -454,7 +461,7 @@ func TestIntegration_ResumeContinuesSameIteration(t *testing.T) {
}
outer := compose.NewWorkflow[int, int]()
- loopNode, err := AddLoopNode(context.Background(), outer, "loop", sub, shouldQuit,
+ loopNode, err := AddLoopNode(ctx, outer, "loop", sub, shouldQuit,
WithLoopMaxIterations(10),
WithLoopCheckpointIDBuilder(func(_ string, iter int) string {
return "resume-same-iter:" + itoa(iter)
@@ -465,17 +472,17 @@ func TestIntegration_ResumeContinuesSameIteration(t *testing.T) {
}
loopNode.AddInput(compose.START)
outer.End().AddInput("loop")
- compiled, err := outer.Compile(context.Background(), compose.WithCheckPointStore(store))
+ compiled, err := outer.Compile(ctx, compose.WithCheckPointStore(store))
if err != nil {
t.Fatalf("compile: %v", err)
}
cpID := "resume-same-iteration"
- _, err = compiled.Invoke(context.Background(), 0, compose.WithCheckPointID(cpID))
+ _, err = compiled.Invoke(ctx, 0, compose.WithCheckPointID(cpID))
if err == nil {
t.Fatal("expected interrupt error, got nil")
}
- resumeCtx := compose.Resume(context.Background(), firstRootInterruptID(t, err))
+ resumeCtx := compose.Resume(ctx, firstRootInterruptID(t, err))
out, err := compiled.Invoke(resumeCtx, 0, compose.WithCheckPointID(cpID))
if err != nil {
t.Fatalf("resume invoke: %v", err)
@@ -498,6 +505,7 @@ func TestIntegration_ResumeContinuesSameIteration(t *testing.T) {
// WithForceNewRun ignores the saved loop checkpoint and restarts
// the loop from iteration 1 on the next invocation.
func TestIntegration_WithForceNewRunRestartsLoop(t *testing.T) {
+ ctx := t.Context()
store := newInMemoryStore()
sub := compose.NewWorkflow[int, int]()
@@ -521,7 +529,7 @@ func TestIntegration_WithForceNewRunRestartsLoop(t *testing.T) {
}
outer := compose.NewWorkflow[int, int]()
- loopNode, err := AddLoopNode(context.Background(), outer, "loop", sub, shouldQuit,
+ loopNode, err := AddLoopNode(ctx, outer, "loop", sub, shouldQuit,
WithLoopMaxIterations(10),
WithLoopCheckpointIDBuilder(func(_ string, iter int) string {
return "force-new-run:" + itoa(iter)
@@ -532,17 +540,17 @@ func TestIntegration_WithForceNewRunRestartsLoop(t *testing.T) {
}
loopNode.AddInput(compose.START)
outer.End().AddInput("loop")
- compiled, err := outer.Compile(context.Background(), compose.WithCheckPointStore(store))
+ compiled, err := outer.Compile(ctx, compose.WithCheckPointStore(store))
if err != nil {
t.Fatalf("compile: %v", err)
}
cpID := "force-new-run"
- _, err = compiled.Invoke(context.Background(), 0, compose.WithCheckPointID(cpID))
+ _, err = compiled.Invoke(ctx, 0, compose.WithCheckPointID(cpID))
if err == nil {
t.Fatal("expected first interrupt, got nil")
}
- _, err = compiled.Invoke(context.Background(), 0,
+ _, err = compiled.Invoke(ctx, 0,
compose.WithCheckPointID(cpID),
compose.WithForceNewRun(),
)
@@ -567,6 +575,7 @@ func TestIntegration_WithForceNewRunRestartsLoop(t *testing.T) {
// the interrupt state is written to the designated checkpoint ID
// and can be resumed from that new location.
func TestIntegration_WithWriteToCheckPointIDPersistsToNewID(t *testing.T) {
+ ctx := t.Context()
store := newInMemoryStore()
sub := interruptingSub(t)
@@ -574,7 +583,7 @@ func TestIntegration_WithWriteToCheckPointIDPersistsToNewID(t *testing.T) {
return next >= 1, nil
}
outer := compose.NewWorkflow[int, int]()
- loopNode, err := AddLoopNode(context.Background(), outer, "loop", sub, shouldQuit,
+ loopNode, err := AddLoopNode(ctx, outer, "loop", sub, shouldQuit,
WithLoopMaxIterations(5),
WithLoopCheckpointIDBuilder(func(_ string, iter int) string {
return "write-to-cp:" + itoa(iter)
@@ -585,28 +594,28 @@ func TestIntegration_WithWriteToCheckPointIDPersistsToNewID(t *testing.T) {
}
loopNode.AddInput(compose.START)
outer.End().AddInput("loop")
- compiled, err := outer.Compile(context.Background(), compose.WithCheckPointStore(store))
+ compiled, err := outer.Compile(ctx, compose.WithCheckPointStore(store))
if err != nil {
t.Fatalf("compile: %v", err)
}
oldID := "loop-old"
newID := "loop-new"
- _, err = compiled.Invoke(context.Background(), 0,
+ _, err = compiled.Invoke(ctx, 0,
compose.WithCheckPointID(oldID),
compose.WithWriteToCheckPointID(newID),
)
if err == nil {
t.Fatal("expected interrupt error, got nil")
}
- if _, found, _ := store.Get(context.Background(), oldID); found {
+ if _, found, _ := store.Get(ctx, oldID); found {
t.Fatalf("old checkpoint %q should not be written", oldID)
}
- if _, found, _ := store.Get(context.Background(), newID); !found {
+ if _, found, _ := store.Get(ctx, newID); !found {
t.Fatalf("new checkpoint %q was not written", newID)
}
- resumeCtx := compose.Resume(context.Background(), firstRootInterruptID(t, err))
+ resumeCtx := compose.Resume(ctx, firstRootInterruptID(t, err))
out, err := compiled.Invoke(resumeCtx, 0, compose.WithCheckPointID(newID))
if err != nil {
t.Fatalf("resume invoke: %v", err)
@@ -620,6 +629,7 @@ func TestIntegration_WithWriteToCheckPointIDPersistsToNewID(t *testing.T) {
// asserts that FinalOnly mode does not expose historical iteration
// chunks after resume.
func TestIntegration_StreamFinalOnly_ResumeExposesOnlyFinalIteration(t *testing.T) {
+ ctx := t.Context()
store := newInMemoryStore()
sub := compose.NewWorkflow[int, int]()
@@ -648,7 +658,7 @@ func TestIntegration_StreamFinalOnly_ResumeExposesOnlyFinalIteration(t *testing.
return next >= 20, nil
}
outer := compose.NewWorkflow[int, int]()
- loopNode, err := AddLoopNode(context.Background(), outer, "loop", sub, shouldQuit,
+ loopNode, err := AddLoopNode(ctx, outer, "loop", sub, shouldQuit,
WithLoopStream(LoopStreamFinalOnly),
WithLoopMaxIterations(5),
WithLoopCheckpointIDBuilder(func(_ string, iter int) string {
@@ -660,20 +670,20 @@ func TestIntegration_StreamFinalOnly_ResumeExposesOnlyFinalIteration(t *testing.
}
loopNode.AddInput(compose.START)
outer.End().AddInput("loop")
- compiled, err := outer.Compile(context.Background(), compose.WithCheckPointStore(store))
+ compiled, err := outer.Compile(ctx, compose.WithCheckPointStore(store))
if err != nil {
t.Fatalf("compile: %v", err)
}
cpID := "stream-final-only"
- sr, err := compiled.Stream(context.Background(), 0, compose.WithCheckPointID(cpID))
+ sr, err := compiled.Stream(ctx, 0, compose.WithCheckPointID(cpID))
if err == nil {
_, err = drainStreamUntilError(t, sr)
}
if err == nil {
t.Fatal("expected interrupt error, got nil")
}
- sr, err = compiled.Stream(context.Background(), 0, compose.WithCheckPointID(cpID))
+ sr, err = compiled.Stream(ctx, 0, compose.WithCheckPointID(cpID))
if err != nil {
t.Fatalf("resume stream: %v", err)
}
@@ -697,6 +707,7 @@ func TestIntegration_StreamFinalOnly_ResumeExposesOnlyFinalIteration(t *testing.
// fully published iterations are not replayed, while the interrupted
// iteration is replayed from its start.
func TestIntegration_StreamEveryIteration_ResumeFromFirstUnpublishedIteration(t *testing.T) {
+ ctx := t.Context()
store := newInMemoryStore()
sub := compose.NewWorkflow[int, int]()
@@ -725,7 +736,7 @@ func TestIntegration_StreamEveryIteration_ResumeFromFirstUnpublishedIteration(t
return next >= 20, nil
}
outer := compose.NewWorkflow[int, int]()
- loopNode, err := AddLoopNode(context.Background(), outer, "loop", sub, shouldQuit,
+ loopNode, err := AddLoopNode(ctx, outer, "loop", sub, shouldQuit,
WithLoopStream(LoopStreamEveryIteration),
WithLoopMaxIterations(5),
WithLoopCheckpointIDBuilder(func(_ string, iter int) string {
@@ -737,20 +748,20 @@ func TestIntegration_StreamEveryIteration_ResumeFromFirstUnpublishedIteration(t
}
loopNode.AddInput(compose.START)
outer.End().AddInput("loop")
- compiled, err := outer.Compile(context.Background(), compose.WithCheckPointStore(store))
+ compiled, err := outer.Compile(ctx, compose.WithCheckPointStore(store))
if err != nil {
t.Fatalf("compile: %v", err)
}
cpID := "stream-every-iteration"
- sr, err := compiled.Stream(context.Background(), 0, compose.WithCheckPointID(cpID))
+ sr, err := compiled.Stream(ctx, 0, compose.WithCheckPointID(cpID))
if err == nil {
_, err = drainStreamUntilError(t, sr)
}
if err == nil {
t.Fatal("expected interrupt error, got nil")
}
- sr, err = compiled.Stream(context.Background(), 0, compose.WithCheckPointID(cpID))
+ sr, err = compiled.Stream(ctx, 0, compose.WithCheckPointID(cpID))
if err != nil {
t.Fatalf("resume stream: %v", err)
}
@@ -806,12 +817,13 @@ func streamingIncSub(t *testing.T) *compose.Workflow[int, int] {
// [2,3] (next=3, quit). Caller must observe ONLY the final iteration's
// chunks: [2, 3].
func TestIntegration_StreamFinalOnly_HappyPath(t *testing.T) {
+ ctx := t.Context()
sub := streamingIncSub(t)
shouldQuit := func(_ context.Context, _, _, next int) (bool, error) {
return next >= 3, nil
}
outer := compose.NewWorkflow[int, int]()
- loopNode, err := AddLoopNode(context.Background(), outer, "loop", sub, shouldQuit,
+ loopNode, err := AddLoopNode(ctx, outer, "loop", sub, shouldQuit,
WithLoopStream(LoopStreamFinalOnly),
WithLoopMaxIterations(10),
)
@@ -820,12 +832,12 @@ func TestIntegration_StreamFinalOnly_HappyPath(t *testing.T) {
}
loopNode.AddInput(compose.START)
outer.End().AddInput("loop")
- compiled, err := outer.Compile(context.Background())
+ compiled, err := outer.Compile(ctx)
if err != nil {
t.Fatalf("compile: %v", err)
}
- sr, err := compiled.Stream(context.Background(), 0)
+ sr, err := compiled.Stream(ctx, 0)
if err != nil {
t.Fatalf("stream: %v", err)
}
@@ -854,12 +866,13 @@ func TestIntegration_StreamFinalOnly_HappyPath(t *testing.T) {
// Caller must observe every iteration's chunks concatenated in order:
// [0, 1, 1, 2, 2, 3].
func TestIntegration_StreamEveryIteration_HappyPath(t *testing.T) {
+ ctx := t.Context()
sub := streamingIncSub(t)
shouldQuit := func(_ context.Context, _, _, next int) (bool, error) {
return next >= 3, nil
}
outer := compose.NewWorkflow[int, int]()
- loopNode, err := AddLoopNode(context.Background(), outer, "loop", sub, shouldQuit,
+ loopNode, err := AddLoopNode(ctx, outer, "loop", sub, shouldQuit,
WithLoopStream(LoopStreamEveryIteration),
WithLoopMaxIterations(10),
)
@@ -868,12 +881,12 @@ func TestIntegration_StreamEveryIteration_HappyPath(t *testing.T) {
}
loopNode.AddInput(compose.START)
outer.End().AddInput("loop")
- compiled, err := outer.Compile(context.Background())
+ compiled, err := outer.Compile(ctx)
if err != nil {
t.Fatalf("compile: %v", err)
}
- sr, err := compiled.Stream(context.Background(), 0)
+ sr, err := compiled.Stream(ctx, 0)
if err != nil {
t.Fatalf("stream: %v", err)
}
@@ -900,6 +913,7 @@ func TestIntegration_StreamEveryIteration_HappyPath(t *testing.T) {
// this test the branch (loop.go: "iteration N produced empty stream")
// is unreachable from the existing test surface.
func TestIntegration_Stream_EmptyIterationFails(t *testing.T) {
+ ctx := t.Context()
sub := compose.NewWorkflow[int, int]()
lambda, err := compose.AnyLambda[int, int, struct{}](
nil,
@@ -921,7 +935,7 @@ func TestIntegration_Stream_EmptyIterationFails(t *testing.T) {
return false, nil
}
outer := compose.NewWorkflow[int, int]()
- loopNode, err := AddLoopNode(context.Background(), outer, "loop", sub, shouldQuit,
+ loopNode, err := AddLoopNode(ctx, outer, "loop", sub, shouldQuit,
WithLoopStream(LoopStreamFinalOnly),
WithLoopMaxIterations(3),
)
@@ -930,12 +944,12 @@ func TestIntegration_Stream_EmptyIterationFails(t *testing.T) {
}
loopNode.AddInput(compose.START)
outer.End().AddInput("loop")
- compiled, err := outer.Compile(context.Background())
+ compiled, err := outer.Compile(ctx)
if err != nil {
t.Fatalf("compile: %v", err)
}
- sr, err := compiled.Stream(context.Background(), 0)
+ sr, err := compiled.Stream(ctx, 0)
if err == nil {
_, err = readAllInts(t, sr)
}
diff --git a/internal/agent/workflowx/loop_options_test.go b/internal/agent/workflowx/loop_options_test.go
index 5d145e5d76..db60be8185 100644
--- a/internal/agent/workflowx/loop_options_test.go
+++ b/internal/agent/workflowx/loop_options_test.go
@@ -179,6 +179,7 @@ func TestOptions_CheckpointBuilder_NilIgnored(t *testing.T) {
// We use a counter sub-workflow and check that the run option is
// observed on each call by counting sub-invocations.
func TestOptions_RunOptionsForwarded(t *testing.T) {
+ ctx := t.Context()
var counter atomic.Int64
sub := buildSubCounter(t, &counter)
@@ -186,7 +187,7 @@ func TestOptions_RunOptionsForwarded(t *testing.T) {
return next >= 3, nil
}
outer := compose.NewWorkflow[int, int]()
- loopNode, err := AddLoopNode(context.Background(), outer, "loop", sub, shouldQuit,
+ loopNode, err := AddLoopNode(ctx, outer, "loop", sub, shouldQuit,
WithLoopMaxIterations(10),
)
if err != nil {
@@ -194,11 +195,11 @@ func TestOptions_RunOptionsForwarded(t *testing.T) {
}
loopNode.AddInput(compose.START)
outer.End().AddInput("loop")
- compiled, err := outer.Compile(context.Background())
+ compiled, err := outer.Compile(ctx)
if err != nil {
t.Fatalf("compile: %v", err)
}
- if _, err := compiled.Invoke(context.Background(), 0); err != nil {
+ if _, err := compiled.Invoke(ctx, 0); err != nil {
t.Fatalf("invoke: %v", err)
}
if got := counter.Load(); got != 3 {
@@ -212,8 +213,9 @@ func TestOptions_RunOptionsForwarded(t *testing.T) {
// store is wired in, subsequent sub-workflow invocations have
// access to it. The store is exercised via a simple key lookup.
func TestOptions_CompileOptionsForwarded(t *testing.T) {
+ ctx := t.Context()
store := newInMemoryStore()
- _ = store.Set(context.Background(), "k", []byte("v"))
+ _ = store.Set(ctx, "k", []byte("v"))
sub := compose.NewWorkflow[int, int]()
lambda := compose.InvokableLambda(func(ctx context.Context, in int) (int, error) {
@@ -233,7 +235,7 @@ func TestOptions_CompileOptionsForwarded(t *testing.T) {
return next >= 2, nil
}
outer := compose.NewWorkflow[int, int]()
- loopNode, err := AddLoopNode(context.Background(), outer, "loop", sub, shouldQuit,
+ loopNode, err := AddLoopNode(ctx, outer, "loop", sub, shouldQuit,
WithLoopMaxIterations(5),
WithLoopCompileOptions(compose.WithCheckPointStore(store)),
)
@@ -242,11 +244,11 @@ func TestOptions_CompileOptionsForwarded(t *testing.T) {
}
loopNode.AddInput(compose.START)
outer.End().AddInput("loop")
- compiled, err := outer.Compile(context.Background())
+ compiled, err := outer.Compile(ctx)
if err != nil {
t.Fatalf("compile: %v", err)
}
- out, err := compiled.Invoke(context.Background(), 0)
+ out, err := compiled.Invoke(ctx, 0)
if err != nil {
t.Fatalf("invoke: %v", err)
}
@@ -258,6 +260,7 @@ func TestOptions_CompileOptionsForwarded(t *testing.T) {
// TestOptions_NilChecks verifies that AddLoopNode rejects nil
// inputs up front, before any compile work happens.
func TestOptions_NilChecks(t *testing.T) {
+ ctx := t.Context()
sub := buildSubIncrement(t)
shouldQuit := func(_ context.Context, _, _, _ int) (bool, error) {
return true, nil
@@ -269,15 +272,15 @@ func TestOptions_NilChecks(t *testing.T) {
fn func() error
}{
{"nil outer", func() error {
- _, err := AddLoopNode(context.Background(), nil, "loop", sub, shouldQuit)
+ _, err := AddLoopNode(ctx, nil, "loop", sub, shouldQuit)
return err
}},
{"nil sub", func() error {
- _, err := AddLoopNode(context.Background(), outer, "loop", nil, shouldQuit)
+ _, err := AddLoopNode(ctx, outer, "loop", nil, shouldQuit)
return err
}},
{"nil shouldQuit", func() error {
- _, err := AddLoopNode(context.Background(), outer, "loop", sub, nil)
+ _, err := AddLoopNode(ctx, outer, "loop", sub, nil)
return err
}},
}
@@ -299,19 +302,20 @@ func TestOptions_NilChecks(t *testing.T) {
// We construct a sub-workflow with no start node so compile fails
// deterministically.
func TestOptions_CompileFailureIsolated(t *testing.T) {
+ ctx := t.Context()
sub := compose.NewWorkflow[int, int]() // no nodes; compile will fail
shouldQuit := func(_ context.Context, _, _, _ int) (bool, error) {
return true, nil
}
outer := compose.NewWorkflow[int, int]()
- _, err := AddLoopNode(context.Background(), outer, "loop", sub, shouldQuit)
+ _, err := AddLoopNode(ctx, outer, "loop", sub, shouldQuit)
if err == nil {
t.Fatal("expected compile error, got nil")
}
// The outer workflow should still be empty. Re-compiling it
// must fail with "start node not set", proving the loop
// didn't silently add a placeholder node.
- _, err = outer.Compile(context.Background())
+ _, err = outer.Compile(ctx)
if err == nil || !strings.Contains(err.Error(), "start node not set") {
t.Errorf("outer workflow not in expected state: %v", err)
}
diff --git a/internal/agent/workflowx/loop_test.go b/internal/agent/workflowx/loop_test.go
index 1aff248fe5..15c04043a4 100644
--- a/internal/agent/workflowx/loop_test.go
+++ b/internal/agent/workflowx/loop_test.go
@@ -86,6 +86,7 @@ func buildSubIncrement(t *testing.T) *compose.Workflow[int, int] {
// increment, and shouldQuit returns true once the value reaches 4,
// so the loop runs 3 times.
func TestLoop_IterationNumbering(t *testing.T) {
+ ctx := t.Context()
var iterations []int
shouldQuit := func(_ context.Context, iter, prev, next int) (bool, error) {
iterations = append(iterations, iter)
@@ -93,7 +94,7 @@ func TestLoop_IterationNumbering(t *testing.T) {
}
outer := compose.NewWorkflow[int, int]()
- loopNode, err := AddLoopNode(context.Background(), outer, "loop",
+ loopNode, err := AddLoopNode(ctx, outer, "loop",
buildSubIncrement(t), shouldQuit,
WithLoopMaxIterations(10),
)
@@ -102,11 +103,11 @@ func TestLoop_IterationNumbering(t *testing.T) {
}
loopNode.AddInput(compose.START)
outer.End().AddInput("loop")
- compiled, err := outer.Compile(context.Background())
+ compiled, err := outer.Compile(ctx)
if err != nil {
t.Fatalf("compile: %v", err)
}
- out, err := compiled.Invoke(context.Background(), 1)
+ out, err := compiled.Invoke(ctx, 1)
if err != nil {
t.Fatalf("invoke: %v", err)
}
@@ -129,13 +130,14 @@ func TestLoop_IterationNumbering(t *testing.T) {
// do-while: shouldQuit is called once with iter=1 and the loop
// exits.
func TestLoop_DoWhileContract(t *testing.T) {
+ ctx := t.Context()
var seen int
shouldQuit := func(_ context.Context, iter, prev, next int) (bool, error) {
seen = iter
return true, nil
}
outer := compose.NewWorkflow[int, int]()
- loopNode, err := AddLoopNode(context.Background(), outer, "loop",
+ loopNode, err := AddLoopNode(ctx, outer, "loop",
buildSubIncrement(t), shouldQuit,
WithLoopMaxIterations(1),
)
@@ -144,11 +146,11 @@ func TestLoop_DoWhileContract(t *testing.T) {
}
loopNode.AddInput(compose.START)
outer.End().AddInput("loop")
- compiled, err := outer.Compile(context.Background())
+ compiled, err := outer.Compile(ctx)
if err != nil {
t.Fatalf("compile: %v", err)
}
- out, err := compiled.Invoke(context.Background(), 7)
+ out, err := compiled.Invoke(ctx, 7)
if err != nil {
t.Fatalf("invoke: %v", err)
}
@@ -164,11 +166,12 @@ func TestLoop_DoWhileContract(t *testing.T) {
// explicitly configured cap returns the final iteration output. Canvas
// maximum_loop_count uses this as normal termination.
func TestLoop_ExplicitMaxIterationsStops(t *testing.T) {
+ ctx := t.Context()
shouldQuit := func(_ context.Context, _ int, _, _ int) (bool, error) {
return false, nil
}
outer := compose.NewWorkflow[int, int]()
- loopNode, err := AddLoopNode(context.Background(), outer, "loop",
+ loopNode, err := AddLoopNode(ctx, outer, "loop",
buildSubIncrement(t), shouldQuit,
WithLoopMaxIterations(3),
)
@@ -177,11 +180,11 @@ func TestLoop_ExplicitMaxIterationsStops(t *testing.T) {
}
loopNode.AddInput(compose.START)
outer.End().AddInput("loop")
- compiled, err := outer.Compile(context.Background())
+ compiled, err := outer.Compile(ctx)
if err != nil {
t.Fatalf("compile: %v", err)
}
- out, err := compiled.Invoke(context.Background(), 0)
+ out, err := compiled.Invoke(ctx, 0)
if err != nil {
t.Fatalf("invoke: %v", err)
}
@@ -194,10 +197,11 @@ func TestLoop_ExplicitMaxIterationsStops(t *testing.T) {
// safety cap remains an error. The test lowers the internal cap to keep the
// case small while preserving the "not user configured" option state.
func TestLoop_DefaultSafetyMaxIterationsExceeded(t *testing.T) {
+ ctx := t.Context()
shouldQuit := func(_ context.Context, _ int, _, _ int) (bool, error) {
return false, nil
}
- compiledSub, err := buildSubIncrement(t).Compile(context.Background())
+ compiledSub, err := buildSubIncrement(t).Compile(ctx)
if err != nil {
t.Fatalf("compile sub: %v", err)
}
@@ -205,7 +209,7 @@ func TestLoop_DefaultSafetyMaxIterationsExceeded(t *testing.T) {
options.maxIterations = 3
options.enableSubCheckpoint = false
- _, err = runLoopInvoke(context.Background(), "loop", compiledSub, 0, shouldQuit, options)
+ _, err = runLoopInvoke(ctx, "loop", compiledSub, 0, shouldQuit, options)
if !errors.Is(err, ErrLoopMaxIterationsExceeded) {
t.Fatalf("runLoopInvoke: got %v, want ErrLoopMaxIterationsExceeded", err)
}
@@ -214,11 +218,12 @@ func TestLoop_DefaultSafetyMaxIterationsExceeded(t *testing.T) {
// TestLoop_QuitConditionError asserts that a non-nil error from
// shouldQuit is wrapped in ErrLoopQuitConditionFailed.
func TestLoop_QuitConditionError(t *testing.T) {
+ ctx := t.Context()
shouldQuit := func(_ context.Context, _ int, _, _ int) (bool, error) {
return false, errors.New("boom")
}
outer := compose.NewWorkflow[int, int]()
- loopNode, err := AddLoopNode(context.Background(), outer, "loop",
+ loopNode, err := AddLoopNode(ctx, outer, "loop",
buildSubIncrement(t), shouldQuit,
WithLoopMaxIterations(5),
)
@@ -227,11 +232,11 @@ func TestLoop_QuitConditionError(t *testing.T) {
}
loopNode.AddInput(compose.START)
outer.End().AddInput("loop")
- compiled, err := outer.Compile(context.Background())
+ compiled, err := outer.Compile(ctx)
if err != nil {
t.Fatalf("compile: %v", err)
}
- _, err = compiled.Invoke(context.Background(), 0)
+ _, err = compiled.Invoke(ctx, 0)
if !errors.Is(err, ErrLoopQuitConditionFailed) {
t.Fatalf("invoke: got %v, want ErrLoopQuitConditionFailed", err)
}
@@ -242,11 +247,12 @@ func TestLoop_QuitConditionError(t *testing.T) {
// TestLoop_NormalConvergence asserts the basic happy path.
func TestLoop_NormalConvergence(t *testing.T) {
+ ctx := t.Context()
shouldQuit := func(_ context.Context, _, _, next int) (bool, error) {
return next >= 3, nil
}
outer := compose.NewWorkflow[int, int]()
- loopNode, err := AddLoopNode(context.Background(), outer, "loop",
+ loopNode, err := AddLoopNode(ctx, outer, "loop",
buildSubIncrement(t), shouldQuit,
WithLoopMaxIterations(10),
)
@@ -255,11 +261,11 @@ func TestLoop_NormalConvergence(t *testing.T) {
}
loopNode.AddInput(compose.START)
outer.End().AddInput("loop")
- compiled, err := outer.Compile(context.Background())
+ compiled, err := outer.Compile(ctx)
if err != nil {
t.Fatalf("compile: %v", err)
}
- out, err := compiled.Invoke(context.Background(), 0)
+ out, err := compiled.Invoke(ctx, 0)
if err != nil {
t.Fatalf("invoke: %v", err)
}
@@ -273,6 +279,7 @@ func TestLoop_NormalConvergence(t *testing.T) {
// ErrLoopSubGraphInterrupted wrap) and that shouldQuit is not
// called.
func TestLoop_SubErrorStopsLoop(t *testing.T) {
+ ctx := t.Context()
sub := compose.NewWorkflow[int, int]()
lambda := compose.InvokableLambda(func(_ context.Context, _ int) (int, error) {
return 0, errors.New("sub-fail")
@@ -285,17 +292,17 @@ func TestLoop_SubErrorStopsLoop(t *testing.T) {
return false, nil
}
outer := compose.NewWorkflow[int, int]()
- loopNode, err := AddLoopNode(context.Background(), outer, "loop", sub, shouldQuit)
+ loopNode, err := AddLoopNode(ctx, outer, "loop", sub, shouldQuit)
if err != nil {
t.Fatalf("AddLoopNode: %v", err)
}
loopNode.AddInput(compose.START)
outer.End().AddInput("loop")
- compiled, err := outer.Compile(context.Background())
+ compiled, err := outer.Compile(ctx)
if err != nil {
t.Fatalf("compile: %v", err)
}
- _, err = compiled.Invoke(context.Background(), 0)
+ _, err = compiled.Invoke(ctx, 0)
if err == nil {
t.Fatal("expected error, got nil")
}
@@ -312,6 +319,7 @@ func TestLoop_SubErrorStopsLoop(t *testing.T) {
// counterLambda() which bumps the global loopCounter. Three
// iterations → counter == 3.
func TestLoop_CounterIncrementedPerIteration(t *testing.T) {
+ ctx := t.Context()
loopCounter.Store(0)
sub := compose.NewWorkflow[int, int]()
@@ -323,7 +331,7 @@ func TestLoop_CounterIncrementedPerIteration(t *testing.T) {
return next >= 3, nil
}
outer := compose.NewWorkflow[int, int]()
- loopNode, err := AddLoopNode(context.Background(), outer, "loop", sub, shouldQuit,
+ loopNode, err := AddLoopNode(ctx, outer, "loop", sub, shouldQuit,
WithLoopMaxIterations(10),
)
if err != nil {
@@ -331,11 +339,11 @@ func TestLoop_CounterIncrementedPerIteration(t *testing.T) {
}
loopNode.AddInput(compose.START)
outer.End().AddInput("loop")
- compiled, err := outer.Compile(context.Background())
+ compiled, err := outer.Compile(ctx)
if err != nil {
t.Fatalf("compile: %v", err)
}
- if _, err := compiled.Invoke(context.Background(), 0); err != nil {
+ if _, err := compiled.Invoke(ctx, 0); err != nil {
t.Fatalf("invoke: %v", err)
}
if got := loopCounter.Load(); got != 3 {
diff --git a/internal/agent/workflowx/parallel_integration_test.go b/internal/agent/workflowx/parallel_integration_test.go
index 5b07b5d452..e9f4e0cd38 100644
--- a/internal/agent/workflowx/parallel_integration_test.go
+++ b/internal/agent/workflowx/parallel_integration_test.go
@@ -60,11 +60,12 @@ func interruptingParallelSub(t *testing.T) *compose.Workflow[int, int] {
// CompositeInterrupt whose InterruptContexts cover every
// per-item interrupt.
func TestIntegration_AllItemsInterrupt_CompositeInterrupt(t *testing.T) {
+ ctx := t.Context()
store := newInMemoryStore()
sub := interruptingParallelSub(t)
outer := compose.NewWorkflow[[]int, []int]()
- pNode, err := AddParallelNode(context.Background(), outer, "par", sub,
+ pNode, err := AddParallelNode(ctx, outer, "par", sub,
WithParallelMaxConcurrency(0),
WithParallelCheckpointIDBuilder(func(_ string, idx int) string {
return "all-int-cp:" + itoa(idx)
@@ -75,7 +76,7 @@ func TestIntegration_AllItemsInterrupt_CompositeInterrupt(t *testing.T) {
}
pNode.AddInput(compose.START)
outer.End().AddInput("par")
- compiled, err := outer.Compile(context.Background(),
+ compiled, err := outer.Compile(ctx,
compose.WithCheckPointStore(store),
)
if err != nil {
@@ -83,7 +84,7 @@ func TestIntegration_AllItemsInterrupt_CompositeInterrupt(t *testing.T) {
}
cpID := "all-int"
- _, err = compiled.Invoke(context.Background(), []int{10, 20, 30},
+ _, err = compiled.Invoke(ctx, []int{10, 20, 30},
compose.WithCheckPointID(cpID),
)
if err == nil {
@@ -102,7 +103,7 @@ func TestIntegration_AllItemsInterrupt_CompositeInterrupt(t *testing.T) {
// The CompositeInterrupt propagates the parallel state
// through eino's state channel; verify it landed in the
// checkpoint store.
- if _, found, _ := store.Get(context.Background(), cpID); !found {
+ if _, found, _ := store.Get(ctx, cpID); !found {
t.Errorf("outer checkpoint %q not written", cpID)
}
}
@@ -121,6 +122,7 @@ func TestIntegration_AllItemsInterrupt_CompositeInterrupt(t *testing.T) {
// lambda's control. The unit tests in parallel_test.go cover the
// resume logic directly.
func TestIntegration_InvokeResume_ReplaysOnlyNonCompletedIndices(t *testing.T) {
+ ctx := t.Context()
var calls atomic.Int32
interrupted := false
sub := testCountingRunnable{
@@ -145,7 +147,7 @@ func TestIntegration_InvokeResume_ReplaysOnlyNonCompletedIndices(t *testing.T) {
// on the first call); item 3 also runs and returns 9+1=10.
// My code processes all items in order even if some
// interrupt, so calls = 4 after the first run.
- _, err := runParallelInvoke(context.Background(), "par", sub, []int{1, 3, 7, 9}, opts, bridge)
+ _, err := runParallelInvoke(ctx, "par", sub, []int{1, 3, 7, 9}, opts, bridge)
if err == nil {
t.Fatal("expected interrupt error, got nil")
}
@@ -164,7 +166,7 @@ func TestIntegration_InvokeResume_ReplaysOnlyNonCompletedIndices(t *testing.T) {
TotalCount: 4,
}
payload, _ := encodeParallelState(state)
- resumeCtx := injectResumeState(context.Background(), payload)
+ resumeCtx := injectResumeState(ctx, payload)
resumeBridge := newParallelBridgeState(nil)
// The "interrupted" bool is shared across the test, so
// the resume's lambda call for in=7 returns 7+1=8. Item 3 is
@@ -194,6 +196,7 @@ func TestIntegration_InvokeResume_ReplaysOnlyNonCompletedIndices(t *testing.T) {
// per-item checkpoint ID is the same across the first run
// and the resume.
func TestIntegration_StableCheckpointID_AcrossResumes(t *testing.T) {
+ ctx := t.Context()
store := newInMemoryStore()
var observedIDs sync.Map // string -> bool
@@ -212,7 +215,7 @@ func TestIntegration_StableCheckpointID_AcrossResumes(t *testing.T) {
wf.End().AddInput("op")
outer := compose.NewWorkflow[[]int, []int]()
- pNode, err := AddParallelNode(context.Background(), outer, "par", wf,
+ pNode, err := AddParallelNode(ctx, outer, "par", wf,
WithParallelMaxConcurrency(0),
WithParallelCheckpointIDBuilder(func(_ string, idx int) string {
id := "stable-par-cp:" + itoa(idx)
@@ -225,7 +228,7 @@ func TestIntegration_StableCheckpointID_AcrossResumes(t *testing.T) {
}
pNode.AddInput(compose.START)
outer.End().AddInput("par")
- compiled, err := outer.Compile(context.Background(),
+ compiled, err := outer.Compile(ctx,
compose.WithCheckPointStore(store),
)
if err != nil {
@@ -233,13 +236,13 @@ func TestIntegration_StableCheckpointID_AcrossResumes(t *testing.T) {
}
cpID := "stable-cp-test"
- _, err = compiled.Invoke(context.Background(), []int{0, 1, 2},
+ _, err = compiled.Invoke(ctx, []int{0, 1, 2},
compose.WithCheckPointID(cpID),
)
if err == nil {
t.Fatal("expected interrupt, got nil")
}
- resumeCtx := compose.Resume(context.Background(), firstRootInterruptID(t, err))
+ resumeCtx := compose.Resume(ctx, firstRootInterruptID(t, err))
_, err = compiled.Invoke(resumeCtx, []int{0, 1, 2},
compose.WithCheckPointID(cpID),
)
@@ -259,10 +262,11 @@ func TestIntegration_StableCheckpointID_AcrossResumes(t *testing.T) {
// WithParallelEnableSubCheckpoint(false) still propagates
// interrupts (just without the per-item WithCheckPointID).
func TestIntegration_EnableSubCheckpoint_False(t *testing.T) {
+ ctx := t.Context()
sub := interruptingParallelSub(t)
outer := compose.NewWorkflow[[]int, []int]()
- pNode, err := AddParallelNode(context.Background(), outer, "par", sub,
+ pNode, err := AddParallelNode(ctx, outer, "par", sub,
WithParallelMaxConcurrency(0),
WithParallelEnableSubCheckpoint(false),
)
@@ -271,11 +275,11 @@ func TestIntegration_EnableSubCheckpoint_False(t *testing.T) {
}
pNode.AddInput(compose.START)
outer.End().AddInput("par")
- compiled, err := outer.Compile(context.Background())
+ compiled, err := outer.Compile(ctx)
if err != nil {
t.Fatalf("compile: %v", err)
}
- _, err = compiled.Invoke(context.Background(), []int{1, 2})
+ _, err = compiled.Invoke(ctx, []int{1, 2})
if err == nil {
t.Fatal("expected interrupt, got nil")
}
@@ -293,8 +297,9 @@ func TestIntegration_EnableSubCheckpoint_False(t *testing.T) {
// workflow. The Stream() call must return the documented
// ErrParallelOuterStreamUnsupported.
func TestIntegration_Stream_OuterUnsupported(t *testing.T) {
+ ctx := t.Context()
outer := compose.NewWorkflow[[]int, []int]()
- pNode, err := AddParallelNode(context.Background(), outer, "par",
+ pNode, err := AddParallelNode(ctx, outer, "par",
buildParallelIncSub(t),
)
if err != nil {
@@ -302,11 +307,11 @@ func TestIntegration_Stream_OuterUnsupported(t *testing.T) {
}
pNode.AddInput(compose.START)
outer.End().AddInput("par")
- compiled, err := outer.Compile(context.Background())
+ compiled, err := outer.Compile(ctx)
if err != nil {
t.Fatalf("compile: %v", err)
}
- _, err = compiled.Stream(context.Background(), []int{1, 2, 3})
+ _, err = compiled.Stream(ctx, []int{1, 2, 3})
if err == nil {
t.Fatal("expected stream-unsupported error, got nil")
}
@@ -324,6 +329,7 @@ func TestIntegration_Stream_OuterUnsupported(t *testing.T) {
// the same semantics as eino's WithForceNewRun. We exercise
// the contract at the runParallelInvoke level.
func TestIntegration_WithForceNewRun_ResetsState(t *testing.T) {
+ ctx := t.Context()
var interruptCount atomic.Int32
makeRunner := func() testCountingRunnable {
return testCountingRunnable{
@@ -342,7 +348,7 @@ func TestIntegration_WithForceNewRun_ResetsState(t *testing.T) {
})
// First run: interrupted at item 0.
bridge := newParallelBridgeState(nil)
- if _, err := runParallelInvoke(context.Background(), "par", makeRunner(), []int{0, 1, 2}, opts, bridge); err == nil {
+ if _, err := runParallelInvoke(ctx, "par", makeRunner(), []int{0, 1, 2}, opts, bridge); err == nil {
t.Fatal("expected first interrupt, got nil")
}
if got := interruptCount.Load(); got != 1 {
@@ -352,7 +358,7 @@ func TestIntegration_WithForceNewRun_ResetsState(t *testing.T) {
// state) makes the next runParallelInvoke behave as a
// fresh run. Item 0 interrupts again.
bridge2 := newParallelBridgeState(nil)
- if _, err := runParallelInvoke(context.Background(), "par", makeRunner(), []int{0, 1, 2}, opts, bridge2); err == nil {
+ if _, err := runParallelInvoke(ctx, "par", makeRunner(), []int{0, 1, 2}, opts, bridge2); err == nil {
t.Fatal("expected second interrupt, got nil")
}
if got := interruptCount.Load(); got != 2 {
diff --git a/internal/agent/workflowx/parallel_options_test.go b/internal/agent/workflowx/parallel_options_test.go
index 92b880b90f..b0c3d59f68 100644
--- a/internal/agent/workflowx/parallel_options_test.go
+++ b/internal/agent/workflowx/parallel_options_test.go
@@ -132,6 +132,7 @@ func TestOptions_EnableSubCheckpoint_False(t *testing.T) {
// options are passed to every per-item sub-workflow Invoke. We
// assert that the run option count matches the call count.
func TestOptions_ParallelRunOptionsForwarded(t *testing.T) {
+ ctx := t.Context()
var calls atomic.Int32
sub := compose.NewWorkflow[int, int]()
lambda := compose.InvokableLambda(func(_ context.Context, in int) (int, error) {
@@ -143,7 +144,7 @@ func TestOptions_ParallelRunOptionsForwarded(t *testing.T) {
sub.End().AddInput("op")
outer := compose.NewWorkflow[[]int, []int]()
- pNode, err := AddParallelNode(context.Background(), outer, "par", sub,
+ pNode, err := AddParallelNode(ctx, outer, "par", sub,
WithParallelMaxConcurrency(0),
WithParallelRunOptions(compose.WithCheckPointID("ignored-by-inner")),
)
@@ -152,11 +153,11 @@ func TestOptions_ParallelRunOptionsForwarded(t *testing.T) {
}
pNode.AddInput(compose.START)
outer.End().AddInput("par")
- compiled, err := outer.Compile(context.Background())
+ compiled, err := outer.Compile(ctx)
if err != nil {
t.Fatalf("compile: %v", err)
}
- _, err = compiled.Invoke(context.Background(), []int{1, 2, 3, 4})
+ _, err = compiled.Invoke(ctx, []int{1, 2, 3, 4})
if err != nil {
t.Fatalf("invoke: %v", err)
}
@@ -168,8 +169,9 @@ func TestOptions_ParallelRunOptionsForwarded(t *testing.T) {
// TestOptions_ParallelCompileOptionsForwarded asserts the compile
// options are passed to the inner sub-workflow's Compile call.
func TestOptions_ParallelCompileOptionsForwarded(t *testing.T) {
+ ctx := t.Context()
store := newInMemoryStore()
- _ = store.Set(context.Background(), "k", []byte("v"))
+ _ = store.Set(ctx, "k", []byte("v"))
sub := compose.NewWorkflow[int, int]()
lambda := compose.InvokableLambda(func(ctx context.Context, in int) (int, error) {
@@ -184,7 +186,7 @@ func TestOptions_ParallelCompileOptionsForwarded(t *testing.T) {
sub.End().AddInput("op")
outer := compose.NewWorkflow[[]int, []int]()
- pNode, err := AddParallelNode(context.Background(), outer, "par", sub,
+ pNode, err := AddParallelNode(ctx, outer, "par", sub,
WithParallelMaxConcurrency(0),
WithParallelCompileOptions(compose.WithCheckPointStore(store)),
)
@@ -193,11 +195,11 @@ func TestOptions_ParallelCompileOptionsForwarded(t *testing.T) {
}
pNode.AddInput(compose.START)
outer.End().AddInput("par")
- compiled, err := outer.Compile(context.Background())
+ compiled, err := outer.Compile(ctx)
if err != nil {
t.Fatalf("compile: %v", err)
}
- got, err := compiled.Invoke(context.Background(), []int{1, 2, 3})
+ got, err := compiled.Invoke(ctx, []int{1, 2, 3})
if err != nil {
t.Fatalf("invoke: %v", err)
}
@@ -214,18 +216,19 @@ func TestOptions_ParallelCompileOptionsForwarded(t *testing.T) {
func TestOptions_ParallelNilChecks(t *testing.T) {
sub := buildParallelIncSub(t)
outer := compose.NewWorkflow[[]int, []int]()
+ ctx := t.Context()
cases := []struct {
name string
fn func() error
}{
{"nil outer", func() error {
- _, err := AddParallelNode[int, int](context.Background(), nil, "par", sub)
+ _, err := AddParallelNode[int, int](ctx, nil, "par", sub)
return err
}},
{"nil sub", func() error {
var nilSub Compilable[int, int]
- _, err := AddParallelNode(context.Background(), outer, "par", nilSub)
+ _, err := AddParallelNode(ctx, outer, "par", nilSub)
return err
}},
}
@@ -245,9 +248,10 @@ func TestOptions_ParallelNilChecks(t *testing.T) {
// workflow is not modified to a state that would mask the
// failure.
func TestOptions_ParallelCompileFailureIsolated(t *testing.T) {
+ ctx := t.Context()
sub := compose.NewWorkflow[int, int]() // no nodes; compile fails
outer := compose.NewWorkflow[[]int, []int]()
- _, err := AddParallelNode(context.Background(), outer, "par", sub)
+ _, err := AddParallelNode(ctx, outer, "par", sub)
if err == nil {
t.Fatal("expected compile error, got nil")
}
@@ -255,7 +259,7 @@ func TestOptions_ParallelCompileFailureIsolated(t *testing.T) {
t.Errorf("errors.Is(err, ErrParallelCompileFailed) = false; err = %v", err)
}
// The outer workflow should still be empty.
- _, err = outer.Compile(context.Background())
+ _, err = outer.Compile(ctx)
if err == nil || !strings.Contains(err.Error(), "start node not set") {
t.Errorf("outer workflow not in expected state: %v", err)
}
@@ -292,6 +296,7 @@ func TestOptions_ParallelSentinelErrorsExist(t *testing.T) {
// tested via the runParallelFanout integration by ensuring the
// sub-workflow still gets called.
func TestOptions_EmptyBuilderReturnRejectsEmptyID(t *testing.T) {
+ ctx := t.Context()
var calls atomic.Int32
sub := compose.NewWorkflow[int, int]()
lambda := compose.InvokableLambda(func(_ context.Context, in int) (int, error) {
@@ -302,7 +307,7 @@ func TestOptions_EmptyBuilderReturnRejectsEmptyID(t *testing.T) {
node.AddInput(compose.START)
sub.End().AddInput("op")
- compiled, err := sub.Compile(context.Background())
+ compiled, err := sub.Compile(ctx)
if err != nil {
t.Fatalf("compile sub: %v", err)
}
@@ -313,7 +318,7 @@ func TestOptions_EmptyBuilderReturnRejectsEmptyID(t *testing.T) {
}),
})
bridge := newParallelBridgeState(nil)
- got, err := runParallelInvoke(context.Background(), "par", compiled, []int{0, 1, 2}, opts, bridge)
+ got, err := runParallelInvoke(ctx, "par", compiled, []int{0, 1, 2}, opts, bridge)
if err != nil {
t.Fatalf("invoke: %v", err)
}
@@ -332,6 +337,7 @@ func TestOptions_EmptyBuilderReturnRejectsEmptyID(t *testing.T) {
// safe because the sub-workflow has no checkpoint store in this
// test.
func TestOptions_EnableSubCheckpointFalse_NoPerItemID(t *testing.T) {
+ ctx := t.Context()
var calls atomic.Int32
sub := compose.NewWorkflow[int, int]()
lambda := compose.InvokableLambda(func(_ context.Context, in int) (int, error) {
@@ -342,7 +348,7 @@ func TestOptions_EnableSubCheckpointFalse_NoPerItemID(t *testing.T) {
node.AddInput(compose.START)
sub.End().AddInput("op")
- compiled, err := sub.Compile(context.Background())
+ compiled, err := sub.Compile(ctx)
if err != nil {
t.Fatalf("compile sub: %v", err)
}
@@ -351,7 +357,7 @@ func TestOptions_EnableSubCheckpointFalse_NoPerItemID(t *testing.T) {
WithParallelEnableSubCheckpoint(false),
})
bridge := newParallelBridgeState(nil)
- _, err = runParallelInvoke(context.Background(), "par", compiled, []int{0, 1, 2}, opts, bridge)
+ _, err = runParallelInvoke(ctx, "par", compiled, []int{0, 1, 2}, opts, bridge)
if err != nil {
t.Fatalf("invoke: %v", err)
}
diff --git a/internal/agent/workflowx/parallel_test.go b/internal/agent/workflowx/parallel_test.go
index f27eeca7c0..c796c316b7 100644
--- a/internal/agent/workflowx/parallel_test.go
+++ b/internal/agent/workflowx/parallel_test.go
@@ -54,18 +54,19 @@ func buildParallelIncSub(t *testing.T) *compose.Workflow[int, int] {
// output slice preserves input order under the default sequential
// path.
func TestParallel_OrderPreservation_Sequential(t *testing.T) {
+ ctx := t.Context()
outer := compose.NewWorkflow[[]int, []int]()
- node, err := AddParallelNode(context.Background(), outer, "par", buildParallelIncSub(t))
+ node, err := AddParallelNode(ctx, outer, "par", buildParallelIncSub(t))
if err != nil {
t.Fatalf("AddParallelNode: %v", err)
}
node.AddInput(compose.START)
outer.End().AddInput("par")
- compiled, err := outer.Compile(context.Background())
+ compiled, err := outer.Compile(ctx)
if err != nil {
t.Fatalf("compile: %v", err)
}
- got, err := compiled.Invoke(context.Background(), []int{1, 2, 3, 4, 5})
+ got, err := compiled.Invoke(ctx, []int{1, 2, 3, 4, 5})
if err != nil {
t.Fatalf("invoke: %v", err)
}
@@ -86,8 +87,9 @@ func TestParallel_OrderPreservation_Sequential(t *testing.T) {
// the per-item index, so outputs[i] is always the result of
// running on inputs[i].
func TestParallel_OrderPreservation_Concurrent(t *testing.T) {
+ ctx := t.Context()
outer := compose.NewWorkflow[[]int, []int]()
- node, err := AddParallelNode(context.Background(), outer, "par",
+ node, err := AddParallelNode(ctx, outer, "par",
buildParallelIncSub(t),
WithParallelMaxConcurrency(8),
)
@@ -96,12 +98,12 @@ func TestParallel_OrderPreservation_Concurrent(t *testing.T) {
}
node.AddInput(compose.START)
outer.End().AddInput("par")
- compiled, err := outer.Compile(context.Background())
+ compiled, err := outer.Compile(ctx)
if err != nil {
t.Fatalf("compile: %v", err)
}
inputs := []int{10, 20, 30, 40, 50, 60, 70, 80}
- got, err := compiled.Invoke(context.Background(), inputs)
+ got, err := compiled.Invoke(ctx, inputs)
if err != nil {
t.Fatalf("invoke: %v", err)
}
@@ -120,12 +122,13 @@ func TestParallel_OrderPreservation_Concurrent(t *testing.T) {
// Modulo garbage collection, runtime.NumGoroutine() before and
// after must match.
func TestParallel_Sequential_ZeroGoroutineSpawns(t *testing.T) {
+ ctx := t.Context()
// Warm up to make any lazy goroutines settle.
_ = runtime.NumGoroutine()
before := runtime.NumGoroutine()
outer := compose.NewWorkflow[[]int, []int]()
- node, err := AddParallelNode(context.Background(), outer, "par",
+ node, err := AddParallelNode(ctx, outer, "par",
buildParallelIncSub(t),
WithParallelMaxConcurrency(0),
)
@@ -134,14 +137,14 @@ func TestParallel_Sequential_ZeroGoroutineSpawns(t *testing.T) {
}
node.AddInput(compose.START)
outer.End().AddInput("par")
- compiled, err := outer.Compile(context.Background())
+ compiled, err := outer.Compile(ctx)
if err != nil {
t.Fatalf("compile: %v", err)
}
// Do the actual work twice so any one-shot goroutines from
// the eino engine settle.
- _, err = compiled.Invoke(context.Background(), []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
+ _, err = compiled.Invoke(ctx, []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
if err != nil {
t.Fatalf("invoke: %v", err)
}
@@ -157,11 +160,12 @@ func TestParallel_Sequential_ZeroGoroutineSpawns(t *testing.T) {
// MaxConcurrency(1) also runs entirely on the calling goroutine.
// The plan §"Concurrency policy" treats 0 and 1 as the same path.
func TestParallel_Sequential_OneGoroutineSpawns(t *testing.T) {
+ ctx := t.Context()
_ = runtime.NumGoroutine()
before := runtime.NumGoroutine()
outer := compose.NewWorkflow[[]int, []int]()
- node, err := AddParallelNode(context.Background(), outer, "par",
+ node, err := AddParallelNode(ctx, outer, "par",
buildParallelIncSub(t),
WithParallelMaxConcurrency(1),
)
@@ -170,12 +174,12 @@ func TestParallel_Sequential_OneGoroutineSpawns(t *testing.T) {
}
node.AddInput(compose.START)
outer.End().AddInput("par")
- compiled, err := outer.Compile(context.Background())
+ compiled, err := outer.Compile(ctx)
if err != nil {
t.Fatalf("compile: %v", err)
}
- _, err = compiled.Invoke(context.Background(), []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
+ _, err = compiled.Invoke(ctx, []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
if err != nil {
t.Fatalf("invoke: %v", err)
}
@@ -247,6 +251,7 @@ func TestParallel_Concurrent_UsesSemaphoreFanout(t *testing.T) {
// wrapping contract. The lambda must return the wrapped error,
// other items must be drained.
func TestParallel_SingleItemError_Wrapped(t *testing.T) {
+ ctx := t.Context()
underlying := errors.New("boom-2")
var calls atomic.Int32
sub := compose.NewWorkflow[int, int]()
@@ -261,7 +266,7 @@ func TestParallel_SingleItemError_Wrapped(t *testing.T) {
node.AddInput(compose.START)
sub.End().AddInput("op")
- compiled, err := sub.Compile(context.Background())
+ compiled, err := sub.Compile(ctx)
if err != nil {
t.Fatalf("compile sub: %v", err)
}
@@ -271,7 +276,7 @@ func TestParallel_SingleItemError_Wrapped(t *testing.T) {
WithParallelEnableSubCheckpoint(false),
})
bridge := newParallelBridgeState(nil)
- _, err = runParallelInvoke(context.Background(), "par", compiled, []int{1, 2, 3}, opts, bridge)
+ _, err = runParallelInvoke(ctx, "par", compiled, []int{1, 2, 3}, opts, bridge)
if err == nil {
t.Fatal("expected error, got nil")
}
@@ -293,6 +298,7 @@ func TestParallel_SingleItemError_Wrapped(t *testing.T) {
// single CompositeInterrupt carrying every per-item interrupt
// error.
func TestParallel_AllItemsInterrupt_CompositeInterrupt(t *testing.T) {
+ ctx := t.Context()
sub := compose.NewWorkflow[int, int]()
lambda := compose.InvokableLambda(func(ctx context.Context, in int) (int, error) {
was, _, _ := compose.GetInterruptState[int](ctx)
@@ -306,7 +312,7 @@ func TestParallel_AllItemsInterrupt_CompositeInterrupt(t *testing.T) {
sub.End().AddInput("op")
outer := compose.NewWorkflow[[]int, []int]()
- pNode, err := AddParallelNode(context.Background(), outer, "par", sub,
+ pNode, err := AddParallelNode(ctx, outer, "par", sub,
WithParallelMaxConcurrency(0),
WithParallelCheckpointIDBuilder(func(_ string, idx int) string {
return "all-int-cp:" + itoa(idx)
@@ -317,11 +323,11 @@ func TestParallel_AllItemsInterrupt_CompositeInterrupt(t *testing.T) {
}
pNode.AddInput(compose.START)
outer.End().AddInput("par")
- compiled, err := outer.Compile(context.Background())
+ compiled, err := outer.Compile(ctx)
if err != nil {
t.Fatalf("compile: %v", err)
}
- _, err = compiled.Invoke(context.Background(), []int{10, 20, 30})
+ _, err = compiled.Invoke(ctx, []int{10, 20, 30})
if err == nil {
t.Fatal("expected interrupt error, got nil")
}
@@ -340,6 +346,7 @@ func TestParallel_AllItemsInterrupt_CompositeInterrupt(t *testing.T) {
// loader checks first (test-only). This lets us inspect the
// encoded payload without a real eino checkpoint store.
func TestParallel_MixedCompletedAndInterrupted_StateStructure(t *testing.T) {
+ ctx := t.Context()
var completedCalls atomic.Int32
sub := compose.NewWorkflow[int, int]()
lambda := compose.InvokableLambda(func(ctx context.Context, in int) (int, error) {
@@ -354,7 +361,7 @@ func TestParallel_MixedCompletedAndInterrupted_StateStructure(t *testing.T) {
node.AddInput(compose.START)
sub.End().AddInput("op")
- compiled, err := sub.Compile(context.Background())
+ compiled, err := sub.Compile(ctx)
if err != nil {
t.Fatalf("compile sub: %v", err)
}
@@ -366,7 +373,7 @@ func TestParallel_MixedCompletedAndInterrupted_StateStructure(t *testing.T) {
}),
})
bridge := newParallelBridgeState(nil)
- _, err = runParallelInvoke(context.Background(), "par", compiled, []int{0, 1, 2}, opts, bridge)
+ _, err = runParallelInvoke(ctx, "par", compiled, []int{0, 1, 2}, opts, bridge)
if err == nil {
t.Fatal("expected interrupt error, got nil")
}
@@ -385,7 +392,7 @@ func TestParallel_MixedCompletedAndInterrupted_StateStructure(t *testing.T) {
if err != nil {
t.Fatalf("encode: %v", err)
}
- st, isResume, err := loadParallelSnapshot(injectResumeState(context.Background(), payload))
+ st, isResume, err := loadParallelSnapshot(injectResumeState(ctx, payload))
if err != nil {
t.Fatalf("loadSnapshot: %v", err)
}
@@ -434,6 +441,7 @@ func TestParallel_BuildPendingIndices_UsesCompletedComplement(t *testing.T) {
// resume payload with an index in neither CompletedResults nor
// InterruptedIndices is rejected as ErrParallelResumeStateInvalid.
func TestParallel_LoadSnapshot_RejectsPartitionHole(t *testing.T) {
+ ctx := t.Context()
payload, err := encodeParallelState(ParallelInterruptState{
OriginalInputsJSON: []byte(`[1,2,3]`),
CompletedResults: map[int]any{0: 2},
@@ -443,7 +451,7 @@ func TestParallel_LoadSnapshot_RejectsPartitionHole(t *testing.T) {
if err != nil {
t.Fatalf("encode: %v", err)
}
- _, _, err = loadParallelSnapshot(injectResumeState(context.Background(), payload))
+ _, _, err = loadParallelSnapshot(injectResumeState(ctx, payload))
if err == nil {
t.Fatal("expected resume state error, got nil")
}
@@ -458,6 +466,7 @@ func TestParallel_LoadSnapshot_RejectsPartitionHole(t *testing.T) {
// TestParallel_EmptyInput_NoSubInvoke asserts that an empty input
// slice returns []O{}, nil without invoking the inner sub-workflow.
func TestParallel_EmptyInput_NoSubInvoke(t *testing.T) {
+ ctx := t.Context()
var calls atomic.Int32
sub := compose.NewWorkflow[int, int]()
lambda := compose.InvokableLambda(func(_ context.Context, in int) (int, error) {
@@ -469,17 +478,17 @@ func TestParallel_EmptyInput_NoSubInvoke(t *testing.T) {
sub.End().AddInput("op")
outer := compose.NewWorkflow[[]int, []int]()
- pNode, err := AddParallelNode(context.Background(), outer, "par", sub)
+ pNode, err := AddParallelNode(ctx, outer, "par", sub)
if err != nil {
t.Fatalf("AddParallelNode: %v", err)
}
pNode.AddInput(compose.START)
outer.End().AddInput("par")
- compiled, err := outer.Compile(context.Background())
+ compiled, err := outer.Compile(ctx)
if err != nil {
t.Fatalf("compile: %v", err)
}
- got, err := compiled.Invoke(context.Background(), []int{})
+ got, err := compiled.Invoke(ctx, []int{})
if err != nil {
t.Fatalf("invoke: %v", err)
}
@@ -497,8 +506,9 @@ func TestParallel_EmptyInput_NoSubInvoke(t *testing.T) {
// TestParallel_OuterStreamUnsupported asserts that calling Stream
// on the outer parallel node returns the documented v1 error.
func TestParallel_OuterStreamUnsupported(t *testing.T) {
+ ctx := t.Context()
outer := compose.NewWorkflow[[]int, []int]()
- node, err := AddParallelNode(context.Background(), outer, "par",
+ node, err := AddParallelNode(ctx, outer, "par",
buildParallelIncSub(t),
)
if err != nil {
@@ -506,11 +516,11 @@ func TestParallel_OuterStreamUnsupported(t *testing.T) {
}
node.AddInput(compose.START)
outer.End().AddInput("par")
- compiled, err := outer.Compile(context.Background())
+ compiled, err := outer.Compile(ctx)
if err != nil {
t.Fatalf("compile: %v", err)
}
- _, err = compiled.Stream(context.Background(), []int{1, 2, 3})
+ _, err = compiled.Stream(ctx, []int{1, 2, 3})
if err == nil {
t.Fatal("expected stream unsupported error, got nil")
}
@@ -526,6 +536,7 @@ func TestParallel_OuterStreamUnsupported(t *testing.T) {
// panics to errors before they reach this layer; to assert
// our own recover, we use a hand-rolled testRunnable.
func TestParallel_PanicRecoveredAsItemError(t *testing.T) {
+ ctx := t.Context()
runner := testCountingRunnable{
fn: func(_ context.Context, in int, _ ...compose.Option) (int, error) {
if in == 1 {
@@ -539,7 +550,7 @@ func TestParallel_PanicRecoveredAsItemError(t *testing.T) {
WithParallelEnableSubCheckpoint(false),
})
bridge := newParallelBridgeState(nil)
- _, err := runParallelInvoke(context.Background(), "par", runner, []int{0, 1, 2}, opts, bridge)
+ _, err := runParallelInvoke(ctx, "par", runner, []int{0, 1, 2}, opts, bridge)
if err == nil {
t.Fatal("expected panic-as-error, got nil")
}
@@ -558,6 +569,7 @@ func TestParallel_PanicRecoveredAsItemError(t *testing.T) {
// verify the builder is invoked on the first run with the
// expected per-index arguments.
func TestParallel_StableCheckpointIDAcrossResume(t *testing.T) {
+ ctx := t.Context()
type call struct {
key string
index int
@@ -574,7 +586,7 @@ func TestParallel_StableCheckpointIDAcrossResume(t *testing.T) {
sub.End().AddInput("op")
bridge := newParallelBridgeState(nil)
- compiled, err := sub.Compile(context.Background(),
+ compiled, err := sub.Compile(ctx,
compose.WithCheckPointStore(bridge.store()),
)
if err != nil {
@@ -590,7 +602,7 @@ func TestParallel_StableCheckpointIDAcrossResume(t *testing.T) {
return "stable-cp:" + nodeKey + ":" + itoa(idx)
}),
})
- _, err = runParallelInvoke(context.Background(), "par", compiled, []int{0, 1, 2}, opts, bridge)
+ _, err = runParallelInvoke(ctx, "par", compiled, []int{0, 1, 2}, opts, bridge)
if err != nil {
t.Fatalf("invoke: %v", err)
}
diff --git a/internal/deepdoc/client_test.go b/internal/deepdoc/client_test.go
index 441f75038c..464875f980 100644
--- a/internal/deepdoc/client_test.go
+++ b/internal/deepdoc/client_test.go
@@ -17,7 +17,6 @@
package deepdoc
import (
- "context"
"errors"
"net/http"
"net/http/httptest"
@@ -119,44 +118,49 @@ func TestOptions_Override(t *testing.T) {
}
func TestClient_DLAWithoutURL(t *testing.T) {
+ ctx := t.Context()
c := NewClientWithURL("")
- _, err := c.DLA(context.Background(), [][]byte{[]byte("jpg")})
+ _, err := c.DLA(ctx, [][]byte{[]byte("jpg")})
if !errors.Is(err, ErrNoURL) {
t.Errorf("DLA() error=%v, want ErrNoURL", err)
}
}
func TestClient_OCRReturnsNoRemoteEndpoint(t *testing.T) {
+ ctx := t.Context()
c := NewClientWithURL("http://x:1")
- _, err := c.OCR(context.Background(), [][]byte{[]byte("jpg")})
+ _, err := c.OCR(ctx, [][]byte{[]byte("jpg")})
if !errors.Is(err, ErrNoRemoteEndpoint) {
t.Errorf("OCR() error=%v, want ErrNoRemoteEndpoint", err)
}
}
func TestClient_OCRNoRemoteEndpointEvenWithUnsetURL(t *testing.T) {
+ ctx := t.Context()
c := NewClientWithURL("")
- _, err := c.OCR(context.Background(), nil)
+ _, err := c.OCR(ctx, nil)
if !errors.Is(err, ErrNoRemoteEndpoint) {
t.Errorf("OCR() error=%v, want ErrNoRemoteEndpoint (call should not fall through to ErrNoURL)", err)
}
}
func TestClient_TSRReturnsNoRemoteEndpoint(t *testing.T) {
+ ctx := t.Context()
c := NewClientWithURL("http://x:1")
- _, err := c.TSR(context.Background(), [][]byte{[]byte("jpg")})
+ _, err := c.TSR(ctx, [][]byte{[]byte("jpg")})
if !errors.Is(err, ErrNoRemoteEndpoint) {
t.Errorf("TSR() error=%v, want ErrNoRemoteEndpoint", err)
}
}
func TestClient_DLAEmptyInput(t *testing.T) {
+ ctx := t.Context()
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
t.Errorf("DLA() with empty input should not hit the server")
}))
defer srv.Close()
c := NewClientWithURL(srv.URL)
- res, err := c.DLA(context.Background(), nil)
+ res, err := c.DLA(ctx, nil)
if err != nil {
t.Errorf("DLA(nil) error=%v, want nil", err)
}