[grid] Add session event API for server-side event bus integration#17015
Conversation
PR TypeEnhancement Description
|
| Relevant files | |||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Enhancement | 16 files
|
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||||||||
9fe699c to
a6a0863
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces a cross-language, event-driven session lifecycle mechanism for Selenium Grid nodes, plus client-side APIs to fire custom session events, and adjusts Grid event bus defaults and node behavior to support sidecar services.
Changes:
- Add
session-created,session-closed, andsession-eventdata/event types plusSessionLifecycleListenerto let Grid nodes publish rich session lifecycle data to both SPI listeners and the EventBus. - Expose a
fireSessionEventclient API in Java, Python, Ruby, and .NET bindings with matching/session/{sessionId}/se/eventwiring across all transports and node implementations. - Refine Grid server internals (LocalNode, SessionSlot, RemoteNode, EventBusOptions, Standalone config) to emit enriched closure events, avoid deadlocks, and choose an appropriate EventBus implementation for standalone vs. distributed setups.
Reviewed changes
Copilot reviewed 35 out of 35 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| rb/spec/unit/selenium/webdriver/remote/features_spec.rb | Adds unit tests covering Ruby Remote::Features#fire_session_event behavior and command registration. |
| rb/lib/selenium/webdriver/remote/features.rb | Extends remote features to register and implement the fire_session_event command mapped to /session/:session_id/se/event. |
| rb/lib/selenium/webdriver/remote/driver.rb | Mixes in HasSessionEvents so Ruby remote drivers expose #fire_session_event. |
| rb/lib/selenium/webdriver/common/driver_extensions/has_session_events.rb | Introduces Ruby driver extension delegating fire_session_event from the driver to the remote bridge. |
| rb/lib/selenium/webdriver/common.rb | Wires the new Ruby driver extension into the common driver bootstrap requires. |
| py/test/unit/selenium/webdriver/remote/fire_session_event_tests.py | Adds Python unit tests ensuring the new command constant, execution wiring, and payload handling for fire_session_event are correct. |
| py/test/selenium/webdriver/remote/remote_session_event_tests.py | Adds Python Grid integration tests validating driver.fire_session_event end-to-end with and without payloads and with complex payloads. |
| py/selenium/webdriver/remote/webdriver.py | Adds WebDriver.fire_session_event with type hints, argument validation at the wire level, and return-value unwrapping from the W3C command response. |
| py/selenium/webdriver/remote/remote_connection.py | Registers the FIRE_SESSION_EVENT command to the /session/$sessionId/se/event HTTP endpoint in the Python remote connection. |
| py/selenium/webdriver/remote/command.py | Introduces the FIRE_SESSION_EVENT command constant for Python remote WebDriver. |
| java/test/org/openqa/selenium/testing/drivers/OutOfProcessSeleniumServer.java | Increases Selenium server startup wait timeout from 10s to 20s to make Grid-based tests more robust. |
| java/test/org/openqa/selenium/remote/RemoteWebDriverUnitTest.java | Adds Java unit tests for RemoteWebDriver.fireSessionEvent (with/without payload and null eventType validation). |
| java/test/org/openqa/selenium/grid/node/NodeTest.java | Adds Grid node tests covering the /session/{id}/se/event endpoint, event bus delivery, error cases, and empty-payload semantics. |
| java/src/org/openqa/selenium/remote/codec/AbstractHttpCommandCodec.java | Defines the HTTP wire mapping for FIRE_SESSION_EVENT to POST /session/:sessionId/se/event in the Java HTTP command codec. |
| java/src/org/openqa/selenium/remote/RemoteWebDriver.java | Adds overloaded fireSessionEvent methods that build the command payload via DriverCommand.FIRE_SESSION_EVENT and return the server’s response map. |
| java/src/org/openqa/selenium/remote/DriverCommand.java | Adds the FIRE_SESSION_EVENT command name and a helper to construct its payload with optional payload field. |
| java/src/org/openqa/selenium/grid/server/EventBusOptions.java | Switches EventBus defaulting logic to prefer GuavaEventBus for standalone (no endpoints) and ZeroMqEventBus when publish/subscribe endpoints are configured. |
| java/src/org/openqa/selenium/grid/node/remote/RemoteNode.java | Forwards fireSessionEvent requests directly to the underlying HTTP client for remote nodes. |
| java/src/org/openqa/selenium/grid/node/local/SessionSlot.java | Extends stop to accept node context and timing and fires SessionClosedEvent with rich SessionClosedData. |
| java/src/org/openqa/selenium/grid/node/local/LocalNode.java | Emits SessionCreatedEvent/SessionEvent, loads SessionLifecycleListeners via ServiceLoader, forwards lifecycle events to them, and routes /se/event requests while including node context. |
| java/src/org/openqa/selenium/grid/node/SessionLifecycleListener.java | Introduces an SPI for sidecar services to receive session created/closed and custom session events with full context. |
| java/src/org/openqa/selenium/grid/node/Node.java | Registers the /session/{sessionId}/se/event route and adds a default fireSessionEvent hook for subclasses to override. |
| java/src/org/openqa/selenium/grid/node/FireSessionEvent.java | Implements the HTTP handler that delegates /se/event requests from the router to the node’s fireSessionEvent method. |
| java/src/org/openqa/selenium/grid/data/SessionEventData.java | Defines the payload-carrying data structure for user-defined session events, including node context, timestamp, validation, and JSON (de)serialization. |
| java/src/org/openqa/selenium/grid/data/SessionEvent.java | Adds the corresponding EventBus event type and convenience listener factories for SessionEventData. |
| java/src/org/openqa/selenium/grid/data/SessionCreatedEvent.java | Adds an event wrapper for SessionCreatedData plus listeners that receive full context or just the SessionId. |
| java/src/org/openqa/selenium/grid/data/SessionCreatedData.java | Introduces a rich session-created data object (session, node, URIs, capabilities, stereotype, timing) with JSON support. |
| java/src/org/openqa/selenium/grid/data/SessionClosedEvent.java | Extends the session-closed event to accept SessionClosedData while keeping the original constructors for backward compatibility. |
| java/src/org/openqa/selenium/grid/data/SessionClosedData.java | Expands closed-session data to include node info, capabilities, timing, and duration plus a new JSON schema, while keeping a backwards-compatible constructor. |
| java/src/org/openqa/selenium/grid/commands/Standalone.java | Marks the EVENT_BUS_ROLE as configurable for the standalone Grid command, ensuring event bus options can be customized. |
| java/src/org/openqa/selenium/grid/commands/DefaultStandaloneConfig.java | Removes the hardcoded EventBus implementation from standalone defaults so EventBusOptions can select it dynamically. |
| dotnet/test/common/SessionEventTest.cs | Adds .NET tests for firing session events with and without payload, argument validation, and ensuring the command constant is known. |
| dotnet/src/webdriver/Remote/W3CWireProtocolCommandInfoRepository.cs | Wires the .NET FireSessionEvent command to POST /session/{sessionId}/se/event in the W3C command repository. |
| dotnet/src/webdriver/Remote/RemoteWebDriver.cs | Adds FireSessionEvent methods for .NET RemoteWebDriver, including validation and response shape checks mirroring other custom commands. |
| dotnet/src/webdriver/DriverCommand.cs | Declares the .NET FireSessionEvent command name and adds it to the set of known commands. |
1e4fa65 to
971a6ac
Compare
a0a3c51 to
ad61b71
Compare
ad61b71 to
756d96e
Compare
756d96e to
48a8c52
Compare
|
/review |
PR Reviewer Guide 🔍(Review updated until commit 2fd125c)Here are some key observations to aid the review process:
|
48a8c52 to
c28c6a7
Compare
3abaccd to
e8de126
Compare
e8de126 to
1e6638d
Compare
1e6638d to
08f039a
Compare
Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
45d4edb to
de97913
Compare
|
/review |
|
Persistent review updated to latest commit 2fd125c |
Summary
Adds a client API to fire custom session events to the Grid's event bus, enabling server-side utilities to react to test lifecycle events.
Users can set up Selenium Grid with sidecar utilities that subscribe to the Grid's event bus, allowing these services to listen and react to session lifecycle events (session created, session closed, custom test events).
Features
Client API
Test code can fire events that server-side utilities subscribe to:
Java:
Python:
JavaScript:
Ruby:
.NET:
Server-Side Integration
Subscribe to events via the Guava EventBus:
For distributed deployments, subscribe to events via ZeroMQ.
Wire Protocol
Node Support
Additional Changes
SessionCreatedEvent,SessionClosedEvent) with rich contextBackward Compatibility
All changes are additive and backward compatible.
Test plan