mirror of
https://github.com/jhillyerd/inbucket.git
synced 2026-10-29 13:42:30 +00:00
test(rest): add black-box WebSocket monitor tests (#621)
Cover the REST WebSocket monitor endpoints (v1 + v2), previously at 0% for all 18 functions in socketv1_controller.go and socketv2_controller.go; pkg/rest coverage goes from 20.9% to 73.2%. The harness dials a real gorilla/websocket client into an httptest server wired to a running msghub.Hub, and relies on the hub's history replay for deterministic ordering: dispatching before dialing seeds the replay, and events are relayed in dispatch order, so receiving event N next proves filtered events were skipped rather than delayed. Covered for both API versions: - monitor-all and per-mailbox endpoints, including history replay and live delivery, and mailbox filtering of both message-stored and (v2) message-deleted events - address-form mailbox names via Manager.MailboxForAddress (user%40example.com) - invalid mailbox names rejected with 500 before the upgrade, and plain GET requests failing the handshake with 400 - client data messages discarded by the read pump - clean client shutdown: listener deregistration, empty close frame from the writer racing the read pump's close-code echo, and the WebSocketConnectsCurrent expvar gauge increment/decrement Tests only; no production changes. Notes for follow-up commits: - v1 monitors ignore deletions while v2 reports them (pinned as current behavior in TestMonitorMailboxMessagesV1) - httptest.Server.Close does not wait for hijacked connections, so dialMonitor's cleanup awaits the handler goroutine via the connections gauge before the hub is stopped; the read/write pumps calling msgListener.Close concurrently can still double-close its channel (check-then-act race in Close's select) and deserves a fix - deadline-set error paths, the 54s ping/pong cycle, and write-failure paths remain uncovered, consistent with the POP3 send-error paths
This commit is contained in:
@@ -51,7 +51,7 @@ func testRestPatch(url string, body string) (*httptest.ResponseRecorder, error)
|
||||
return w, nil
|
||||
}
|
||||
|
||||
func setupWebServer(mm message.Manager) *bytes.Buffer {
|
||||
func setupWebServer(mm message.Manager, hub *msghub.Hub) *bytes.Buffer {
|
||||
// Capture log output
|
||||
buf := new(bytes.Buffer)
|
||||
log.SetOutput(buf)
|
||||
@@ -63,7 +63,7 @@ func setupWebServer(mm message.Manager) *bytes.Buffer {
|
||||
},
|
||||
}
|
||||
SetupRoutes(web.Router.PathPrefix("/api/").Subrouter())
|
||||
web.NewServer(cfg, mm, &msghub.Hub{})
|
||||
web.NewServer(cfg, mm, hub)
|
||||
|
||||
return buf
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user