Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TEST_P(CatalogClientTest, CancelPendingRequestsCatalog) {
- olp::client::HRN hrn(GetTestCatalog());
- testing::InSequence s;
- auto catalog_client = std::make_unique<CatalogClient>(hrn, settings_);
- auto catalog_request = CatalogRequest().WithFetchOption(OnlineOnly);
- auto version_request = CatalogVersionRequest().WithFetchOption(OnlineOnly);
- // Make a few requests
- auto wait_for_cancel = std::make_shared<std::promise<void>>();
- auto pause_for_cancel = std::make_shared<std::promise<void>>();
- {
- olp::http::RequestId request_id;
- NetworkCallback send_mock;
- CancelCallback cancel_mock;
- std::tie(request_id, send_mock, cancel_mock) =
- GenerateNetworkMockActions(wait_for_cancel, pause_for_cancel,
- {200, HTTP_RESPONSE_LOOKUP_CONFIG});
- EXPECT_CALL(*network_mock_,
- Send(IsGetRequest(URL_LOOKUP_CONFIG), _, _, _, _))
- .Times(1)
- .WillOnce(testing::Invoke(std::move(send_mock)));
- EXPECT_CALL(*network_mock_, Cancel(request_id))
- .WillOnce(testing::Invoke(std::move(cancel_mock)));
- }
- auto catalog_future = catalog_client->GetCatalog(catalog_request);
- auto version_future = catalog_client->GetLatestVersion(version_request);
- wait_for_cancel->get_future().get();
- // Cancel them all
- catalog_client->CancelPendingRequests();
- pause_for_cancel->set_value();
- // Verify they are all cancelled
- CatalogResponse catalog_response = catalog_future.GetFuture().get();
- ASSERT_FALSE(catalog_response.IsSuccessful())
- << ApiErrorToString(catalog_response.GetError());
- ASSERT_EQ(static_cast<int>(olp::http::ErrorCode::CANCELLED_ERROR),
- catalog_response.GetError().GetHttpStatusCode());
- ASSERT_EQ(olp::client::ErrorCode::Cancelled,
- catalog_response.GetError().GetErrorCode());
- CatalogVersionResponse version_response = version_future.GetFuture().get();
- ASSERT_FALSE(version_response.IsSuccessful())
- << ApiErrorToString(version_response.GetError());
- ASSERT_EQ(static_cast<int>(olp::http::ErrorCode::CANCELLED_ERROR),
- version_response.GetError().GetHttpStatusCode());
- ASSERT_EQ(olp::client::ErrorCode::Cancelled,
- version_response.GetError().GetErrorCode());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement