This commit is contained in:
2026-08-17 02:12:17 +08:00
parent 560ae46b82
commit 6a05803e08
96 changed files with 2888 additions and 685 deletions
+25
View File
@@ -23,3 +23,28 @@ func TestCloseSubscribersClosesEveryAlertStream(t *testing.T) {
// closed and removed every channel.
scheduler.Unsubscribe(1, first)
}
func TestSubscribeCapsConnectionsPerUser(t *testing.T) {
scheduler := &TaskScheduler{subscribers: map[uint]map[chan []byte]struct{}{}}
channels := make([]chan []byte, 0, 11)
for i := 0; i < 11; i++ {
channels = append(channels, scheduler.Subscribe(7))
}
if got := len(scheduler.subscribers[7]); got != 10 {
t.Fatalf("subscriber count = %d, want 10", got)
}
closed := 0
for _, ch := range channels {
select {
case _, open := <-ch:
if !open {
closed++
}
default:
}
}
if closed != 1 {
t.Fatalf("evicted subscriber count = %d, want 1", closed)
}
scheduler.closeSubscribers()
}