Unattended test: build the subscription the current way
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"testing"
|
||||
@@ -320,7 +321,42 @@ func TestChatStuckUnattendedTurnIsReleased(t *testing.T) {
|
||||
waitFor(t, "stuck observer released", func() bool { active, _ := broker.streams(); return active == 0 })
|
||||
}
|
||||
|
||||
// At most chatUnattendedLimit chats are kept observing with no client.
|
||||
// A turn this server started keeps notifying however many chats are already
|
||||
// observed unattended: the idle cap never drops live work.
|
||||
func TestChatUnattendedRunningTurnsIgnoreTheCap(t *testing.T) {
|
||||
fastUnattended(t)
|
||||
h := newChatHub()
|
||||
defer func() {
|
||||
h.mu.Lock()
|
||||
for _, room := range h.rooms {
|
||||
room.cancel()
|
||||
}
|
||||
h.mu.Unlock()
|
||||
}()
|
||||
count := chatUnattendedLimit + 3
|
||||
kept := 0
|
||||
for i := 0; i < count; i++ {
|
||||
id := fmt.Sprintf("ses_run_%03d", i)
|
||||
h.mu.Lock()
|
||||
room := h.roomLocked(id)
|
||||
room.running = true
|
||||
sub := &chatSub{hub: h, room: room, clientID: "c", limit: 1, done: make(chan struct{})}
|
||||
room.subs["c"] = sub
|
||||
h.mu.Unlock()
|
||||
h.detach(id, sub)
|
||||
h.mu.Lock()
|
||||
if h.rooms[id] == room {
|
||||
kept++
|
||||
}
|
||||
h.mu.Unlock()
|
||||
}
|
||||
if kept != count {
|
||||
t.Fatalf("kept %d unattended running rooms, want all %d", kept, count)
|
||||
}
|
||||
}
|
||||
|
||||
// At most chatUnattendedLimit chats are kept observing with no client on
|
||||
// weaker evidence than live work (a stream-announced turn).
|
||||
func TestChatUnattendedRoomsAreBounded(t *testing.T) {
|
||||
fastUnattended(t)
|
||||
h := newChatHub()
|
||||
@@ -333,10 +369,10 @@ func TestChatUnattendedRoomsAreBounded(t *testing.T) {
|
||||
}()
|
||||
kept := 0
|
||||
for i := 0; i < chatUnattendedLimit+3; i++ {
|
||||
id := "ses_" + string(rune('a'+i))
|
||||
id := fmt.Sprintf("ses_obs_%03d", i)
|
||||
h.mu.Lock()
|
||||
room := h.roomLocked(id)
|
||||
room.running = true
|
||||
room.observedTurn = true
|
||||
sub := &chatSub{hub: h, room: room, clientID: "c", limit: 1, done: make(chan struct{})}
|
||||
room.subs["c"] = sub
|
||||
h.mu.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user