25
25
26
26
#include " stdafx.h"
27
27
#include " cpprest/rawptrstream.h"
28
+ #include " os_utilities.h"
28
29
#include < stdexcept>
29
30
30
31
using namespace web ;
@@ -33,6 +34,7 @@ using namespace concurrency;
33
34
using namespace web ::http;
34
35
using namespace web ::http::client;
35
36
37
+ using namespace tests ::common::utilities;
36
38
using namespace tests ::functional::http::utilities;
37
39
38
40
namespace tests { namespace functional { namespace http { namespace client {
@@ -163,37 +165,53 @@ TEST_FIXTURE(uri_address, outside_ssl_json)
163
165
164
166
// Send request
165
167
web::http::client::http_client playlistClient (playlistUri.to_uri ());
166
- playlistClient.request (methods::GET).then ([=](http_response playlistResponse) -> pplx::task<json::value>
167
- {
168
- return playlistResponse.extract_json ();
169
- }).then ([=](json::value v)
170
- {
171
- int count = 0 ;
172
- auto & obj = v.as_object ();
173
-
174
- VERIFY_ARE_NOT_EQUAL (obj.find (U (" pageInfo" )), obj.end ());
175
- VERIFY_ARE_NOT_EQUAL (obj.find (U (" items" )), obj.end ());
176
-
177
- auto & items = obj[U (" items" )];
178
168
179
- for (auto iter = items.as_array ().cbegin (); iter != items.as_array ().cend (); ++iter)
169
+ // Retry up to 4 times.
170
+ for (int i = 0 ; i < 4 ; ++i)
171
+ {
172
+ try
180
173
{
181
- const auto & i = *iter;
182
- auto iSnippet = i.as_object ().find (U (" snippet" ));
183
- if (iSnippet == i.as_object ().end ())
174
+ playlistClient.request (methods::GET).then ([=](http_response playlistResponse) -> pplx::task < json::value >
184
175
{
185
- throw std::runtime_error (" snippet key not found" );
186
- }
187
- auto iTitle = iSnippet->second .as_object ().find (U (" title" ));
188
- if (iTitle == iSnippet->second .as_object ().end ())
176
+ return playlistResponse.extract_json ();
177
+ }).then ([=](json::value v)
189
178
{
190
- throw std::runtime_error (" title key not found" );
191
- }
192
- auto name = iTitle->second .serialize ();
193
- count++;
179
+ int count = 0 ;
180
+ auto & obj = v.as_object ();
181
+
182
+ VERIFY_ARE_NOT_EQUAL (obj.find (U (" pageInfo" )), obj.end ());
183
+ VERIFY_ARE_NOT_EQUAL (obj.find (U (" items" )), obj.end ());
184
+
185
+ auto & items = obj[U (" items" )];
186
+
187
+ for (auto iter = items.as_array ().cbegin (); iter != items.as_array ().cend (); ++iter)
188
+ {
189
+ const auto & i = *iter;
190
+ auto iSnippet = i.as_object ().find (U (" snippet" ));
191
+ if (iSnippet == i.as_object ().end ())
192
+ {
193
+ throw std::runtime_error (" snippet key not found" );
194
+ }
195
+ auto iTitle = iSnippet->second .as_object ().find (U (" title" ));
196
+ if (iTitle == iSnippet->second .as_object ().end ())
197
+ {
198
+ throw std::runtime_error (" title key not found" );
199
+ }
200
+ auto name = iTitle->second .serialize ();
201
+ count++;
202
+ }
203
+ VERIFY_ARE_EQUAL (3 , count); // Update this accordingly, if the number of items changes
204
+ }).wait ();
205
+ break ;
194
206
}
195
- VERIFY_ARE_EQUAL (3 , count); // Update this accordingly, if the number of items changes
196
- }).wait ();
207
+ catch (web::http::http_exception const & e)
208
+ {
209
+ if (e.what () != " Error in: WinHttpQueryDataAvailable" || i == 3 )
210
+ // If we didn't get a "connection broken" error (or we are on the last retry), rethrow it
211
+ throw ;
212
+ os_utilities::sleep (1000 );
213
+ }
214
+ }
197
215
}
198
216
199
217
} // SUITE(outside_tests)
0 commit comments