... |
... |
@@ -24,6 +24,7 @@ import grpc |
24
|
24
|
from grpc._server import _Context
|
25
|
25
|
import pytest
|
26
|
26
|
|
|
27
|
+from buildgrid._enums import OperationStage
|
27
|
28
|
from buildgrid._exceptions import InvalidArgumentError
|
28
|
29
|
from buildgrid._protos.build.bazel.remote.execution.v2 import remote_execution_pb2
|
29
|
30
|
from buildgrid._protos.google.longrunning import operations_pb2
|
... |
... |
@@ -236,12 +237,24 @@ def test_delete_operation_fail(instance, context): |
236
|
237
|
context.set_code.assert_called_once_with(grpc.StatusCode.INVALID_ARGUMENT)
|
237
|
238
|
|
238
|
239
|
|
239
|
|
-def test_cancel_operation(instance, context):
|
|
240
|
+def test_cancel_operation(instance, controller, execute_request, context):
|
|
241
|
+ response_execute = controller.execution_instance.execute(execute_request.action_digest,
|
|
242
|
+ execute_request.skip_cache_lookup)
|
|
243
|
+
|
240
|
244
|
request = operations_pb2.CancelOperationRequest()
|
241
|
|
- request.name = "{}/{}".format(instance_name, "runner")
|
|
245
|
+ request.name = "{}/{}".format(instance_name, response_execute.name)
|
|
246
|
+
|
242
|
247
|
instance.CancelOperation(request, context)
|
243
|
248
|
|
244
|
|
- context.set_code.assert_called_once_with(grpc.StatusCode.UNIMPLEMENTED)
|
|
249
|
+ request = operations_pb2.ListOperationsRequest(name=instance_name)
|
|
250
|
+ response = instance.ListOperations(request, context)
|
|
251
|
+
|
|
252
|
+ assert len(response.operations) is 1
|
|
253
|
+
|
|
254
|
+ for operation in response.operations:
|
|
255
|
+ operation_metadata = remote_execution_pb2.ExecuteOperationMetadata()
|
|
256
|
+ operation.metadata.Unpack(operation_metadata)
|
|
257
|
+ assert operation_metadata.stage == OperationStage.COMPLETED.value
|
245
|
258
|
|
246
|
259
|
|
247
|
260
|
def test_cancel_operation_blank(blank_instance, context):
|
... |
... |
@@ -249,7 +262,7 @@ def test_cancel_operation_blank(blank_instance, context): |
249
|
262
|
request.name = "runner"
|
250
|
263
|
blank_instance.CancelOperation(request, context)
|
251
|
264
|
|
252
|
|
- context.set_code.assert_called_once_with(grpc.StatusCode.UNIMPLEMENTED)
|
|
265
|
+ context.set_code.assert_called_once_with(grpc.StatusCode.INVALID_ARGUMENT)
|
253
|
266
|
|
254
|
267
|
|
255
|
268
|
def test_cancel_operation_instance_fail(instance, context):
|