MCPcopy Create free account
hub / github.com/astercloud/aster / TestExecuteParallel

Function TestExecuteParallel

pkg/executionplan/executor_test.go:283–325  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

281}
282
283func TestExecuteParallel(t *testing.T) {
284 // Use delays to verify parallel execution
285 tool1 := newDelayedMockTool("tool1", "result1", 50*time.Millisecond)
286 tool2 := newDelayedMockTool("tool2", "result2", 50*time.Millisecond)
287 tool3 := newDelayedMockTool("tool3", "result3", 50*time.Millisecond)
288
289 toolMap := map[string]tools.Tool{
290 "tool1": tool1,
291 "tool2": tool2,
292 "tool3": tool3,
293 }
294
295 executor := NewExecutor(toolMap)
296
297 plan := NewExecutionPlan("Parallel test")
298 plan.AddStep("tool1", "Step 1", nil)
299 plan.AddStep("tool2", "Step 2", nil)
300 plan.AddStep("tool3", "Step 3", nil)
301 plan.Options.RequireApproval = false
302 plan.Options.AllowParallel = true
303 plan.Options.MaxParallelSteps = 3
304
305 ctx := context.Background()
306 toolCtx := &tools.ToolContext{AgentID: "test-agent"}
307
308 start := time.Now()
309 err := executor.Execute(ctx, plan, toolCtx)
310 duration := time.Since(start)
311
312 if err != nil {
313 t.Fatalf("unexpected error: %v", err)
314 }
315
316 // If executed sequentially, it would take ~150ms
317 // If executed in parallel, it should take ~50-70ms
318 if duration > 120*time.Millisecond {
319 t.Errorf("parallel execution took too long: %v (expected < 120ms)", duration)
320 }
321
322 if plan.Status != StatusCompleted {
323 t.Errorf("expected status %v, got %v", StatusCompleted, plan.Status)
324 }
325}
326
327func TestExecuteWithDependencies(t *testing.T) {
328 tool1 := newMockTool("tool1", "result1", nil)

Callers

nothing calls this directly

Calls 5

AddStepMethod · 0.95
ExecuteMethod · 0.95
newDelayedMockToolFunction · 0.85
NewExecutionPlanFunction · 0.85
NewExecutorFunction · 0.70

Tested by

no test coverage detected