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

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

The first draft of a test that spawns a process and explodes the reactor.

  • 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        class TestException(Exception):
     307            pass
     308
     309        class Protocol(ProcessProtocol):
     310            def processExited(self, reason):
     311                raise TestException("processedExited raised")
     312
     313        reactor = self.buildReactor()
     314        protocol = Protocol()
     315        transport = reactor.spawnProcess(
     316            protocol, sys.executable, [sys.executable, "-c", ""],
     317            usePTY=self.usePTY)
     318
     319        transport.processEnded(0)
     320        # TODO: would be good to regain control of the reactor here and
     321        #       then fail via an assert
     322
     323
    301324class ProcessTestsBuilder(ProcessTestsBuilderBase):
    302325    """
    303326    Builder defining tests relating to L{IReactorProcess} for child processes