示例#1
0
文件: servers.py 项目: rusek/across
def _set_debug_level_and_connect():
    set_debug_level(10)
    handler = ProcessConnectionHandler()
    with ServerWorker(run_tcp, localhost, 0, handler=handler) as worker:
        with Connection.from_tcp(*worker.address) as conn:
            if conn.call(get_debug_level) != 10:
                raise AssertionError
示例#2
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
示例#3
0
 def test_invalid_timeout_type(self):
     for timeout in [
         [],
             '12.0',
     ]:
         with self.assertRaises(TypeError):
             Connection(EOFChannel(), options=Options(timeout=timeout))
示例#4
0
文件: state.py 项目: rusek/across
 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
示例#5
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())
示例#6
0
文件: servers.py 项目: rusek/across
 def __run_stopping_test(self, handler):
     with ServerWorker(run_tcp, localhost, 0, handler=handler) as worker:
         conn = Connection.from_tcp(*worker.address)
         self.assertEqual(conn.call(add, 1, 2), 3)
     self.assertRaises(DisconnectError, conn.call, add, 1, 2)
     try:
         conn.close()
     except OSError:  # Connection reset by peer on Windows
         pass
示例#7
0
文件: state.py 项目: rusek/across
 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()
示例#8
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))
示例#9
0
文件: state.py 项目: rusek/across
 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()
示例#10
0
文件: servers.py 项目: rusek/across
 def test_bios_handler(self):
     handler = BIOSConnectionHandler()
     # Child process may be interrupted during interpreter shutdown, causing various errors to be
     # printed on stderr. Let's suppress them.
     with InheritableStderrCollector():
         with ServerWorker(run_tcp, localhost, 0,
                           handler=handler) as worker:
             with Connection.from_tcp(*worker.address) as conn:
                 self.assertEqual(conn.call(add, 1, 2), 3)
                 self.assertNotEqual(conn.call(os.getpid), os.getpid())
示例#11
0
文件: state.py 项目: rusek/across
 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__()
示例#12
0
文件: servers.py 项目: rusek/across
    def test_multiple_connections(self):
        with ServerWorker(run_tcp, localhost, 0) as worker:
            num_conns = 5

            conns = [
                Connection.from_tcp(*worker.address) for _ in range(num_conns)
            ]

            for i, conn in enumerate(conns):
                self.assertEqual(conn.call(add, i, 1), i + 1)

            for conn in conns:
                conn.close()
示例#13
0
文件: state.py 项目: rusek/across
 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
示例#14
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)
示例#15
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
示例#16
0
 def test_from_command(self):
     with Connection.from_command(base_args) as conn:
         self.assertEqual(conn.call(operator.add, 2, 2), 4)
示例#17
0
 def test_from_shell(self):
     with Connection.from_shell(' '.join(map(shell_quote,
                                             base_args))) as conn:
         self.assertEqual(conn.call(operator.add, 2, 2), 4)
示例#18
0
 def test_from_process(self):
     proc = subprocess.Popen(base_args,
                             stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE)
     with Connection.from_process(proc) as conn:
         self.assertEqual(conn.call(operator.add, 2, 2), 4)
示例#19
0
 def test_large_timeout(self):
     with Connection(ConnectionChannel(),
                     options=Options(timeout=1.0e100)) as conn:
         conn.call(nop)
示例#20
0
 def test_valid_timeouts(self):
     for timeout in [10, 10.0]:
         with Connection(ConnectionChannel(),
                         options=Options(timeout=timeout)) as conn:
             conn.call(nop)
示例#21
0
文件: state.py 项目: rusek/across
 def _run_shutdown_with_unresponsive_connections_test():
     Connection(make_channel_pair()[0], options=Options(timeout=1e100))
示例#22
0
文件: state.py 项目: rusek/across
 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__()
示例#23
0
文件: servers.py 项目: rusek/across
 def test_unix(self):
     path = mktemp()
     with ServerWorker(run_unix, path):
         with Connection.from_unix(path) as conn:
             self.assertEqual(conn.call(add, 1, 2), 3)
示例#24
0
文件: state.py 项目: rusek/across
 def test_exit_after_disconnect(self):
     chan = ConnectionChannel()
     with self.assertRaises(ValueError):
         with Connection(chan) as conn:
             conn.call(Box(chan.cancel))
示例#25
0
文件: servers.py 项目: rusek/across
 def test_tcp_dual_stack(self):
     with ServerWorker(run_tcp, anyaddr_ipv6, 0) as worker:
         with Connection.from_tcp(localhost, worker.address[1]) as conn:
             self.assertEqual(conn.call(add, 1, 2), 3)
示例#26
0
文件: servers.py 项目: rusek/across
 def test_tcp_ipv6(self):
     with ServerWorker(run_tcp, localhost_ipv6, 0) as worker:
         with Connection.from_tcp(*worker.address[:2]) as conn:
             self.assertEqual(conn.call(add, 1, 2), 3)
示例#27
0
文件: state.py 项目: rusek/across
 def test_enter_after_remote_close(self):
     chan1, chan2 = make_channel_pair()
     conn1, conn2 = Connection(chan1), Connection(chan2)
     conn2.close()
     with conn1:
         pass
示例#28
0
文件: servers.py 项目: rusek/across
 def make_connection(self, handler):
     sock1, sock2 = make_tcp_socket_pair()
     conn = Connection.from_socket(sock1)
     handler.handle_socket(sock2)
     return conn
示例#29
0
 def test_from_command_no_action(self):
     with Connection.from_command(base_args):
         pass