|
|
|
@ -15,6 +15,8 @@ |
|
|
|
|
|
|
|
|
|
import grpc |
|
|
|
|
|
|
|
|
|
import threading |
|
|
|
|
|
|
|
|
|
# requests_pb2 is a semantic dependency of this module. |
|
|
|
|
from tests.testing import _application_common |
|
|
|
|
from tests.testing.proto import requests_pb2 # pylint: disable=unused-import |
|
|
|
@ -25,9 +27,26 @@ from tests.testing.proto import services_pb2_grpc |
|
|
|
|
class FirstServiceServicer(services_pb2_grpc.FirstServiceServicer): |
|
|
|
|
"""Services RPCs.""" |
|
|
|
|
|
|
|
|
|
def __init__(self): |
|
|
|
|
self._abort_lock = threading.RLock() |
|
|
|
|
self._abort_response = _application_common.ABORT_NO_STATUS_RESPONSE |
|
|
|
|
|
|
|
|
|
def UnUn(self, request, context): |
|
|
|
|
if _application_common.UNARY_UNARY_REQUEST == request: |
|
|
|
|
if request == _application_common.UNARY_UNARY_REQUEST: |
|
|
|
|
return _application_common.UNARY_UNARY_RESPONSE |
|
|
|
|
elif request == _application_common.ABORT_REQUEST: |
|
|
|
|
with self._abort_lock: |
|
|
|
|
try: |
|
|
|
|
context.abort(grpc.StatusCode.PERMISSION_DENIED, |
|
|
|
|
"Denying permission to test abort.") |
|
|
|
|
except Exception as e: # pylint: disable=broad-except |
|
|
|
|
self._abort_response = _application_common.ABORT_SUCCESS_RESPONSE |
|
|
|
|
else: |
|
|
|
|
self._abort_status = _application_common.ABORT_FAILURE_RESPONSE |
|
|
|
|
return None # NOTE: For the linter. |
|
|
|
|
elif request == _application_common.ABORT_SUCCESS_QUERY: |
|
|
|
|
with self._abort_lock: |
|
|
|
|
return self._abort_response |
|
|
|
|
else: |
|
|
|
|
context.set_code(grpc.StatusCode.INVALID_ARGUMENT) |
|
|
|
|
context.set_details('Something is wrong with your request!') |
|
|
|
|