Skip to content

Commit

Permalink
other_test
Browse files Browse the repository at this point in the history
  • Loading branch information
chamini2 committed Sep 23, 2024
1 parent 9401853 commit bdcb316
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,8 @@ def test_server_single_use_submit(
stub: definitions.IsolateStub,
monkeypatch: Any,
) -> None:
import time

inherit_from_local(monkeypatch)

request = definitions.SubmitRequest(function=prepare_request(myserver))
Expand All @@ -773,8 +775,52 @@ def test_server_single_use_submit(
assert exc_info.value.code() == grpc.StatusCode.RESOURCE_EXHAUSTED

stub.Cancel(definitions.CancelRequest(task_id=task_id))
time.sleep(1)

with pytest.raises(grpc.RpcError) as exc_info:
stub.List(definitions.ListRequest())

# Server should be shutting down
assert exc_info.value.code() == grpc.StatusCode.UNAVAILABLE


@pytest.mark.parametrize(
"interceptors",
[
[SingleTaskInterceptor()],
],
)
def test_server_single_use_run(
tmp_path: Path,
interceptors: List[ServerBoundInterceptor],
monkeypatch: Any,
) -> None:
import time

inherit_from_local(monkeypatch)

with make_server(tmp_path, interceptors) as stubs:
stubs.isolate_stub.Run(prepare_request(myserver))
time.sleep(1)

# Now try to Submit again
with pytest.raises(grpc.RpcError) as exc_info:
stubs.isolate_stub.Submit(prepare_request(myserver))

assert exc_info.value.code() == grpc.StatusCode.UNAVAILABLE

# And try to Run a task
with pytest.raises(grpc.RpcError) as exc_info:
run_request(stubs.isolate_stub, prepare_request(myserver))

assert exc_info.value.code() == grpc.StatusCode.UNAVAILABLE

with make_server(tmp_path, interceptors) as stubs:
stubs.isolate_stub.Run(prepare_request(myserver))
time.sleep(1)

# Now try to Submit again
with pytest.raises(grpc.RpcError) as exc_info:
stubs.isolate_stub.List(definitions.ListRequest())

assert exc_info.value.code() == grpc.StatusCode.UNAVAILABLE

0 comments on commit bdcb316

Please sign in to comment.