_dns_resolver_test.py
Go to the documentation of this file.
1 # Copyright 2019 The gRPC Authors
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 """Tests for an actual dns resolution."""
15 
16 import logging
17 import unittest
18 
19 import grpc
20 import six
21 
22 from tests.unit import test_common
23 from tests.unit.framework.common import test_constants
24 
25 _METHOD = '/ANY/METHOD'
26 _REQUEST = b'\x00\x00\x00'
27 _RESPONSE = _REQUEST
28 
29 
31 
32  def service(self, unused_handler_details):
34  lambda request, unused_context: request,
35  )
36 
37 
38 class DNSResolverTest(unittest.TestCase):
39 
40  def setUp(self):
41  self._server = test_common.test_server()
42  self._server.add_generic_rpc_handlers((GenericHandler(),))
43  self._port = self._server.add_insecure_port('[::]:0')
44  self._server.start()
45 
46  def tearDown(self):
47  self._server.stop(None)
48 
50  # NOTE(https://github.com/grpc/grpc/issues/18422)
51  # In short, Gevent + C-Ares = Segfault. The C-Ares driver is not
52  # supported by custom io manager like "gevent"
53  # NOTE(b/201064791): use loopback46.unittest.grpc.io since
54  # it returns the expected responses even when DNS64 dns servers
55  # are used on the test worker (and for purposes of this
56  # test the use of loopback4 vs loopback46 makes no difference).
57  with grpc.insecure_channel('loopback46.unittest.grpc.io:%d' %
58  self._port) as channel:
59  self.assertEqual(
60  channel.unary_unary(_METHOD)(
61  _REQUEST,
62  timeout=10,
63  ), _RESPONSE)
64 
65 
66 if __name__ == '__main__':
67  logging.basicConfig()
68  unittest.main(verbosity=2)
grpc.unary_unary_rpc_method_handler
def unary_unary_rpc_method_handler(behavior, request_deserializer=None, response_serializer=None)
Definition: src/python/grpcio/grpc/__init__.py:1510
grpc.insecure_channel
def insecure_channel(target, options=None, compression=None)
Definition: src/python/grpcio/grpc/__init__.py:1962
tests.unit._dns_resolver_test.DNSResolverTest._server
_server
Definition: _dns_resolver_test.py:41
tests.unit._dns_resolver_test.DNSResolverTest._port
_port
Definition: _dns_resolver_test.py:43
tests.unit._dns_resolver_test.DNSResolverTest.test_connect_loopback
def test_connect_loopback(self)
Definition: _dns_resolver_test.py:49
start
static uint64_t start
Definition: benchmark-pound.c:74
tests.unit._dns_resolver_test.GenericHandler.service
def service(self, unused_handler_details)
Definition: _dns_resolver_test.py:32
grpc.GenericRpcHandler
Definition: src/python/grpcio/grpc/__init__.py:1333
tests.unit._dns_resolver_test.DNSResolverTest.setUp
def setUp(self)
Definition: _dns_resolver_test.py:40
tests.unit._dns_resolver_test.DNSResolverTest.tearDown
def tearDown(self)
Definition: _dns_resolver_test.py:46
tests.unit._dns_resolver_test.DNSResolverTest
Definition: _dns_resolver_test.py:38
tests.unit
Definition: src/python/grpcio_tests/tests/unit/__init__.py:1
tests.unit._dns_resolver_test.GenericHandler
Definition: _dns_resolver_test.py:30
stop
static const char stop[]
Definition: benchmark-async-pummel.c:35
tests.unit.framework.common
Definition: src/python/grpcio_tests/tests/unit/framework/common/__init__.py:1


grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:38