Skip to content

Commit f391e11

Browse files
committed
Updating data_download_exception test case to gracefully handle timeouts.
1 parent f48c41a commit f391e11

File tree

6 files changed

+75
-87
lines changed

6 files changed

+75
-87
lines changed

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

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -50,36 +50,6 @@ using namespace tests::functional::http::utilities;
5050

5151
namespace tests { namespace functional { namespace http { namespace client {
5252

53-
// helper function to check if failure is due to timeout.
54-
bool is_timeout(const std::string &msg)
55-
{
56-
if (msg.find("The operation timed out") != std::string::npos /* WinHTTP */ ||
57-
msg.find("The operation was timed out") != std::string::npos /* IXmlHttpRequest2 */)
58-
{
59-
return true;
60-
}
61-
return false;
62-
}
63-
64-
template <typename Func>
65-
void handle_timeout(const Func &f)
66-
{
67-
try
68-
{
69-
f();
70-
}
71-
catch (const http_exception &e)
72-
{
73-
if (is_timeout(e.what()))
74-
{
75-
// Since this test depends on an outside server sometimes it sporadically can fail due to timeouts
76-
// especially on our build machines.
77-
return;
78-
}
79-
throw;
80-
}
81-
}
82-
8353
SUITE(authentication_tests)
8454
{
8555

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

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -45,36 +45,6 @@ namespace tests { namespace functional { namespace http { namespace client {
4545
SUITE(outside_tests)
4646
{
4747

48-
// helper function to check if failure is due to timeout.
49-
bool is_timeout(const std::string &msg)
50-
{
51-
if (msg.find("The operation timed out") != std::string::npos /* WinHTTP */ ||
52-
msg.find("The operation was timed out") != std::string::npos /* IXmlHttpRequest2 */)
53-
{
54-
return true;
55-
}
56-
return false;
57-
}
58-
59-
template <typename Func>
60-
void handle_timeout(const Func &f)
61-
{
62-
try
63-
{
64-
f();
65-
}
66-
catch (const http_exception &e)
67-
{
68-
if (is_timeout(e.what()))
69-
{
70-
// Since this test depends on an outside server sometimes it sporadically can fail due to timeouts
71-
// especially on our build machines.
72-
return;
73-
}
74-
throw;
75-
}
76-
}
77-
7848
TEST_FIXTURE(uri_address, outside_cnn_dot_com)
7949
{
8050
handle_timeout([]

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

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -245,20 +245,20 @@ TEST_FIXTURE(uri_address, set_progress_handler_open_failure)
245245
const size_t repeats = 5500;
246246
for (size_t i = 0; i < repeats; ++i)
247247
data.append(U("abcdefghihklmnopqrstuvwxyz"));
248-
248+
249249
utility::size64_t upsize = 4711u, downsize = 4711u;
250250
int calls = 0;
251251

252252
http_request msg(mtd);
253253
// We should never see this handler called.
254254
msg.set_progress_handler(
255-
[&](message_direction::direction direction, utility::size64_t so_far)
256-
{
255+
[&](message_direction::direction direction, utility::size64_t so_far)
256+
{
257257
calls += 1;
258-
if (direction == message_direction::upload)
259-
upsize = so_far;
260-
else
261-
downsize = so_far;
258+
if (direction == message_direction::upload)
259+
upsize = so_far;
260+
else
261+
downsize = so_far;
262262
});
263263

264264
msg.set_body(data);
@@ -406,12 +406,6 @@ TEST_FIXTURE(uri_address, data_download_exception)
406406
int numCalls = 0;
407407
msg.set_progress_handler([&](message_direction::direction, utility::size64_t)
408408
{
409-
// TODO stgates - adding some debugging information to help with hard to reproduce
410-
// sporadic failure.
411-
#if (defined(_MSC_VER) && (_MSC_VER >= 1800))
412-
printf("In progress handler, numCalls:%i\n", numCalls);
413-
#endif
414-
415409
if(++numCalls == 2)
416410
{
417411
// 2rd is for data download
@@ -421,22 +415,15 @@ TEST_FIXTURE(uri_address, data_download_exception)
421415

422416
try
423417
{
424-
client.request(msg).get().content_ready().get();
425-
}
426-
catch (http_exception const &e)
427-
{
428-
printf("http_exception:%s\n", e.what());
429-
VERIFY_IS_TRUE(false);
418+
handle_timeout([&]
419+
{
420+
client.request(msg).get().content_ready().get();
421+
});
430422
}
431423
catch (std::invalid_argument const &)
432424
{
433-
printf("std::invalid_argument\n");
434-
}
435-
catch (std::exception const &e)
436-
{
437-
printf("std::exception:%s\n", e.what());
425+
// Expected.
438426
}
439-
//VERIFY_THROWS(client.request(msg).get().content_ready().get(), std::invalid_argument);
440427
}
441428

442429
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/***
22
* ==++==
33
*
4-
* Copyright (c) Microsoft Corporation. All rights reserved.
4+
* Copyright (c) Microsoft Corporation. All rights reserved.
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
77
* You may obtain a copy of the License at
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

Release/tests/functional/http/client/stdafx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@
3434
#include "http_test_utilities.h"
3535
#include "unittestpp.h"
3636
#include "os_utilities.h"
37+
#include "timeout_handler.h"
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/***
2+
* ==++==
3+
*
4+
* Copyright (c) Microsoft Corporation. All rights reserved.
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* ==--==
17+
* =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
18+
*
19+
* Simple utility for handling timeouts with http client test cases.
20+
*
21+
* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
22+
****/
23+
24+
#pragma once
25+
26+
#include "cpprest/http_client.h"
27+
28+
namespace tests { namespace functional { namespace http { namespace client {
29+
30+
// helper function to check if failure is due to timeout.
31+
bool is_timeout(const std::string &msg)
32+
{
33+
if (msg.find("The operation timed out") != std::string::npos /* WinHTTP */ ||
34+
msg.find("The operation was timed out") != std::string::npos /* IXmlHttpRequest2 */)
35+
{
36+
return true;
37+
}
38+
return false;
39+
}
40+
41+
template <typename Func>
42+
void handle_timeout(const Func &f)
43+
{
44+
try
45+
{
46+
f();
47+
}
48+
catch (const web::http::http_exception &e)
49+
{
50+
if (is_timeout(e.what()))
51+
{
52+
// Since this test depends on an outside server sometimes it sporadically can fail due to timeouts
53+
// especially on our build machines.
54+
return;
55+
}
56+
throw;
57+
}
58+
}
59+
60+
}}}}

0 commit comments

Comments
 (0)