@@ -14,42 +14,66 @@ def start_client(client):
14
14
client .start ()
15
15
16
16
17
+ class _ClientServer (object ):
18
+ """ A class to setup a client/server pair """
19
+ def __init__ (self ):
20
+ # Client to Server pipe
21
+ csr , csw = os .pipe ()
22
+ # Server to client pipe
23
+ scr , scw = os .pipe ()
24
+
25
+ self .server_thread = Thread (target = start_io_lang_server , args = (
26
+ os .fdopen (csr , 'rb' ), os .fdopen (scw , 'wb' ), PythonLanguageServer
27
+ ))
28
+ self .server_thread .daemon = True
29
+ self .server_thread .start ()
30
+
31
+ self .client = PythonLanguageServer (os .fdopen (scr , 'rb' ), os .fdopen (csw , 'wb' ))
32
+ self .client_thread = Thread (target = start_client , args = [self .client ])
33
+ self .client_thread .daemon = True
34
+ self .client_thread .start ()
35
+
36
+
17
37
@pytest .fixture
18
38
def client_server ():
19
- """ A fixture to setup a client/server """
39
+ """ A fixture that sets up a client/server pair and shuts down the server """
40
+ client_server_pair = _ClientServer ()
20
41
21
- # Client to Server pipe
22
- csr , csw = os .pipe ()
23
- # Server to client pipe
24
- scr , scw = os .pipe ()
42
+ yield client_server_pair .client
43
+
44
+ shutdown_response = client_server_pair .client ._endpoint .request ('shutdown' ).result (timeout = CALL_TIMEOUT )
45
+ assert shutdown_response is None
46
+ client_server_pair .client ._endpoint .notify ('exit' )
25
47
26
- server_thread = Thread (target = start_io_lang_server , args = (
27
- os .fdopen (csr , 'rb' ), os .fdopen (scw , 'wb' ), PythonLanguageServer
28
- ))
29
- server_thread .daemon = True
30
- server_thread .start ()
31
48
32
- client = PythonLanguageServer ( os . fdopen ( scr , 'rb' ), os . fdopen ( csw , 'wb' ))
33
- client_thread = Thread ( target = start_client , args = [ client ])
34
- client_thread . daemon = True
35
- client_thread . start ()
49
+ @ pytest . fixture
50
+ def client_exited_server ():
51
+ """ A fixture that sets up a client/server pair and assert the server has already exited """
52
+ client_server_pair = _ClientServer ()
36
53
37
- yield client
54
+ yield client_server_pair . client
38
55
39
- shutdown_response = client ._endpoint .request ('shutdown' ).result (timeout = CALL_TIMEOUT )
40
- assert shutdown_response is None
41
- client ._endpoint .notify ('exit' )
56
+ assert client_server_pair .server_thread .is_alive () is False
42
57
43
58
44
59
def test_initialize (client_server ): # pylint: disable=redefined-outer-name
45
60
response = client_server ._endpoint .request ('initialize' , {
46
- 'processId' : 1234 ,
47
61
'rootPath' : os .path .dirname (__file__ ),
48
62
'initializationOptions' : {}
49
63
}).result (timeout = CALL_TIMEOUT )
50
64
assert 'capabilities' in response
51
65
52
66
67
+ def test_exit_with_parent_process_died (client_exited_server ): # pylint: disable=redefined-outer-name
68
+ # language server should have already exited before responding
69
+ with pytest .raises (Exception ):
70
+ client_exited_server ._endpoint .request ('initialize' , {
71
+ 'processId' : 1234 ,
72
+ 'rootPath' : os .path .dirname (__file__ ),
73
+ 'initializationOptions' : {}
74
+ }).result (timeout = CALL_TIMEOUT )
75
+
76
+
53
77
def test_missing_message (client_server ): # pylint: disable=redefined-outer-name
54
78
with pytest .raises (JsonRpcMethodNotFound ):
55
79
client_server ._endpoint .request ('unknown_method' ).result (timeout = CALL_TIMEOUT )
0 commit comments