def test_abort(self): def connection_made(transport): transport.abort() self.protocol.connection_made = connection_made self._run_test(self.t, [TransportMock.Abort()])
def test_catch_unexpected_write_eof(self): def connection_made(transport): transport.write_eof() self.protocol.connection_made = connection_made with self.assertRaisesRegex(AssertionError, "unexpected write_eof"): self._run_test(self.t, [TransportMock.Abort()])
def test_hard_deadtime_kills_stream(self): import aioxmpp.protocol import aioxmpp.stream version = (1, 0) fut = asyncio.Future() p = aioxmpp.protocol.XMLStream(to=TEST_PEER, sorted_attributes=True, features_future=fut) t = TransportMock(self, p) s = aioxmpp.stream.StanzaStream(TEST_FROM.bare()) s.soft_timeout = timedelta(seconds=0.1) s.round_trip_time = timedelta(seconds=0.1) failure_fut = s.on_failure.future() run_coroutine( t.run_test([ TransportMock.Write( STREAM_HEADER, response=[ TransportMock.Receive( PEER_STREAM_HEADER_TEMPLATE.format( minor=version[1], major=version[0]).encode("utf-8")), ]), ], partial=True)) self.assertEqual(p.state, aioxmpp.protocol.State.OPEN) s.start(p) IQ_bak = aioxmpp.IQ def fake_iq_constructor(*args, **kwargs): iq = IQ_bak(*args, **kwargs) iq.id_ = "ping" return iq with unittest.mock.patch("aioxmpp.stanza.IQ") as IQ: IQ.side_effect = fake_iq_constructor run_coroutine( t.run_test([ TransportMock.Write(b'<iq id="ping" type="get">' b'<ping xmlns="urn:xmpp:ping"/></iq>'), ], partial=True)) run_coroutine(t.run_test([ TransportMock.Abort(), ], )) run_coroutine(asyncio.sleep(0)) self.assertFalse(s.running) self.assertTrue(failure_fut.done()) self.assertIsInstance(failure_fut.exception(), ConnectionError) self.assertIn("timeout", str(failure_fut.exception()))