Skip to content

Commit

Permalink
Add testing for cancelling a request after release
Browse files Browse the repository at this point in the history
  • Loading branch information
Tabrizian committed Aug 31, 2023
1 parent 8bb1c84 commit 83c0077
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/test/request_cancellation_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ class RequestCancellationTest : public ::testing::Test {

TRITONSERVER_Server* RequestCancellationTest::server_ = nullptr;

void
ReleaseCallback(
struct TRITONSERVER_InferenceRequest* request, const uint32_t flags,
void* userp)
{
// no-op
}

TEST_F(RequestCancellationTest, Cancellation)
{
Expand Down Expand Up @@ -138,6 +145,50 @@ TEST_F(RequestCancellationTest, Cancellation)
FAIL_TEST_IF_ERR(TRITONSERVER_InferenceRequestDelete(request));
}

TEST_F(RequestCancellationTest, CancellationAfterRelease)
{
TRITONSERVER_InferenceRequest* request;
FAIL_TEST_IF_ERR(
TRITONSERVER_InferenceRequestNew(&request, server_, "model", 1));
FAIL_TEST_IF_ERR(TRITONSERVER_InferenceRequestSetResponseCallback(
request, nullptr, nullptr, nullptr, nullptr));
FAIL_TEST_IF_ERR(TRITONSERVER_InferenceRequestSetReleaseCallback(
request, ReleaseCallback, nullptr));
TRITONBACKEND_Request* backend_request =
reinterpret_cast<TRITONBACKEND_Request*>(request);
TRITONBACKEND_ResponseFactory* response_factory;
FAIL_TEST_IF_ERR(
TRITONBACKEND_ResponseFactoryNew(&response_factory, backend_request));
FAIL_TEST_IF_ERR(TRITONBACKEND_RequestRelease(
backend_request, TRITONSERVER_REQUEST_RELEASE_ALL));

bool is_cancelled = true;
FAIL_TEST_IF_ERR(
TRITONSERVER_InferenceRequestIsCancelled(request, &is_cancelled));
ASSERT_FALSE(is_cancelled);

is_cancelled = true;
FAIL_TEST_IF_ERR(TRITONBACKEND_ResponseFactoryIsCancelled(
response_factory, &is_cancelled));
ASSERT_FALSE(is_cancelled);

is_cancelled = false;
FAIL_TEST_IF_ERR(TRITONSERVER_InferenceRequestCancel(request));

is_cancelled = false;
FAIL_TEST_IF_ERR(
TRITONSERVER_InferenceRequestIsCancelled(request, &is_cancelled));
ASSERT_TRUE(is_cancelled);

is_cancelled = false;
FAIL_TEST_IF_ERR(TRITONBACKEND_ResponseFactoryIsCancelled(
response_factory, &is_cancelled));
ASSERT_TRUE(is_cancelled);

FAIL_TEST_IF_ERR(TRITONBACKEND_ResponseFactoryDelete(response_factory));
FAIL_TEST_IF_ERR(TRITONSERVER_InferenceRequestDelete(request));
}

int
main(int argc, char** argv)
{
Expand Down

0 comments on commit 83c0077

Please sign in to comment.