Exemplo n.º 1
0
  def test_immediately_connectable_channel_connectivity(self):
    server_completion_queue = _low.CompletionQueue()
    server = _low.Server(server_completion_queue, [])
    port = server.add_http2_port('[::]:0')
    server.start()
    server_completion_queue_thread = threading.Thread(
        target=_drive_completion_queue, args=(server_completion_queue,))
    server_completion_queue_thread.start()
    channel = beta.create_insecure_channel('localhost', port)
    callback = _Callback()

    try:
      ready_future = utilities.channel_ready_future(channel)
      ready_future.add_done_callback(callback.accept_value)
      self.assertIsNone(
          ready_future.result(test_constants.SHORT_TIMEOUT))
      value_passed_to_callback = callback.block_until_called()
      self.assertIs(ready_future, value_passed_to_callback)
      self.assertFalse(ready_future.cancelled())
      self.assertTrue(ready_future.done())
      self.assertFalse(ready_future.running())
      # Cancellation after maturity has no effect.
      ready_future.cancel()
      self.assertFalse(ready_future.cancelled())
      self.assertTrue(ready_future.done())
      self.assertFalse(ready_future.running())
    finally:
      ready_future.cancel()
      server.shutdown()
      server_completion_queue.shutdown()
      server_completion_queue_thread.join()
Exemplo n.º 2
0
    def test_immediately_connectable_channel_connectivity(self):
        server = implementations.server({})
        port = server.add_insecure_port('[::]:0')
        server.start()
        channel = implementations.insecure_channel('localhost', port)
        callback = _Callback()

        try:
            ready_future = utilities.channel_ready_future(channel)
            ready_future.add_done_callback(callback.accept_value)
            self.assertIsNone(
                ready_future.result(timeout=test_constants.LONG_TIMEOUT))
            value_passed_to_callback = callback.block_until_called()
            self.assertIs(ready_future, value_passed_to_callback)
            self.assertFalse(ready_future.cancelled())
            self.assertTrue(ready_future.done())
            self.assertFalse(ready_future.running())
            # Cancellation after maturity has no effect.
            ready_future.cancel()
            self.assertFalse(ready_future.cancelled())
            self.assertTrue(ready_future.done())
            self.assertFalse(ready_future.running())
        finally:
            ready_future.cancel()
            server.stop(0)
Exemplo n.º 3
0
    def test_immediately_connectable_channel_connectivity(self):
        server_completion_queue = _low.CompletionQueue()
        server = _low.Server(server_completion_queue, [])
        port = server.add_http2_port('[::]:0')
        server.start()
        server_completion_queue_thread = threading.Thread(
            target=_drive_completion_queue, args=(server_completion_queue, ))
        server_completion_queue_thread.start()
        channel = implementations.insecure_channel('localhost', port)
        callback = _Callback()

        try:
            ready_future = utilities.channel_ready_future(channel)
            ready_future.add_done_callback(callback.accept_value)
            self.assertIsNone(ready_future.result(
                test_constants.SHORT_TIMEOUT))
            value_passed_to_callback = callback.block_until_called()
            self.assertIs(ready_future, value_passed_to_callback)
            self.assertFalse(ready_future.cancelled())
            self.assertTrue(ready_future.done())
            self.assertFalse(ready_future.running())
            # Cancellation after maturity has no effect.
            ready_future.cancel()
            self.assertFalse(ready_future.cancelled())
            self.assertTrue(ready_future.done())
            self.assertFalse(ready_future.running())
        finally:
            ready_future.cancel()
            server.shutdown()
            server_completion_queue.shutdown()
            server_completion_queue_thread.join()
Exemplo n.º 4
0
    def test_immediately_connectable_channel_connectivity(self):
        server = implementations.server({})
        port = server.add_insecure_port('[::]:0')
        server.start()
        channel = implementations.insecure_channel('localhost', port)
        callback = _Callback()

        try:
            ready_future = utilities.channel_ready_future(channel)
            ready_future.add_done_callback(callback.accept_value)
            self.assertIsNone(
                ready_future.result(timeout=test_constants.LONG_TIMEOUT))
            value_passed_to_callback = callback.block_until_called()
            self.assertIs(ready_future, value_passed_to_callback)
            self.assertFalse(ready_future.cancelled())
            self.assertTrue(ready_future.done())
            self.assertFalse(ready_future.running())
            # Cancellation after maturity has no effect.
            ready_future.cancel()
            self.assertFalse(ready_future.cancelled())
            self.assertTrue(ready_future.done())
            self.assertFalse(ready_future.running())
        finally:
            ready_future.cancel()
            server.stop(0)
Exemplo n.º 5
0
  def test_lonely_channel_connectivity(self):
    channel = beta.create_insecure_channel('localhost', 12345)
    callback = _Callback()

    ready_future = utilities.channel_ready_future(channel)
    ready_future.add_done_callback(callback.accept_value)
    with self.assertRaises(future.TimeoutError):
      ready_future.result(test_constants.SHORT_TIMEOUT)
    self.assertFalse(ready_future.cancelled())
    self.assertFalse(ready_future.done())
    self.assertTrue(ready_future.running())
    ready_future.cancel()
    value_passed_to_callback = callback.block_until_called()
    self.assertIs(ready_future, value_passed_to_callback)
    self.assertTrue(ready_future.cancelled())
    self.assertTrue(ready_future.done())
    self.assertFalse(ready_future.running())
Exemplo n.º 6
0
    def test_lonely_channel_connectivity(self):
        channel = implementations.insecure_channel('localhost', 12345)
        callback = _Callback()

        ready_future = utilities.channel_ready_future(channel)
        ready_future.add_done_callback(callback.accept_value)
        with self.assertRaises(future.TimeoutError):
            ready_future.result(timeout=test_constants.SHORT_TIMEOUT)
        self.assertFalse(ready_future.cancelled())
        self.assertFalse(ready_future.done())
        self.assertTrue(ready_future.running())
        ready_future.cancel()
        value_passed_to_callback = callback.block_until_called()
        self.assertIs(ready_future, value_passed_to_callback)
        self.assertTrue(ready_future.cancelled())
        self.assertTrue(ready_future.done())
        self.assertFalse(ready_future.running())