Files
sam 1f99fb592e fix(daemon): let a run waiting on a callee release its capacity
A wait:true workflow.call run held its global slot and its repo's place for
the callee's whole life, and the drain pass waited for its own tasks, so a
callee queued by that pass was never claimed. With containers.max_concurrency
saturated, or a repo that does not allow concurrency, the wait could not end.

A drain pass now returns once the stream and the claim fallback are empty, and
shutdown waits for in-flight work once. Suspend/Resume give a run's slot and
repo place back while it waits on a callee, driven by the workflow call events
on the daemon's bus; a hold records one slot and one place, so a second
re-acquire gives back what it took.
2026-10-08 22:31:07 +11:00

40 lines
954 B
Go

package daemon
import (
"context"
"testing"
"time"
"github.com/samcharles93/archie-core/internal/domain/workflow"
)
func TestDispatcherWaitIncludesQueuedWork(t *testing.T) {
dispatcher := newTaskDispatcher(1, nil)
started := make(chan struct{}, 2)
release := make(chan struct{})
process := func() { started <- struct{}{}; <-release }
for range 2 {
dispatcher.Submit(t.Context(), &workflow.Task{Owner: "o", Repo: "r"}, func(_ context.Context, _ *workflow.Task, _ *taskHold) { process() })
}
<-started
dispatcher.mu.Lock()
count := dispatcher.pending
dispatcher.mu.Unlock()
if count != 2 {
t.Fatalf("in-flight count=%d, want running and queued task", count)
}
done := make(chan struct{})
go func() { dispatcher.Wait(); close(done) }()
select {
case <-done:
t.Fatal("drain completed with pending work")
default:
}
close(release)
select {
case <-done:
case <-time.After(time.Second):
t.Fatal("drain did not finish")
}
}