Пример #1
0
    def test_conn2_err(self):
        """Connection closes with data proc. in progress
        """
        T = proto_helpers.StringTransportWithDisconnection()
        P = MockBLP()
        P.rx_buf_size = 4
        T.protocol = P
        P.makeConnection(T)

        P.dataReceived('A\nB\nC')
        self.assertEqual(P.lines, ['A', 'B'])

        P.connectionLost(failure.Failure(error.ConnectionAborted()))
        self.assertFalse(
            P.defer.called)  # not called until processing completes

        P._finish(ok=42)

        try:
            yield P.defer
            self.assertTrue(False)
        except error.ConnectionAborted:
            pass

        self.alldone = True
Пример #2
0
    def test_proc_err(self):
        """Processing function throws exception
        """
        T = proto_helpers.StringTransport()
        P = MockBLP()
        P.rx_buf_size = 4
        P.makeConnection(T)

        P.dataReceived('A\nB\nC\n')
        self.assertEqual(P.lines, ['A', 'B', 'C'])

        P._finish(err=RuntimeError('oops'))
        self.assertEqual(T.producerState, 'stopped')
        P.connectionLost(error.ConnectionClosed())

        # connection error will be ignored in favor of proc. error
        P.connectionLost(failure.Failure(error.ConnectionAborted()))

        try:
            yield P.defer
            self.assertTrue(False)
        except RuntimeError as e:
            self.assertEqual(e.message, 'oops')

        self.alldone = True
Пример #3
0
 def test_str(self):
     """
     The default message of L{ConnectionAborted} is a sentence which points
     to L{ITCPTransport.abortConnection()}
     """
     self.assertEqual(
         ("Connection was aborted locally"
          " using ITCPTransport.abortConnection."),
         str(error.ConnectionAborted()),
     )
Пример #4
0
 def test_strArgs(self):
     """
     Any arguments passed to L{ConnectionAborted} are included in its
     message.
     """
     self.assertEqual(
         ("Connection was aborted locally using"
          " ITCPTransport.abortConnection:"
          " foo bar."),
         str(error.ConnectionAborted("foo", "bar")),
     )
Пример #5
0
    def abortConnection(self):
        """
        Aborts the connection immediately, dropping any buffered data.

        @since: 11.1
        """
        if self.disconnected or self._aborting:
            return
        self._aborting = True
        self.stopReading()
        self.stopWriting()
        self.doRead = lambda *args, **kwargs: None
        self.doWrite = lambda *args, **kwargs: None
        self.reactor.callLater(0, self.connectionLost,
                               failure.Failure(error.ConnectionAborted()))
Пример #6
0
    def test_conn_err(self):
        """Connection closes with data in buffer, but no proc.
        """
        T = proto_helpers.StringTransportWithDisconnection()
        P = MockBLP()
        T.protocol = P
        P.makeConnection(T)

        P.dataReceived('A\nB\nC\n')
        self.assertIdentical(P.lines, None)

        P.connectionLost(failure.Failure(error.ConnectionAborted()))

        try:
            yield P.defer
            self.assertTrue(False)
        except error.ConnectionAborted:
            pass

        self.alldone = True