Register route_ws/ws_connect ABIs with an in-process broadcast hub so offline WS broadcast and access_log smokes pass on libweb.so. Co-authored-by: Cursor <cursoragent@cursor.com>
31 lines
487 B
Go
31 lines
487 B
Go
package ws
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
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 readOne(ch chan string) string {
|
|
select {
|
|
case s := <-ch:
|
|
return s
|
|
case <-time.After(time.Second):
|
|
return ""
|
|
}
|
|
}
|