Skip to content

Commit 9cec9e8

Browse files
committed
cleaning up unit tests
1 parent af672cd commit 9cec9e8

File tree

5 files changed

+15
-19
lines changed

5 files changed

+15
-19
lines changed

jupyter_server/serverapp.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@
110110
from jupyter_server.services.kernels.connection.channels import (
111111
ZMQChannelsWebsocketConnection,
112112
)
113-
from jupyter_server.services.kernels.kernel_broker import KernelWebsocketBroker
114113
from jupyter_server.services.kernels.kernelmanager import (
115114
AsyncMappingKernelManager,
116115
MappingKernelManager,

jupyter_server/services/kernels/connection/abc.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,20 @@ class KernelWebsocketConnectionABC(ABC):
1414

1515
@abstractmethod
1616
async def connect(self):
17+
"""Connect the kernel websocket to the kernel ZMQ connections"""
1718
...
1819

1920
@abstractmethod
2021
async def disconnect(self):
22+
"""Disconnect the kernel websocket from the kernel ZMQ connections"""
2123
...
2224

2325
@abstractmethod
2426
def handle_incoming_message(self, incoming_msg: str) -> None:
27+
"""Broker the incoming websocket message to the appropriate ZMQ channel."""
2528
...
2629

2730
@abstractmethod
2831
def handle_outgoing_message(self, stream: str, outgoing_msg: list) -> None:
32+
"""Broker outgoing ZMQ messages to the kernel websocket."""
2933
...

jupyter_server/services/kernels/connection/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44

55
from jupyter_client.session import Session
6-
from traitlets import Float, Instance, default
6+
from traitlets import Callable, Float, Instance, default
77
from traitlets.config import LoggingConfigurable
88

99
try:
@@ -135,6 +135,8 @@ def _default_kernel_info_timeout(self):
135135
def _default_session(self):
136136
return Session(config=self.config)
137137

138+
write_message = Callable()
139+
138140
async def connect(self):
139141
raise NotImplementedError()
140142

jupyter_server/services/kernels/connection/channels.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from tornado import gen, web
1010
from tornado.ioloop import IOLoop
1111
from tornado.websocket import WebSocketClosedError
12-
from traitlets import Bool, Dict, Float, Instance, Int, List, Unicode, default
12+
from traitlets import Any, Bool, Dict, Float, Instance, Int, List, Unicode, default
1313

1414
try:
1515
from jupyter_client.jsonutil import json_default
@@ -89,7 +89,7 @@ class ZMQChannelsWebsocketConnection(BaseKernelWebsocketConnection):
8989
_close_future: Future
9090

9191
channels = Dict({})
92-
kernel_info_channel = Unicode(allow_none=True)
92+
kernel_info_channel = Any(allow_none=True)
9393

9494
_kernel_info_future = Instance(klass=Future)
9595

@@ -132,7 +132,7 @@ def create_stream(self):
132132
identity = self.session.bsession
133133
for channel in ("iopub", "shell", "control", "stdin"):
134134
meth = getattr(self.kernel_manager, "connect_" + channel)
135-
self.channels[channel] = stream = meth(self.kernel_id, identity=identity)
135+
self.channels[channel] = stream = meth(identity=identity)
136136
stream.channel = channel
137137

138138
def nudge(self):
@@ -214,14 +214,6 @@ def on_iopub(msg):
214214
# Nudge the kernel with kernel info requests until we get an IOPub message
215215
def nudge(count):
216216
count += 1
217-
218-
# NOTE: this close check appears to never be True during on_open,
219-
# even when the peer has closed the connection
220-
if self.ws_connection is None or self.ws_connection.is_closing():
221-
self.log.debug("Nudge: cancelling on closed websocket: %s", self.kernel_id)
222-
finish()
223-
return
224-
225217
# check for stopped kernel
226218
if self.kernel_id not in self.multi_kernel_manager:
227219
self.log.debug("Nudge: cancelling on stopped kernel: %s", self.kernel_id)
@@ -274,8 +266,6 @@ async def _register_session(self):
274266
self._open_sessions[self.session_key] = self
275267

276268
async def prepare(self):
277-
# authenticate first
278-
super().pre_get()
279269
# check session collision:
280270
await self._register_session()
281271
# then request kernel info, waiting up to a certain time before giving up.
@@ -525,7 +515,7 @@ def select_subprotocol(self, subprotocols):
525515
def _on_zmq_reply(self, stream, msg_list):
526516
# Sometimes this gets triggered when the on_close method is scheduled in the
527517
# eventloop but hasn't been called.
528-
if self.ws_connection is None or stream.closed():
518+
if stream.closed():
529519
self.log.warning("zmq message arrived on closed channel")
530520
self.close()
531521
return
@@ -554,7 +544,7 @@ def request_kernel_info(self):
554544
# Create a kernel_info channel to query the kernel protocol version.
555545
# This channel will be closed after the kernel_info reply is received.
556546
if self.kernel_info_channel is None:
557-
self.kernel_info_channel = self.kernel_manager.connect_shell(self.kernel_id)
547+
self.kernel_info_channel = self.multi_kernel_manager.connect_shell(self.kernel_id)
558548
assert self.kernel_info_channel is not None
559549
self.kernel_info_channel.on_recv(self._handle_kernel_info_reply)
560550
self.session.send(self.kernel_info_channel, "kernel_info_request")

jupyter_server/services/kernels/websocket.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,18 +187,19 @@ async def pre_get(self):
187187
else:
188188
self.log.warning("No session ID specified")
189189
# For backwards compatibility with older versions
190-
# of the message broker, call a prepare method if found.
190+
# of the websocket connection, call a prepare method if found.
191191
if hasattr(self.connection, "prepare"):
192192
await self.connection.prepare()
193193

194194
async def get(self, kernel_id):
195195
self.kernel_id = kernel_id
196+
await self.pre_get()
196197
await super().get(kernel_id=kernel_id)
197198

198199
async def open(self, kernel_id):
199200
# Wait for the kernel to emit an idle status.
200201
self.log.info(f"Connecting to kernel {self.kernel_id}.")
201-
await self.connection.connect(session_id=self.session_id)
202+
await self.connection.connect()
202203

203204
def on_message(self, ws_message):
204205
"""Get a kernel message from the websocket and turn it into a ZMQ message."""

0 commit comments

Comments
 (0)