summaryrefslogtreecommitdiff
path: root/internal/executor/executor_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/executor/executor_test.go')
-rw-r--r--internal/executor/executor_test.go30
1 files changed, 19 insertions, 11 deletions
diff --git a/internal/executor/executor_test.go b/internal/executor/executor_test.go
index 9ad0617..028e5cf 100644
--- a/internal/executor/executor_test.go
+++ b/internal/executor/executor_test.go
@@ -224,27 +224,35 @@ func TestPool_Cancel_UnknownTask_ReturnsFalse(t *testing.T) {
}
}
-func TestPool_AtCapacity(t *testing.T) {
+// TestPool_QueuedWhenAtCapacity verifies that Submit enqueues a task rather than
+// returning an error when the pool is at capacity. Both tasks should eventually complete.
+func TestPool_QueuedWhenAtCapacity(t *testing.T) {
store := testStore(t)
- runner := &mockRunner{delay: time.Second}
+ runner := &mockRunner{delay: 100 * time.Millisecond}
runners := map[string]Runner{"claude": runner}
logger := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelError}))
pool := NewPool(1, runners, store, logger)
- tk1 := makeTask("cap-1")
+ tk1 := makeTask("queue-1")
store.CreateTask(tk1)
- pool.Submit(context.Background(), tk1)
+ if err := pool.Submit(context.Background(), tk1); err != nil {
+ t.Fatalf("first submit: %v", err)
+ }
- // Pool is at capacity, second submit should fail.
- time.Sleep(10 * time.Millisecond) // let goroutine start
- tk2 := makeTask("cap-2")
+ // Second submit must succeed (queued) even though pool slot is taken.
+ tk2 := makeTask("queue-2")
store.CreateTask(tk2)
- err := pool.Submit(context.Background(), tk2)
- if err == nil {
- t.Fatal("expected capacity error")
+ if err := pool.Submit(context.Background(), tk2); err != nil {
+ t.Fatalf("second submit: %v — expected task to be queued, not rejected", err)
}
- <-pool.Results() // drain
+ // Both tasks must complete.
+ for i := 0; i < 2; i++ {
+ r := <-pool.Results()
+ if r.Err != nil {
+ t.Errorf("task %s error: %v", r.TaskID, r.Err)
+ }
+ }
}
// logPatherMockRunner is a mockRunner that also implements LogPather,