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

File test-process-exited-raises.2.diff, 1.2 KB (added by hodgestar, 5 years ago)

Less broken version of the simple test that raises during processExited and explodes the reactor. Fails (and explodes all later tests) without exarkun's patch. Passes with it.

  • 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.2, 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        # TODO: figure out how to regain control of the reactor and raise
     323        #       an error.
     324
     325
     326
    301327class ProcessTestsBuilder(ProcessTestsBuilderBase):
    302328    """
    303329    Builder defining tests relating to L{IReactorProcess} for child processes