|
|
|
@ -17,6 +17,7 @@ import time |
|
|
|
|
import weakref |
|
|
|
|
import unittest |
|
|
|
|
import threading |
|
|
|
|
import logging |
|
|
|
|
import socket |
|
|
|
|
from six.moves import queue |
|
|
|
|
|
|
|
|
@ -25,7 +26,7 @@ import grpc |
|
|
|
|
from tests.unit import test_common |
|
|
|
|
from tests.unit.framework.common import test_constants |
|
|
|
|
import tests.unit.framework.common |
|
|
|
|
from tests.unit.framework.common import bound_socket |
|
|
|
|
from tests.unit.framework.common import get_socket |
|
|
|
|
|
|
|
|
|
_UNARY_UNARY = '/test/UnaryUnary' |
|
|
|
|
_UNARY_STREAM = '/test/UnaryStream' |
|
|
|
@ -101,7 +102,8 @@ class _GenericHandler(grpc.GenericRpcHandler): |
|
|
|
|
|
|
|
|
|
def create_dummy_channel(): |
|
|
|
|
"""Creating dummy channels is a workaround for retries""" |
|
|
|
|
with bound_socket() as (host, port): |
|
|
|
|
host, port, sock = get_socket() |
|
|
|
|
sock.close() |
|
|
|
|
return grpc.insecure_channel('{}:{}'.format(host, port)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -203,7 +205,11 @@ class MetadataFlagsTest(unittest.TestCase): |
|
|
|
|
# main thread. So, it need another method to store the |
|
|
|
|
# exceptions and raise them again in main thread. |
|
|
|
|
unhandled_exceptions = queue.Queue() |
|
|
|
|
with bound_socket(listen=False) as (host, port): |
|
|
|
|
|
|
|
|
|
# We just need an unused TCP port |
|
|
|
|
host, port, sock = get_socket() |
|
|
|
|
sock.close() |
|
|
|
|
|
|
|
|
|
addr = '{}:{}'.format(host, port) |
|
|
|
|
wg = test_common.WaitGroup(len(_ALL_CALL_CASES)) |
|
|
|
|
|
|
|
|
@ -227,6 +233,7 @@ class MetadataFlagsTest(unittest.TestCase): |
|
|
|
|
for perform_call in _ALL_CALL_CASES: |
|
|
|
|
test_thread = threading.Thread(target=test_call, |
|
|
|
|
args=(perform_call,)) |
|
|
|
|
test_thread.daemon = True |
|
|
|
|
test_thread.exception = None |
|
|
|
|
test_thread.start() |
|
|
|
|
test_threads.append(test_thread) |
|
|
|
@ -234,8 +241,7 @@ class MetadataFlagsTest(unittest.TestCase): |
|
|
|
|
# Start the server after the connections are waiting |
|
|
|
|
wg.wait() |
|
|
|
|
server = test_common.test_server(reuse_port=True) |
|
|
|
|
server.add_generic_rpc_handlers( |
|
|
|
|
(_GenericHandler(weakref.proxy(self)),)) |
|
|
|
|
server.add_generic_rpc_handlers((_GenericHandler(weakref.proxy(self)),)) |
|
|
|
|
server.add_insecure_port(addr) |
|
|
|
|
server.start() |
|
|
|
|
|
|
|
|
@ -250,4 +256,5 @@ class MetadataFlagsTest(unittest.TestCase): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
|
logging.basicConfig(level=logging.DEBUG) |
|
|
|
|
unittest.main(verbosity=2) |
|
|
|
|