Skip to content

Commit 779d9c3

Browse files
committed
Updating http_client outside_ssl_json test to not fail due to timeouts.
1 parent 1c2cf7b commit 779d9c3

File tree

1 file changed

+44
-41
lines changed

1 file changed

+44
-41
lines changed

Release/tests/functional/http/client/outside_tests.cpp

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -232,59 +232,62 @@ TEST_FIXTURE(uri_address, outside_ssl_json)
232232
// Send request
233233
web::http::client::http_client playlistClient(playlistUri.to_uri());
234234

235-
// Retry up to 4 times.
236-
for (int i = 0; i < 4; ++i)
235+
handle_timeout([]
237236
{
238-
try
237+
// Retry up to 4 times.
238+
for (int i = 0; i < 4; ++i)
239239
{
240-
playlistClient.request(methods::GET).then([=](http_response playlistResponse) -> pplx::task < json::value >
241-
{
242-
return playlistResponse.extract_json();
243-
}).then([=](json::value v)
240+
try
244241
{
245-
int count = 0;
246-
auto& obj = v.as_object();
242+
playlistClient.request(methods::GET).then([=](http_response playlistResponse) -> pplx::task < json::value >
243+
{
244+
return playlistResponse.extract_json();
245+
}).then([=](json::value v)
246+
{
247+
int count = 0;
248+
auto& obj = v.as_object();
247249

248-
VERIFY_ARE_NOT_EQUAL(obj.find(U("pageInfo")), obj.end());
249-
VERIFY_ARE_NOT_EQUAL(obj.find(U("items")), obj.end());
250+
VERIFY_ARE_NOT_EQUAL(obj.find(U("pageInfo")), obj.end());
251+
VERIFY_ARE_NOT_EQUAL(obj.find(U("items")), obj.end());
250252

251-
auto& items = obj[U("items")];
253+
auto& items = obj[U("items")];
252254

253-
for (auto iter = items.as_array().cbegin(); iter != items.as_array().cend(); ++iter)
254-
{
255-
const auto& item = *iter;
256-
auto iSnippet = item.as_object().find(U("snippet"));
257-
if (iSnippet == item.as_object().end())
255+
for (auto iter = items.as_array().cbegin(); iter != items.as_array().cend(); ++iter)
258256
{
259-
throw std::runtime_error("snippet key not found");
257+
const auto& item = *iter;
258+
auto iSnippet = item.as_object().find(U("snippet"));
259+
if (iSnippet == item.as_object().end())
260+
{
261+
throw std::runtime_error("snippet key not found");
262+
}
263+
auto iTitle = iSnippet->second.as_object().find(U("title"));
264+
if (iTitle == iSnippet->second.as_object().end())
265+
{
266+
throw std::runtime_error("title key not found");
267+
}
268+
auto name = iTitle->second.serialize();
269+
count++;
260270
}
261-
auto iTitle = iSnippet->second.as_object().find(U("title"));
262-
if (iTitle == iSnippet->second.as_object().end())
263-
{
264-
throw std::runtime_error("title key not found");
265-
}
266-
auto name = iTitle->second.serialize();
267-
count++;
268-
}
269-
VERIFY_ARE_EQUAL(3, count); // Update this accordingly, if the number of items changes
270-
}).wait();
271-
break;
272-
}
273-
catch (web::http::http_exception const& e)
274-
{
275-
#if defined(_MSC_VER) && !defined(__cplusplus_winrt)
276-
if (e.error_code().value() != API_QUERY_DATA_AVAILABLE || i == 3)
277-
{
278-
// If we didn't get a "connection broken" error (or we are on the last retry), rethrow it
279-
throw;
271+
VERIFY_ARE_EQUAL(3, count); // Update this accordingly, if the number of items changes
272+
}).wait();
273+
break;
280274
}
275+
catch (web::http::http_exception const& e)
276+
{
277+
#if defined(_MSC_VER) && !defined(__cplusplus_winrt)
278+
if (e.error_code().value() != API_QUERY_DATA_AVAILABLE || i == 3)
279+
{
280+
// If we didn't get a "connection broken" error (or we are on the last retry), rethrow it
281+
throw;
282+
}
281283
#else
282-
CASABLANCA_UNREFERENCED_PARAMETER(e);
283-
throw;
284+
CASABLANCA_UNREFERENCED_PARAMETER(e);
285+
throw;
284286
#endif
285-
os_utilities::sleep(1000);
287+
os_utilities::sleep(1000);
288+
}
286289
}
287-
}
290+
});
288291
}
289292

290293
} // SUITE(outside_tests)

0 commit comments

Comments
 (0)