- CHANGELOG.md:v2.8.0 条目(中英双语); - README.md:版本行 2.7.1→2.8.0 + 愿景第 6 条(知识可证明); - doc/releases/v2.8.0.md:双语发版说明(亮点/用法/已知限制); - skills/marqdo-dev/index.mq.md:新增 prove 任务(路径/目录模式/ require_lean/json;参数用 + 行声明升参,check 与 narrative-ratio 通过); - 设计文档 §12.5 标记已合入;发版链接统一指向 doc/releases/v2.8.0.md。
78 lines
1.6 KiB
Go
Executable File
78 lines
1.6 KiB
Go
Executable File
package ws
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestNamedRoomJoinPublishLeave(t *testing.T) {
|
|
room := "chat.room.42"
|
|
ch := JoinRoom(room)
|
|
ch2 := JoinRoom(room)
|
|
PublishRoom(room, "hello-room")
|
|
if got := readOne(ch); got != "hello-room" {
|
|
t.Fatalf("ch1=%q", got)
|
|
}
|
|
if got := readOne(ch2); got != "hello-room" {
|
|
t.Fatalf("ch2=%q", got)
|
|
}
|
|
LeaveRoom(room, ch)
|
|
LeaveRoom(room, ch2)
|
|
}
|
|
|
|
func TestBroadcastFanout(t *testing.T) {
|
|
path := "/t-fanout-go"
|
|
ch := subscribe(path)
|
|
ch2 := subscribe(path)
|
|
Publish(path, "hi")
|
|
if got := readOne(ch); got != "hi" {
|
|
t.Fatalf("ch1=%q", got)
|
|
}
|
|
if got := readOne(ch2); got != "hi" {
|
|
t.Fatalf("ch2=%q", got)
|
|
}
|
|
unsubscribe(path, ch)
|
|
unsubscribe(path, ch2)
|
|
}
|
|
|
|
func TestUnsubscribeRemovesEmptyRoom(t *testing.T) {
|
|
path := "/t-empty-room-gc"
|
|
ch := subscribe(path)
|
|
unsubscribe(path, ch)
|
|
globalHub.mu.Lock()
|
|
_, ok := globalHub.room[path]
|
|
globalHub.mu.Unlock()
|
|
if ok {
|
|
t.Fatalf("empty room %q was not garbage-collected", path)
|
|
}
|
|
}
|
|
|
|
func TestResubscribeDuringCleanupKeepsRoom(t *testing.T) {
|
|
path := "/t-room-rejoin"
|
|
ch := subscribe(path)
|
|
ch2 := subscribe(path)
|
|
unsubscribe(path, ch)
|
|
unsubscribe(path, ch2)
|
|
ch3 := subscribe(path)
|
|
Publish(path, "still-alive")
|
|
if got := readOne(ch3); got != "still-alive" {
|
|
t.Fatalf("re-subscribed chan got %q", got)
|
|
}
|
|
unsubscribe(path, ch3)
|
|
globalHub.mu.Lock()
|
|
_, ok := globalHub.room[path]
|
|
globalHub.mu.Unlock()
|
|
if ok {
|
|
t.Fatalf("empty room %q was not garbage-collected after rejoin", path)
|
|
}
|
|
}
|
|
|
|
func readOne(ch chan string) string {
|
|
select {
|
|
case s := <-ch:
|
|
return s
|
|
case <-time.After(time.Second):
|
|
return ""
|
|
}
|
|
}
|