From e678187996bb7239315f30d9e50734c50ee4027b Mon Sep 17 00:00:00 2001 From: Eric Gribkoff Date: Thu, 27 Dec 2018 09:39:53 -0800 Subject: use test constants, fix formatting --- .../grpc_health/v1/health.py | 10 ++++---- .../tests/health_check/_health_servicer_test.py | 27 +++++++++++----------- 2 files changed, 18 insertions(+), 19 deletions(-) (limited to 'src/python') diff --git a/src/python/grpcio_health_checking/grpc_health/v1/health.py b/src/python/grpcio_health_checking/grpc_health/v1/health.py index 75c480b0a7..0a5bbb5504 100644 --- a/src/python/grpcio_health_checking/grpc_health/v1/health.py +++ b/src/python/grpcio_health_checking/grpc_health/v1/health.py @@ -102,11 +102,11 @@ class HealthServicer(_health_pb2_grpc.HealthServicer): def set(self, service, status): """Sets the status of a service. - Args: - service: string, the name of the service. NOTE, '' must be set. - status: HealthCheckResponse.status enum value indicating the status of - the service - """ + Args: + service: string, the name of the service. NOTE, '' must be set. + status: HealthCheckResponse.status enum value indicating the status of + the service + """ with self._lock: self._server_status[service] = status if service in self._watchers: diff --git a/src/python/grpcio_tests/tests/health_check/_health_servicer_test.py b/src/python/grpcio_tests/tests/health_check/_health_servicer_test.py index 657ceef1e4..bf90fa15c0 100644 --- a/src/python/grpcio_tests/tests/health_check/_health_servicer_test.py +++ b/src/python/grpcio_tests/tests/health_check/_health_servicer_test.py @@ -22,11 +22,10 @@ from grpc_health.v1 import health_pb2 from grpc_health.v1 import health_pb2_grpc from tests.unit import test_common +from tests.unit.framework.common import test_constants from six.moves import queue -_QUEUE_TIMEOUT_S = 5 - _SERVING_SERVICE = 'grpc.test.TestServiceServing' _UNKNOWN_SERVICE = 'grpc.test.TestServiceUnknown' _NOT_SERVING_SERVICE = 'grpc.test.TestServiceNotServing' @@ -98,7 +97,7 @@ class HealthServicerTest(unittest.TestCase): target=_consume_responses, args=(rendezvous, response_queue)) thread.start() - response = response_queue.get(timeout=_QUEUE_TIMEOUT_S) + response = response_queue.get(timeout=test_constants.SHORT_TIMEOUT) self.assertEqual(health_pb2.HealthCheckResponse.SERVING, response.status) @@ -114,19 +113,19 @@ class HealthServicerTest(unittest.TestCase): target=_consume_responses, args=(rendezvous, response_queue)) thread.start() - response = response_queue.get(timeout=_QUEUE_TIMEOUT_S) + response = response_queue.get(timeout=test_constants.SHORT_TIMEOUT) self.assertEqual(health_pb2.HealthCheckResponse.SERVICE_UNKNOWN, response.status) self._servicer.set(_WATCH_SERVICE, health_pb2.HealthCheckResponse.SERVING) - response = response_queue.get(timeout=_QUEUE_TIMEOUT_S) + response = response_queue.get(timeout=test_constants.SHORT_TIMEOUT) self.assertEqual(health_pb2.HealthCheckResponse.SERVING, response.status) self._servicer.set(_WATCH_SERVICE, health_pb2.HealthCheckResponse.NOT_SERVING) - response = response_queue.get(timeout=_QUEUE_TIMEOUT_S) + response = response_queue.get(timeout=test_constants.SHORT_TIMEOUT) self.assertEqual(health_pb2.HealthCheckResponse.NOT_SERVING, response.status) @@ -142,14 +141,14 @@ class HealthServicerTest(unittest.TestCase): target=_consume_responses, args=(rendezvous, response_queue)) thread.start() - response = response_queue.get(timeout=_QUEUE_TIMEOUT_S) + response = response_queue.get(timeout=test_constants.SHORT_TIMEOUT) self.assertEqual(health_pb2.HealthCheckResponse.SERVICE_UNKNOWN, response.status) self._servicer.set('some-other-service', health_pb2.HealthCheckResponse.SERVING) - with self.assertRaises(queue.Empty) as context: - response_queue.get(timeout=_QUEUE_TIMEOUT_S) + with self.assertRaises(queue.Empty): + response_queue.get(timeout=test_constants.SHORT_TIMEOUT) rendezvous.cancel() thread.join() @@ -168,8 +167,8 @@ class HealthServicerTest(unittest.TestCase): thread1.start() thread2.start() - response1 = response_queue1.get(timeout=_QUEUE_TIMEOUT_S) - response2 = response_queue2.get(timeout=_QUEUE_TIMEOUT_S) + response1 = response_queue1.get(timeout=test_constants.SHORT_TIMEOUT) + response2 = response_queue2.get(timeout=test_constants.SHORT_TIMEOUT) self.assertEqual(health_pb2.HealthCheckResponse.SERVICE_UNKNOWN, response1.status) self.assertEqual(health_pb2.HealthCheckResponse.SERVICE_UNKNOWN, @@ -177,8 +176,8 @@ class HealthServicerTest(unittest.TestCase): self._servicer.set(_WATCH_SERVICE, health_pb2.HealthCheckResponse.SERVING) - response1 = response_queue1.get(timeout=_QUEUE_TIMEOUT_S) - response2 = response_queue2.get(timeout=_QUEUE_TIMEOUT_S) + response1 = response_queue1.get(timeout=test_constants.SHORT_TIMEOUT) + response2 = response_queue2.get(timeout=test_constants.SHORT_TIMEOUT) self.assertEqual(health_pb2.HealthCheckResponse.SERVING, response1.status) self.assertEqual(health_pb2.HealthCheckResponse.SERVING, @@ -199,7 +198,7 @@ class HealthServicerTest(unittest.TestCase): target=_consume_responses, args=(rendezvous, response_queue)) thread.start() - response = response_queue.get(timeout=_QUEUE_TIMEOUT_S) + response = response_queue.get(timeout=test_constants.SHORT_TIMEOUT) self.assertEqual(health_pb2.HealthCheckResponse.SERVICE_UNKNOWN, response.status) -- cgit v1.2.3