Skip to content

Commit 13dd92e

Browse files
authored
Merge pull request #257 from minrk/await-maybe
add ensure_async in status handler
2 parents ca6a4a9 + 511fc00 commit 13dd92e

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

jupyter_server/services/api/handlers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from tornado import web
1010

1111
from ...base.handlers import JupyterHandler, APIHandler
12+
from jupyter_server.utils import ensure_async
1213
from jupyter_server._tz import utcfromtimestamp, isoformat
1314

1415

@@ -36,7 +37,7 @@ async def get(self):
3637
started = self.settings.get('started', utcfromtimestamp(0))
3738
started = isoformat(started)
3839

39-
kernels = await self.kernel_manager.list_kernels()
40+
kernels = await ensure_async(self.kernel_manager.list_kernels())
4041
total_connections = sum(k['connections'] for k in kernels)
4142
last_activity = isoformat(self.application.last_activity())
4243
model = {

tests/services/api/test_api.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1-
import pytest
2-
3-
from jupyter_server.utils import url_path_join
1+
import json
42

53

64
async def test_get_spec(fetch):
7-
response = await fetch(
8-
'api', 'spec.yaml',
9-
method='GET'
10-
)
5+
response = await fetch("api", "spec.yaml", method="GET")
116
assert response.code == 200
127

138

14-
9+
async def test_get_status(fetch):
10+
response = await fetch("api", "status", method="GET")
11+
assert response.code == 200
12+
assert response.headers.get("Content-Type") == "application/json"
13+
status = json.loads(response.body.decode("utf8"))
14+
assert sorted(status.keys()) == [
15+
"connections",
16+
"kernels",
17+
"last_activity",
18+
"started",
19+
]
20+
assert status["connections"] == 0
21+
assert status["kernels"] == 0
22+
assert status["last_activity"].endswith("Z")
23+
assert status["started"].endswith("Z")

0 commit comments

Comments
 (0)