Recover background chat observers from durable live membership
This commit is contained in:
@@ -109,10 +109,9 @@ func TestChatActivityReachesEveryConnection(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A background task that never reports its exit does not hold the observer
|
||||
// forever: it is released after chatUnattendedTurnLimit, and the list then
|
||||
// reports no tasks rather than a stale count.
|
||||
func TestChatUnreportedBackgroundTaskIsReleased(t *testing.T) {
|
||||
// A running task is not an idle observer: the old observer TTL must not
|
||||
// invent completion. A terminal event releases it and clears list activity.
|
||||
func TestChatBackgroundTaskWaitsForExitBeyondObserverTTL(t *testing.T) {
|
||||
fastUnattended(t)
|
||||
t.Setenv("PIPELINES_NTFY_URL", "")
|
||||
limit := chatUnattendedTurnLimit
|
||||
@@ -134,17 +133,21 @@ func TestChatUnreportedBackgroundTaskIsReleased(t *testing.T) {
|
||||
broker.push(stepFrameFor(protocol.ChatStepEnded, "turn_1"))
|
||||
readActivity(t, server.ctx, list)
|
||||
viewer.CloseNow()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
time.Sleep(2 * chatUnattendedTurnLimit)
|
||||
if active, _ := broker.streams(); active != 1 {
|
||||
t.Fatalf("background task not observed: %d", active)
|
||||
t.Fatalf("background observer expired: %d", active)
|
||||
}
|
||||
if got := listActivity(t, server.ctx, list); got == nil || got.BackgroundTasks != 1 {
|
||||
t.Fatalf("invented task completion: %+v", got)
|
||||
}
|
||||
broker.push(shellFrame("sh_1", protocol.ChatShellExited))
|
||||
released := readActivity(t, server.ctx, list)
|
||||
if released.TurnRunning || released.BackgroundTasks != 0 {
|
||||
t.Fatalf("release push = %+v", released)
|
||||
}
|
||||
waitFor(t, "observer released", func() bool { active, _ := broker.streams(); return active == 0 })
|
||||
if got := listActivity(t, server.ctx, list); got == nil || got.BackgroundTasks != 0 {
|
||||
t.Fatalf("listed activity after expiry = %+v", got)
|
||||
t.Fatalf("listed activity after completion = %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user