aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp/naming/utils
diff options
context:
space:
mode:
Diffstat (limited to 'test/cpp/naming/utils')
-rwxr-xr-xtest/cpp/naming/utils/dns_resolver.py6
-rwxr-xr-xtest/cpp/naming/utils/dns_server.py21
-rwxr-xr-xtest/cpp/naming/utils/tcp_connect.py6
3 files changed, 26 insertions, 7 deletions
diff --git a/test/cpp/naming/utils/dns_resolver.py b/test/cpp/naming/utils/dns_resolver.py
index 6b272444e7..74f4ca2351 100755
--- a/test/cpp/naming/utils/dns_resolver.py
+++ b/test/cpp/naming/utils/dns_resolver.py
@@ -16,9 +16,12 @@
"""Makes DNS queries for A records to specified servers"""
import argparse
-import signal
+import threading
+import time
import twisted.internet.task as task
import twisted.names.client as client
+import twisted.internet.reactor as reactor
+
def main():
argp = argparse.ArgumentParser(description='Make DNS queries for A records')
@@ -31,7 +34,6 @@ def main():
argp.add_argument('-t', '--timeout', default=1, type=int,
help=('Force process exit after this number of seconds.'))
args = argp.parse_args()
- signal.alarm(args.timeout)
def OnResolverResultAvailable(result):
answers, authority, additional = result
for a in answers:
diff --git a/test/cpp/naming/utils/dns_server.py b/test/cpp/naming/utils/dns_server.py
index 9f42f65ee6..1e8e2e3287 100755
--- a/test/cpp/naming/utils/dns_server.py
+++ b/test/cpp/naming/utils/dns_server.py
@@ -20,6 +20,8 @@ import sys
import yaml
import signal
import os
+import threading
+import time
import twisted
import twisted.internet
@@ -33,6 +35,7 @@ import twisted.names.dns
import twisted.names.server
from twisted.names import client, server, common, authority, dns
import argparse
+import platform
_SERVER_HEALTH_CHECK_RECORD_NAME = 'health-check-local-dns-server-is-alive.resolver-tests.grpctestingexp' # missing end '.' for twisted syntax
_SERVER_HEALTH_CHECK_RECORD_DATA = '123.123.123.123'
@@ -115,6 +118,18 @@ def _quit_on_signal(signum, _frame):
sys.stdout.flush()
sys.exit(0)
+def flush_stdout_loop():
+ num_timeouts_so_far = 0
+ sleep_time = 1
+ # Prevent zombies. Tests that use this server are short-lived.
+ max_timeouts = 60 * 2
+ while num_timeouts_so_far < max_timeouts:
+ sys.stdout.flush()
+ time.sleep(sleep_time)
+ num_timeouts_so_far += 1
+ print('Process timeout reached, or cancelled. Exitting 0.')
+ os.kill(os.getpid(), signal.SIGTERM)
+
def main():
argp = argparse.ArgumentParser(description='Local DNS Server for resolver tests')
argp.add_argument('-p', '--port', default=None, type=int,
@@ -123,11 +138,11 @@ def main():
help=('Directory of resolver_test_record_groups.yaml file. '
'Defauls to path needed when the test is invoked as part of run_tests.py.'))
args = argp.parse_args()
- signal.signal(signal.SIGALRM, _quit_on_signal)
signal.signal(signal.SIGTERM, _quit_on_signal)
signal.signal(signal.SIGINT, _quit_on_signal)
- # Prevent zombies. Tests that use this server are short-lived.
- signal.alarm(2 * 60)
+ output_flush_thread = threading.Thread(target=flush_stdout_loop)
+ output_flush_thread.setDaemon(True)
+ output_flush_thread.start()
start_local_dns_server(args)
if __name__ == '__main__':
diff --git a/test/cpp/naming/utils/tcp_connect.py b/test/cpp/naming/utils/tcp_connect.py
index bf7455e3c2..5773c7cae8 100755
--- a/test/cpp/naming/utils/tcp_connect.py
+++ b/test/cpp/naming/utils/tcp_connect.py
@@ -16,8 +16,11 @@
"""Opens a TCP connection to a specified server and then exits."""
import argparse
-import signal
import socket
+import threading
+import time
+import sys
+
def main():
argp = argparse.ArgumentParser(description='Open a TCP handshake to a server')
@@ -28,7 +31,6 @@ def main():
argp.add_argument('-t', '--timeout', default=1, type=int,
help='Force process exit after this number of seconds.')
args = argp.parse_args()
- signal.alarm(args.timeout)
socket.create_connection([args.server_host, args.server_port])
if __name__ == '__main__':