@@ -218,6 +218,8 @@ def setUp(self):
218218 pact .platform , 'platform' , autospec = True ).start ()
219219 self .mock_wait_for_server_start = patch .object (
220220 pact .Pact , '_wait_for_server_start' , autospec = True ).start ()
221+ self .mock_Pid_exists = patch .object (
222+ pact .psutil , 'pid_exists' , autospec = True ).start ()
221223
222224 def test_start_fails (self ):
223225 self .mock_Popen .return_value .returncode = 1
@@ -289,18 +291,22 @@ def test_stop_windows(self):
289291 self .mock_platform .return_value = 'Windows'
290292 ruby_exe = Mock (spec = Process )
291293 self .mock_Process .return_value .children .return_value = [ruby_exe ]
294+ self .mock_Pid_exists .return_value = False
292295 pact = Pact (Consumer ('consumer' ), Provider ('provider' ))
293- pact ._process = Mock (spec = Popen , pid = 999 , returncode = 0 )
296+ pact ._process = Mock (spec = Popen , pid = 999 )
294297 pact .stop_service ()
295298
296299 self .assertFalse (pact ._process .terminate .called )
297- pact ._process .communicate .assert_called_once_with ( )
300+ self . assertFalse ( pact ._process .communicate .called )
298301 self .mock_Process .assert_called_once_with (999 )
299302 self .mock_Process .return_value .children .assert_called_once_with (
300303 recursive = True )
301304 ruby_exe .terminate .assert_called_once_with ()
305+ self .mock_Process .return_value .wait .assert_called_once_with ()
306+ self .mock_Pid_exists .assert_called_once_with (999 )
302307
303- def test_stop_fails (self ):
308+ def test_stop_fails_posix (self ):
309+ self .mock_platform .return_value = 'Linux'
304310 self .mock_Popen .return_value .returncode = 1
305311 pact = Pact (Consumer ('consumer' ), Provider ('provider' ))
306312 pact ._process = Mock (spec = Popen , pid = 999 , returncode = 1 )
@@ -310,6 +316,24 @@ def test_stop_fails(self):
310316 pact ._process .terminate .assert_called_once_with ()
311317 pact ._process .communicate .assert_called_once_with ()
312318
319+ def test_stop_fails_windows (self ):
320+ self .mock_platform .return_value = 'Windows'
321+ self .mock_Popen .return_value .returncode = 15
322+ self .mock_Pid_exists .return_value = True
323+
324+ pact = Pact (Consumer ('consumer' ), Provider ('provider' ))
325+ pact ._process = Mock (spec = Popen , pid = 999 , returncode = 15 )
326+ with self .assertRaises (RuntimeError ):
327+ pact .stop_service ()
328+
329+ self .assertFalse (pact ._process .terminate .called )
330+ self .assertFalse (pact ._process .communicate .called )
331+ self .mock_Process .assert_called_once_with (999 )
332+ self .mock_Process .return_value .children .assert_called_once_with (
333+ recursive = True )
334+ self .mock_Process .return_value .wait .assert_called_once_with ()
335+ self .mock_Pid_exists .assert_called_once_with (999 )
336+
313337
314338class PactWaitForServerStartTestCase (TestCase ):
315339 def setUp (self ):
0 commit comments