12
12
CULL_TIMEOUT = 30 if platform .python_implementation () == "PyPy" else 5
13
13
CULL_INTERVAL = 1
14
14
15
+ sample_kernel_json_with_metadata = {
16
+ "argv" : ["cat" , "{connection_file}" ],
17
+ "display_name" : "Test kernel" ,
18
+ "metadata" : {"cull_idle_timeout" : 0 },
19
+ }
20
+
15
21
16
22
@pytest .fixture (autouse = True )
17
23
def suppress_deprecation_warnings ():
@@ -24,6 +30,21 @@ def suppress_deprecation_warnings():
24
30
yield
25
31
26
32
33
+ @pytest .fixture
34
+ def jp_kernelspec_with_metadata (jp_data_dir ):
35
+ """Configures some sample kernelspecs in the Jupyter data directory."""
36
+ kenrel_spec_name = "sample_with_metadata"
37
+ sample_kernel_dir = jp_data_dir .joinpath ("kernels" , kenrel_spec_name )
38
+ sample_kernel_dir .mkdir (parents = True )
39
+ # Create kernel json file
40
+ sample_kernel_file = sample_kernel_dir .joinpath ("kernel.json" )
41
+ kernel_json = sample_kernel_json_with_metadata .copy ()
42
+ sample_kernel_file .write_text (json .dumps (kernel_json ))
43
+ # Create resources text
44
+ sample_kernel_resources = sample_kernel_dir .joinpath ("resource.txt" )
45
+ sample_kernel_resources .write_text ("resource" )
46
+
47
+
27
48
@pytest .mark .parametrize (
28
49
"jp_server_config" ,
29
50
[
@@ -73,6 +94,24 @@ async def test_cull_idle(jp_fetch, jp_ws_fetch):
73
94
assert culled
74
95
75
96
97
+ async def test_cull_idle_disable (jp_fetch , jp_ws_fetch , jp_kernelspec_with_metadata ):
98
+ r = await jp_fetch ("api" , "kernels" , method = "POST" , allow_nonstandard_methods = True )
99
+ kernel = json .loads (r .body .decode ())
100
+ kid = kernel ["id" ]
101
+
102
+ # Open a websocket connection.
103
+ ws = await jp_ws_fetch ("api" , "kernels" , kid , "channels" )
104
+
105
+ r = await jp_fetch ("api" , "kernels" , kid , method = "GET" )
106
+ model = json .loads (r .body .decode ())
107
+ assert model ["connections" ] == 1
108
+ culled = await get_cull_status (kid , jp_fetch ) # connected, should not be culled
109
+ assert not culled
110
+ ws .close ()
111
+ culled = await get_cull_status (kid , jp_fetch ) # not connected, should not be culled
112
+ assert not culled
113
+
114
+
76
115
# Pending kernels was released in Jupyter Client 7.1
77
116
# It is currently broken on Windows (Jan 2022). When fixed, we can remove the Windows check.
78
117
# See https://github.com/jupyter-server/jupyter_server/issues/672
0 commit comments