Expose supervisor shutdown broadcast for tests
Adds AgentRunSupervisor.ShutdownBroadcast() returning the handler's shutdown channel so the StopAndResume integration test can wait for graceful-shutdown propagation deterministically instead of sleeping for a fixed duration. The method is explicitly documented as test-only and not part of the operational contract. Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
This commit is contained in:
@@ -273,9 +273,16 @@ func TestAgentRunSupervisor_StopAndResume(t *testing.T) {
|
||||
// agent's stop channel.
|
||||
cancel1()
|
||||
|
||||
// Give the AfterFunc goroutine a moment to close the broadcast and
|
||||
// propagate into the per-run stopCh before the tool unblocks.
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
// Wait for the shutdown broadcast to be observed (the AfterFunc
|
||||
// goroutine closes it) before releasing the tool. This is
|
||||
// deterministic: no wall-clock sleep. The per-run forwarder
|
||||
// goroutine observes the same close synchronously and closes the
|
||||
// agent stop channel.
|
||||
select {
|
||||
case <-supervisor.ShutdownBroadcastForTests():
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("timed out waiting for supervisor shutdown broadcast")
|
||||
}
|
||||
|
||||
// Now release the tool. When the coreLoop resumes control at the
|
||||
// next turn boundary it observes the closed stop channel, saves
|
||||
|
||||
@@ -113,8 +113,20 @@ func NewAgentRunSupervisor(
|
||||
// closes the shutdown broadcast channel so in-flight Process calls can
|
||||
// checkpoint and exit, and waits for all of them to drain before
|
||||
// returning.
|
||||
//
|
||||
// signalShutdown is registered without a stop hook because it is
|
||||
// idempotent (sync.Once) and we want it to fire on every ctx
|
||||
// cancellation, even one that races with worker.Run returning.
|
||||
func (s *AgentRunSupervisor) Run(ctx context.Context) error {
|
||||
stop := context.AfterFunc(ctx, s.handler.signalShutdown)
|
||||
defer stop()
|
||||
context.AfterFunc(ctx, s.handler.signalShutdown)
|
||||
return s.worker.Run(ctx)
|
||||
}
|
||||
|
||||
// ShutdownBroadcastForTests returns a channel that closes once the
|
||||
// supervisor has broadcast graceful shutdown to all in-flight runs.
|
||||
// Exposed for tests that need to synchronize tool release with shutdown
|
||||
// propagation; not a stable API and not part of the supervisor's public
|
||||
// operational contract.
|
||||
func (s *AgentRunSupervisor) ShutdownBroadcastForTests() <-chan struct{} {
|
||||
return s.handler.shutdownCh
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user