[glibmm/glibmm-2-64] tests/giomm_tls_client: Skip test, if socket can't be connected
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm/glibmm-2-64] tests/giomm_tls_client: Skip test, if socket can't be connected
- Date: Mon, 25 Jan 2021 12:58:43 +0000 (UTC)
commit 782f865d13972e5b66226dced87b547f171e313b
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date: Mon Jan 25 13:56:35 2021 +0100
tests/giomm_tls_client: Skip test, if socket can't be connected
This test sometimes fails in CI runs, probably for a reason that's out
of glibmm's control.
Gio::Socket::create() can throw an exception. Put it in a try block.
See #84
tests/giomm_tls_client/main.cc | 29 ++++++++++++++++++++++-------
1 file changed, 22 insertions(+), 7 deletions(-)
---
diff --git a/tests/giomm_tls_client/main.cc b/tests/giomm_tls_client/main.cc
index 5f133253..e87437fd 100644
--- a/tests/giomm_tls_client/main.cc
+++ b/tests/giomm_tls_client/main.cc
@@ -76,20 +76,35 @@ main(int, char**)
std::cout << "First address of test host is " << first_inet_address->to_string() << "."
<< std::endl;
- auto socket = Gio::Socket::create(
- first_inet_address->get_family(), Gio::SOCKET_TYPE_STREAM, Gio::SOCKET_PROTOCOL_TCP);
-
- auto address = Gio::InetSocketAddress::create(first_inet_address, 443);
+ Glib::RefPtr<Gio::Socket> socket;
+ try
+ {
+ socket = Gio::Socket::create(
+ first_inet_address->get_family(), Gio::SOCKET_TYPE_STREAM, Gio::SOCKET_PROTOCOL_TCP);
+ }
+ catch (const Gio::Error& ex)
+ {
+ std::cout << "Could not create socket. Exception: " << ex.what() << std::endl;
+ return EXIT_FAILURE;
+ }
+ Glib::RefPtr<Gio::InetSocketAddress> address;
try
{
+ address = Gio::InetSocketAddress::create(first_inet_address, 443);
socket->connect(address);
}
catch (const Gio::Error& ex)
{
- std::cout << "Could not connect socket to " << address->get_address()->to_string() << ":"
- << address->get_port() << ". Exception: " << ex.what() << std::endl;
- return EXIT_FAILURE;
+ if (!address)
+ std::cout << "Could not create socket address. Exception: " << ex.what() << std::endl;
+ else
+ std::cout << "Could not connect socket to " << address->get_address()->to_string() << ":"
+ << address->get_port() << ". Exception: " << ex.what() << std::endl;
+
+ // When running CI (continuous integration), socket->connect(address)
+ // sometimes fails. Skip this test.
+ return 77;
}
if (!socket->is_connected())
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]