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.
@@ -44,7 +44,7 @@ void auth_helper(test_websocket_server& server, const utility::string_t &usernam
4444 server.set_http_handler ([username, password](test_http_request request)
4545 {
4646 test_http_response resp;
47- if (request->username ().empty ()) // No credentials -> challenge the request
47+ if (request->username ().empty ()) // No credentials -> challenge the request
4848 {
4949 resp.set_status_code (401 ); // Unauthorized.
5050 resp.set_realm (" My Realm" );
@@ -86,6 +86,19 @@ TEST_FIXTURE(uri_address, auth_with_credentials, "Ignore", "245")
8686}
8787#endif
8888
89+ // helper function to check if failure is due to timeout.
90+ bool is_timeout (const std::string &msg)
91+ {
92+ if (msg.find (" set_fail_handler" ) != std::string::npos)
93+ {
94+ if (msg.find (" TLS handshake timed out" ) != std::string::npos || msg.find (" Timer Expired" ) != std::string::npos)
95+ {
96+ return true ;
97+ }
98+ }
99+ return false ;
100+ }
101+
89102TEST (ssl_test)
90103{
91104 websocket_client client;
@@ -112,15 +125,11 @@ TEST(ssl_test)
112125 }
113126 catch (const websocket_exception &e)
114127 {
115- const auto msg = std::string (e.what ());
116- if (msg.find (" set_fail_handler" ) != std::string::npos)
128+ if (is_timeout (e.what ())
117129 {
118- if (msg.find (" TLS handshake timed out" ) != std::string::npos || msg.find (" Timer Expired" ) != std::string::npos)
119- {
120- // Since this test depends on an outside server sometimes it sporadically can fail due to timeouts
121- // especially on our build machines.
122- return ;
123- }
130+ // Since this test depends on an outside server sometimes it sporadically can fail due to timeouts
131+ // especially on our build machines.
132+ return ;
124133 }
125134 throw ;
126135 }
@@ -139,6 +148,12 @@ void handshake_error_test_impl(const ::utility::string_t &host)
139148 }
140149 catch (const websocket_exception &e)
141150 {
151+ if (is_timeout (e.what ()))
152+ {
153+ // Since this test depends on an outside server sometimes it sporadically can fail due to timeouts
154+ // especially on our build machines.
155+ return ;
156+ }
142157 VERIFY_ARE_EQUAL (" TLS handshake failed" , e.error_code ().message ());
143158 }
144159}
0 commit comments