Ticket #5151: test-process-exited-raises.3.diff

File test-process-exited-raises.3.diff, 1.4 KB (added by hodgestar, 3 years ago)

Version of previous patch that doesn't wreck the rest of the test suite if the test fails.

  • twisted/internet/test/test_process.py

     
    298298        self.runReactor(reactor) 
    299299 
    300300 
     301    def test_processExitedRaises(self): 
     302        """ 
     303        Test that a protocol raising an exception inside processExited 
     304        doesn't cause the reactor to explode. 
     305        """ 
     306        reactor = self.buildReactor() 
     307 
     308        class TestException(Exception): 
     309            pass 
     310 
     311        class Protocol(ProcessProtocol): 
     312            def processExited(self, reason): 
     313                reactor.callLater(0.01, lambda: reactor.stop()) 
     314                raise TestException("processedExited raised") 
     315 
     316        protocol = Protocol() 
     317        transport = reactor.spawnProcess( 
     318               protocol, sys.executable, [sys.executable, "-c", ""], 
     319               usePTY=self.usePTY) 
     320        reactor.run() 
     321 
     322        # Manually clean-up broken process handler 
     323        for pid, handler in process.reapProcessHandlers.items(): 
     324            if handler is not transport: 
     325                continue 
     326            process.unregisterReapProcessHandler(pid, handler) 
     327 
     328 
    301329class ProcessTestsBuilder(ProcessTestsBuilderBase): 
    302330    """ 
    303331    Builder defining tests relating to L{IReactorProcess} for child processes