-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
31 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
"""An EventBus for use in the Jupyter server. | ||
.. versionadded:: 2.0 | ||
""" | ||
# Copyright (c) Jupyter Development Team. | ||
# Distributed under the terms of the Modified BSD License. | ||
from jupyter_telemetry.eventlog import EventLog | ||
from traitlets.config import SingletonConfigurable | ||
|
||
|
||
class EventBus(EventLog, SingletonConfigurable): | ||
"""A Jupyter EventLog as a Singleton, making it easy to | ||
access from anywhere and log events. | ||
"""A singleton eventlog that behaves as an event | ||
bus for emitting Jupyter Server (and extension) | ||
event data. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
from .mock_extension import _load_jupyter_server_extension | ||
|
||
# Function that makes these extensions discoverable | ||
# by the test functions. | ||
|
||
|
||
def _jupyter_server_extension_points(): | ||
return [ | ||
{"module": "tests.events.mock_extension"}, | ||
{"module": "tests.services.events.mockextension"}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,32 @@ | ||
import json | ||
import pathlib | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def event_bus(jp_serverapp): | ||
event_bus = jp_serverapp.event_bus | ||
event_bus.allowed_schemas = ["event.mockextension.jupyter.com/message"] | ||
return event_bus | ||
def jp_server_config(): | ||
config = { | ||
"ServerApp": { | ||
"jpserver_extensions": {"tests.services.events.mockextension": True}, | ||
}, | ||
"EventBus": {"allowed_schemas": ["event.mockextension.jupyter.com/message"]}, | ||
} | ||
return config | ||
|
||
|
||
async def test_subscribe_websocket(jp_ws_fetch, jp_fetch, event_bus): | ||
# Open a websocket connection. | ||
async def test_subscribe_websocket(jp_ws_fetch, jp_fetch): | ||
# Open an event listener websocket | ||
ws = await jp_ws_fetch("/api/events/subscribe") | ||
|
||
# Hit the extension endpoint that emits an event | ||
await jp_fetch("/mock/event") | ||
|
||
# Check the event listener for a message | ||
message = await ws.read_message() | ||
event_data = json.loads(message) | ||
|
||
# Close websocket | ||
ws.close() | ||
|
||
# Verify that an event message was received. | ||
assert event_data.get("event_message") == "Hello world, from mock extension!" |