(t *testing.T)
| 281 | } |
| 282 | |
| 283 | func 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 | |
| 327 | func TestExecuteWithDependencies(t *testing.T) { |
| 328 | tool1 := newMockTool("tool1", "result1", nil) |
nothing calls this directly
no test coverage detected