Debian Codegraph @

unittest/gunit/libmysqlgcs/xcom/gcs_xcom_network_provider-t.cc

raw symbols SCIP
1 /* Copyright (c) 2021, 2026, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24 #include "unittest/gunit/libmysqlgcs/include/gcs_base_test.h"
25
26 #include "plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/network/xcom_network_provider.h"
27
28 namespace gcs_xcom_networkprovidertest {
29 class XComNetworkProviderTest : public GcsBaseTest {
30 protected:
31 XComNetworkProviderTest() {}
32
33 virtual void SetUp() {}
34
35 virtual void TearDown() {}
36 };
37
38 TEST_F(XComNetworkProviderTest, StartAndStopTestMissingPort) {
39 Xcom_network_provider net_provider;
40
41 ASSERT_TRUE(net_provider.start().first);
42 net_provider.stop();
43 }
44
45 TEST_F(XComNetworkProviderTest, StartAndStopTest) {
46 Xcom_network_provider net_provider;
47 Network_configuration_parameters params;
48 params.port = 12345;
49 net_provider.configure(params);
50
51 ASSERT_FALSE(net_provider.start().first);
52
53 // Make sure that the first one has started correctly
54 My_xp_util::sleep_seconds(5);
55
56 net_provider.stop();
57 }
58
59 #ifndef _WIN32 // Windows is sensitive to successive binds operations.
60 // To avoid adding big sleeps to the test, we will just skip
61 // them as a whole.
62 TEST_F(XComNetworkProviderTest, StartAgainAndStopTest) {
63 Xcom_network_provider net_provider;
64 Network_configuration_parameters params;
65 params.port = 12345;
66 net_provider.configure(params);
67
68 ASSERT_FALSE(net_provider.start().first);
69
70 // Make sure that the first one has started correctly
71 My_xp_util::sleep_seconds(5);
72
73 ASSERT_TRUE(net_provider.start().first);
74
75 net_provider.stop();
76 }
77
78 TEST_F(XComNetworkProviderTest, StartAndStopTestWithError) {
79 Xcom_network_provider net_provider1, net_provider2;
80 Network_configuration_parameters params;
81 params.port = 12345;
82 net_provider1.configure(params);
83 net_provider2.configure(params);
84
85 ASSERT_FALSE(net_provider1.start().first);
86
87 // Make sure that the first one has started correctly
88 My_xp_util::sleep_seconds(5);
89
90 ASSERT_TRUE(net_provider2.start().first);
91
92 net_provider1.stop();
93 }
94 #endif
95
96 TEST_F(XComNetworkProviderTest, CreateConnectionToSelfTest) {
97 Xcom_network_provider net_provider;
98 Network_configuration_parameters params;
99 params.port = 12345;
100 net_provider.configure(params);
101
102 ASSERT_FALSE(net_provider.start().first);
103
104 // Make sure that it has started correctly
105 My_xp_util::sleep_seconds(5);
106
107 auto new_connection =
108 net_provider.open_connection("localhost", 12345, {"", "", false});
109
110 ASSERT_TRUE(new_connection.get() != nullptr);
111
112 int close_connection_retval = net_provider.close_connection(*new_connection);
113
114 ASSERT_EQ(0, close_connection_retval);
115
116 net_provider.stop();
117 }
118
119 } // namespace gcs_xcom_networkprovidertest