Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. TEST_P(CatalogClientTest, CancelPendingRequestsCatalog) {
  2. olp::client::HRN hrn(GetTestCatalog());
  3. testing::InSequence s;
  4.  
  5. auto catalog_client = std::make_unique<CatalogClient>(hrn, settings_);
  6. auto catalog_request = CatalogRequest().WithFetchOption(OnlineOnly);
  7. auto version_request = CatalogVersionRequest().WithFetchOption(OnlineOnly);
  8.  
  9. // Make a few requests
  10. auto wait_for_cancel = std::make_shared<std::promise<void>>();
  11. auto pause_for_cancel = std::make_shared<std::promise<void>>();
  12.  
  13. {
  14. olp::http::RequestId request_id;
  15. NetworkCallback send_mock;
  16. CancelCallback cancel_mock;
  17.  
  18. std::tie(request_id, send_mock, cancel_mock) =
  19. GenerateNetworkMockActions(wait_for_cancel, pause_for_cancel,
  20. {200, HTTP_RESPONSE_LOOKUP_CONFIG});
  21.  
  22. EXPECT_CALL(*network_mock_,
  23. Send(IsGetRequest(URL_LOOKUP_CONFIG), _, _, _, _))
  24. .Times(1)
  25. .WillOnce(testing::Invoke(std::move(send_mock)));
  26.  
  27. EXPECT_CALL(*network_mock_, Cancel(request_id))
  28. .WillOnce(testing::Invoke(std::move(cancel_mock)));
  29. }
  30.  
  31. auto catalog_future = catalog_client->GetCatalog(catalog_request);
  32. auto version_future = catalog_client->GetLatestVersion(version_request);
  33. wait_for_cancel->get_future().get();
  34.  
  35. // Cancel them all
  36. catalog_client->CancelPendingRequests();
  37. pause_for_cancel->set_value();
  38.  
  39. // Verify they are all cancelled
  40. CatalogResponse catalog_response = catalog_future.GetFuture().get();
  41.  
  42. ASSERT_FALSE(catalog_response.IsSuccessful())
  43. << ApiErrorToString(catalog_response.GetError());
  44.  
  45. ASSERT_EQ(static_cast<int>(olp::http::ErrorCode::CANCELLED_ERROR),
  46. catalog_response.GetError().GetHttpStatusCode());
  47. ASSERT_EQ(olp::client::ErrorCode::Cancelled,
  48. catalog_response.GetError().GetErrorCode());
  49.  
  50. CatalogVersionResponse version_response = version_future.GetFuture().get();
  51.  
  52. ASSERT_FALSE(version_response.IsSuccessful())
  53. << ApiErrorToString(version_response.GetError());
  54.  
  55. ASSERT_EQ(static_cast<int>(olp::http::ErrorCode::CANCELLED_ERROR),
  56. version_response.GetError().GetHttpStatusCode());
  57. ASSERT_EQ(olp::client::ErrorCode::Cancelled,
  58. version_response.GetError().GetErrorCode());
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement