Skip to content

feat: add Broadcasting module tests and scaffolding#137

Open
goravel-coder wants to merge 21 commits into
masterfrom
feat/broadcasting-tests
Open

feat: add Broadcasting module tests and scaffolding#137
goravel-coder wants to merge 21 commits into
masterfrom
feat/broadcasting-tests

Conversation

@goravel-coder

@goravel-coder goravel-coder commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add Broadcasting module integration tests covering dispatch and channel authorization
  • Add mock-based tests for facades.Broadcast().Channel() and facades.Broadcast().Dispatch()
  • Add RelayCloud Docker service to docker-compose.yml for automated end-to-end broadcast testing

Why

This PR adds full test coverage for the new Broadcasting module from goravel/framework#1525. The module enables real-time event delivery through Pusher, Log, and Null drivers. Events implement the ShouldBroadcast contract and are dispatched through the queue system for non-blocking delivery.

// routes/channels.go
facades.Broadcast().Channel("orders.{orderId}", func(user any, channelName string, params map[string]string) bool {
	userID := user.(map[string]any)["id"]
	return userID != nil && params["orderId"] != ""
})
// Dispatch from a controller
facades.Broadcast().Dispatch(&broadcasting.OrderShipped{
	OrderID:    1,
	OrderData:  map[string]any{"id": 1, "name": "Test Order"},
	ShouldFire: true,
})

A RelayCloud container (darknautica/relay:latest) runs as a docker-compose service alongside the existing test infrastructure, providing a Pusher-compatible WebSocket server for real broadcast verification.

- Add config/broadcasting.go with pusher, log, null drivers
- Add app/facades/broadcast.go facade wrapper
- Add routes/channels.go channel auth callbacks
- Add app/broadcasting/events.go implementing all ShouldBroadcast* contracts
- Add tests/feature/broadcast_test.go: 13 integration tests
- Add mock examples: BroadcastChannel, BroadcastDispatch
- Register broadcasting service provider
- Wire routes.Channels() in bootstrap
- Bump framework to 8b12654
@goravel-coder
goravel-coder requested a review from a team as a code owner July 24, 2026 08:40
opencode added 3 commits July 24, 2026 16:57
- Add relay service to docker-compose.yml using darknautica/relay:latest
- Add docker/relay/apps.json with test credentials
- Add SetupSuite/TearDownSuite to manage relay container lifecycle
- Relay tests now run automatically as part of the test suite
Comment thread tests/feature/broadcast_test.go Outdated
opencode added 7 commits July 24, 2026 17:12
Connections are already defined in config/broadcasting.go.
Only switch the default driver per test, matching the redis_test.go pattern.
Split dispatch tests into LogDriver, NullDriver, and PusherDriver.
Each test explicitly switches the default connection and verifies
driver-specific behavior rather than relying on a single default.
Interactive browser page that connects to RelayCloud via WebSocket
and subscribes to channels to verify real-time broadcasting.
Served at /broadcast.html.
RelayCloud uses Bearer token auth for REST API, not Pusher HMAC.
pusher-http-go and the Goravel pusher driver are incompatible.
Keep log and null driver tests which work correctly.
Replace RelayCloud with Soketi (quay.io/soketi/soketi:latest) which implements
full Pusher protocol including REST API with HMAC auth.

Add Go WebSocket client (tests/broadcast_ws_client.go) to subscribe to
channels and receive broadcast events from Soketi.

Add TestPusherDriverEndToEnd which:
1. Connects to Soketi via WebSocket and subscribes to a channel
2. Switches the broadcast driver to pusher via App().Restart()
3. Dispatches an OrderShippedNow event
4. Verifies the event was received on the WebSocket

Remove relay artifacts (docker/relay/).
Replace RelayCloud with Soketi (quay.io/soketi/soketi) which implements
full Pusher protocol with HMAC auth for REST API.

Merge WSClient into tests/feature/broadcast_test.go. Add 4 dedicated
WebSocket client tests:
- TestWSClientConnect: verify socket_id from connection_established
- TestWSClientPublishAndReceive: subscribe + trigger event via Pusher REST API
- TestWSClientPublishToMultipleChannels: verify multi-channel fanout
- TestWSClientPrivateChannelAuthRejected: verify auth endpoint returns error

Add soketiTrigger/soketiTriggerMulti helpers that sign requests using the
Pusher HMAC protocol and POST to Soketi's /apps/{id}/events endpoint.

Manage soketi lifecycle via TestMain (start on boot, stop on teardown).
Remove tests/broadcast_ws_client.go (merged).
Remove docker/relay/ (replaced).
Comment thread tests/feature/main_test.go Outdated
Comment thread tests/feature/broadcast_test.go Outdated
Comment thread app/broadcasting/events.go Outdated
Comment thread tests/feature/broadcast_test.go Outdated
Comment thread tests/feature/broadcast_test.go Outdated
Comment thread tests/feature/broadcast_test.go Outdated
Comment thread tests/feature/broadcast_test.go Outdated
opencode added 10 commits July 25, 2026 22:47
- Move broadcasting events from app/broadcasting to app/events
- Rename types to avoid collision with existing event types
- Test pusher driver as default instead of null/log
- Move soketi lifecycle into broadcast_test.go SetupSuite/TearDownSuite
- Remove framework-internal tests (channel helpers, constants)
- Remove per-test config overrides
- Rename contracts import to contractsbroadcasting
…faces

Cover ShouldBroadcastWithQueue, WithQueueConnection, WithDelay,
WithTries/Backoff/Timeout, and WithConnections via queue
consumption, delay gating, retry timing, timeout cap, and
end-to-end pusher+null+log WebSocket verification.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants