Exemplo n.º 1
0
 def test_remote_close_during_call(self):
     chan, rchan = make_channel_pair()
     conn = Connection(chan)
     Connection(rchan).close()
     with self.assertRaisesRegex(DisconnectError,
                                 'Connection was remotely closed'):
         conn.call(nop)
     conn.close()
Exemplo n.º 2
0
 def _run_export_over_multiple_connections_test():
     options = Options(accept_exported_modules=True)
     conn1 = Connection(make_channel_pair()[0], options=options)
     try:
         Connection(make_channel_pair()[0], options=options)
     except ValueError:
         pass
     else:
         raise AssertionError('ValueError not raised')
     conn1.cancel()
     try:
         conn1.close()
     except Exception:  # generated by cancel()
         pass
Exemplo n.º 3
0
 def test_invalid_timeout_type(self):
     for timeout in [
         [],
             '12.0',
     ]:
         with self.assertRaises(TypeError):
             Connection(EOFChannel(), options=Options(timeout=timeout))
Exemplo n.º 4
0
 def test_enter_after_cancel(self):
     # There are no writes to chan2, so handshake should never complete
     chan1, chan2 = make_channel_pair()
     conn = Connection(chan1)
     conn.cancel()
     with self.assertRaises(ValueError):
         conn.__enter__()
Exemplo n.º 5
0
 def test_connect_exception(self):
     chan = FailingChannel()
     chan.connect_future.set_exception(FirstError())
     chan.close_future.set_result(None)
     with self.assertRaises(FirstError):
         with Connection(chan):
             pass
Exemplo n.º 6
0
 def test_no_idle_messages(self):
     timeout = None
     TimeoutableQueue.last = None
     chan = ByteCountingConnectionChannel()
     remote_sender_queue = TimeoutableQueue.last
     with Connection(chan, options=Options(timeout=timeout)) as conn:
         conn.call(nop)  # ensure handshake is done
         self.assertIsNone(remote_sender_queue.get_last_get_timeout())
Exemplo n.º 7
0
 def test_invalid_timeout_value(self):
     for timeout in [
             -1,
             -1.0,
             float('nan'),
             float('-inf'),
     ]:
         with self.assertRaises(ValueError):
             Connection(EOFChannel(), options=Options(timeout=timeout))
Exemplo n.º 8
0
 def test_channel_close_exception_is_ignored_after_previous_exception(self):
     chan = FailingChannel()
     chan.connect_future.set_result(None)
     chan.send_future.set_result(None)
     chan.recv_future.set_exception(FirstError())
     chan.close_future.set_exception(SecondError())
     with self.assertRaises(FirstError):
         with Connection(chan) as conn:
             conn.wait()
Exemplo n.º 9
0
 def test_idle_messages(self):
     timeout = 10
     TimeoutableQueue.last = None
     chan = ByteCountingConnectionChannel()
     remote_sender_queue = TimeoutableQueue.last
     with Connection(chan, options=Options(timeout=timeout)) as conn:
         conn.call(nop)  # ensure handshake is done
         for _ in range(10):
             recv_bytes = chan.get_recv_bytes()
             remote_sender_queue.simulate_timeout()
             chan.wait_recv_bytes_changed(recv_bytes)
         last_get_timeout = remote_sender_queue.get_last_get_timeout()
         self.assertIsNotNone(last_get_timeout)
         self.assertLess(last_get_timeout, timeout * 0.75)
         self.assertGreater(last_get_timeout, timeout * 0.1)
Exemplo n.º 10
0
def boot_connection(export=top_name, cwd=None):
    if cwd is None:
        cwd = mktemp()
        os.mkdir(cwd)
    chan = ProcessChannel([
        sys.executable,
        '-c',
        get_bios(),
    ], cwd=cwd)
    conn = Connection(chan)
    if export is None:
        export = []
    elif isinstance(export, str):
        export = [export]
    conn.export(*export)
    return conn
Exemplo n.º 11
0
 def test_communication_error_during_call(self):
     chan = ConnectionChannel()
     conn = Connection(chan)
     try:
         with self.assertRaisesRegex(DisconnectError,
                                     'Connection was aborted due to .*'):
             conn.call(Box(chan.cancel)
                       )  # simulate communication error with channel.cancel
         with self.assertRaisesRegex(DisconnectError,
                                     'Connection was aborted due to .*'):
             conn.call(nop)
     finally:
         try:
             conn.close()
         except Exception:
             pass
Exemplo n.º 12
0
 def test_enter_after_remote_close(self):
     chan1, chan2 = make_channel_pair()
     conn1, conn2 = Connection(chan1), Connection(chan2)
     conn2.close()
     with conn1:
         pass
Exemplo n.º 13
0
 def _run_shutdown_with_unresponsive_connections_test():
     Connection(make_channel_pair()[0], options=Options(timeout=1e100))
Exemplo n.º 14
0
 def test_enter_when_connect_fails(self):
     conn = Connection(UnconnectableChannel())
     with self.assertRaises(ConnectError):
         conn.__enter__()
     with self.assertRaisesRegex(ValueError, 'Connection is closed'):
         conn.__enter__()
Exemplo n.º 15
0
 def test_large_timeout(self):
     with Connection(ConnectionChannel(),
                     options=Options(timeout=1.0e100)) as conn:
         conn.call(nop)
Exemplo n.º 16
0
 def test_valid_timeouts(self):
     for timeout in [10, 10.0]:
         with Connection(ConnectionChannel(),
                         options=Options(timeout=timeout)) as conn:
             conn.call(nop)
Exemplo n.º 17
0
 def test_exit_after_disconnect(self):
     chan = ConnectionChannel()
     with self.assertRaises(ValueError):
         with Connection(chan) as conn:
             conn.call(Box(chan.cancel))