Debian Codegraph @

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

raw symbols SCIP
1 /* Copyright (c) 2018, 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 "gcs_base_test.h"
25
26 #include <cstring>
27 #include <string>
28 #include <vector>
29 #include "app_data.h"
30 #include "get_synode_app_data.h"
31 #include "pax_msg.h"
32 #include "xcom_base.h"
33 #include "xcom_cache.h"
34 #include "xcom_memory.h"
35 #include "xcom_transport.h"
36
37 #include "plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/network/network_provider_manager.h"
38 #include "plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/network/xcom_network_provider.h"
39
40 namespace xcom_base_unittest {
41
42 class XcomBase : public GcsBaseTest {
43 protected:
44 XcomBase() {
45 ::init_cache();
46
47 auto &net_manager = Network_provider_manager::getInstance();
48
49 auto xcom_network_provider = std::make_shared<Xcom_network_provider>();
50 net_manager.add_network_provider(xcom_network_provider);
51 }
52 ~XcomBase() { ::deinit_cache(); }
53 };
54
55 TEST_F(XcomBase, XcomSendClientAppDataUpgradeScenario) {
56 app_data a;
57 std::string address("127.0.0.1:12345");
58
59 char const *names[]{address.c_str()};
60 node_address *na = new_node_address(1, names);
61
62 a.body.c_t = add_node_type;
63 a.body.app_u_u.nodes.node_list_len = 1;
64 a.body.app_u_u.nodes.node_list_val = na;
65
66 int result = 0;
67 result = are_we_allowed_to_upgrade_to_v6(&a);
68
69 ASSERT_EQ(result, 1);
70 delete_node_address(1, na);
71 }
72
73 TEST_F(XcomBase, XcomSendClientAppDataUpgradeScenarioV6) {
74 app_data a;
75 std::string address("[::1]:12345");
76
77 char const *names[]{address.c_str()};
78 node_address *na = new_node_address(1, names);
79
80 a.body.c_t = add_node_type;
81 a.body.app_u_u.nodes.node_list_len = 1;
82 a.body.app_u_u.nodes.node_list_val = na;
83
84 int result = 0;
85 result = are_we_allowed_to_upgrade_to_v6(&a);
86
87 ASSERT_EQ(result, 0);
88
89 delete_node_address(1, na);
90 }
91
92 TEST_F(XcomBase, XcomSendClientAppDataUpgradeScenarioMalformed) {
93 app_data a;
94 std::string address("::1]:12345");
95
96 char const *names[]{address.c_str()};
97 node_address *na = new_node_address(1, names);
98
99 a.body.c_t = add_node_type;
100 a.body.app_u_u.nodes.node_list_len = 1;
101 a.body.app_u_u.nodes.node_list_val = na;
102
103 int result = 0;
104 result = are_we_allowed_to_upgrade_to_v6(&a);
105
106 ASSERT_EQ(result, 0);
107
108 delete_node_address(1, na);
109 }
110
111 TEST_F(XcomBase, XcomNewClientEligibleDowngradeScenario) {
112 std::string address("127.0.0.1:12345");
113
114 char const *names[]{address.c_str()};
115 node_address *na = new_node_address(1, names);
116
117 site_def *sd = new_site_def();
118 init_site_def(1, na, sd);
119
120 xcom_proto incoming = x_1_4;
121 int result = is_new_node_eligible_for_ipv6(incoming, sd);
122
123 ASSERT_EQ(result, 0);
124
125 free_site_def(sd);
126 delete_node_address(1, na);
127 }
128
129 TEST_F(XcomBase, XcomNewClientEligibleDowngradeScenarioFail) {
130 std::string address("[::1]:12345");
131
132 char const *names[]{address.c_str()};
133 node_address *na = new_node_address(1, names);
134
135 site_def *sd = new_site_def();
136 init_site_def(1, na, sd);
137
138 xcom_proto incoming = x_1_4;
139 int result = is_new_node_eligible_for_ipv6(incoming, sd);
140
141 ASSERT_EQ(result, 1);
142
143 free_site_def(sd);
144 delete_node_address(1, na);
145 }
146
147 TEST_F(XcomBase, XcomNewClientEligibleDowngradeScenarioNullSiteDef) {
148 xcom_proto incoming = x_1_4;
149 int result = is_new_node_eligible_for_ipv6(incoming, nullptr);
150
151 ASSERT_EQ(result, 0);
152 }
153
154 TEST_F(XcomBase, XcomNewClientEligibleDowngradeScenarioVersionSame) {
155 xcom_proto incoming = my_xcom_version;
156 int result = is_new_node_eligible_for_ipv6(incoming, nullptr);
157
158 ASSERT_EQ(result, 0);
159 }
160
161 TEST_F(XcomBase, GetSynodeAppDataNotCached) {
162 synode_no synode;
163 synode.group_id = 12345;
164 synode.msgno = 0;
165 synode.node = 0;
166
167 synode_no_array synodes;
168 synodes.synode_no_array_len = 1;
169 synodes.synode_no_array_val = &synode;
170
171 synode_app_data_array result;
172 result.synode_app_data_array_len = 0;
173 result.synode_app_data_array_val = nullptr;
174
175 auto error_code = ::xcom_get_synode_app_data(&synodes, &result);
176 ASSERT_EQ(error_code, XCOM_GET_SYNODE_APP_DATA_NOT_CACHED);
177 }
178
179 TEST_F(XcomBase, GetSynodeAppDataNotDecided) {
180 synode_no synode;
181 synode.group_id = 12345;
182 synode.msgno = 0;
183 synode.node = 0;
184
185 synode_no_array synodes;
186 synodes.synode_no_array_len = 1;
187 synodes.synode_no_array_val = &synode;
188
189 synode_app_data_array result;
190 result.synode_app_data_array_len = 0;
191 result.synode_app_data_array_val = nullptr;
192
193 /* Add the synode to the cache, but it is undecided. */
194 get_cache(synode);
195
196 auto error_code = ::xcom_get_synode_app_data(&synodes, &result);
197 ASSERT_EQ(error_code, XCOM_GET_SYNODE_APP_DATA_NOT_DECIDED);
198 }
199
200 TEST_F(XcomBase, GetSynodeAppDataSuccessful) {
201 synode_no synode;
202 synode.group_id = 12345;
203 synode.msgno = 0;
204 synode.node = 0;
205
206 synode_no origin;
207 origin.group_id = 12345;
208 origin.msgno = 0;
209 origin.node = 1;
210
211 synode_no_array synodes;
212 synodes.synode_no_array_len = 1;
213 synodes.synode_no_array_val = &synode;
214
215 synode_app_data_array result;
216 result.synode_app_data_array_len = 0;
217 result.synode_app_data_array_val = nullptr;
218
219 /* Add the synode to the cache, and set it as decided. */
220 char const *const payload = "Message in a bottle";
221 app_data_ptr a = new_app_data();
222 a->unique_id = origin;
223 a->body.c_t = app_type;
224 a->body.app_u_u.data.data_len = std::strlen(payload) + 1;
225 a->body.app_u_u.data.data_val = const_cast<char *>(payload);
226
227 pax_msg *p = pax_msg_new_0(synode);
228 p->op = learn_op;
229 p->a = a;
230 p->refcnt = 1;
231
232 pax_machine *paxos = get_cache(synode);
233 paxos->learner.msg = p;
234
235 auto error_code = ::xcom_get_synode_app_data(&synodes, &result);
236 ASSERT_EQ(error_code, XCOM_GET_SYNODE_APP_DATA_OK);
237
238 ASSERT_EQ(result.synode_app_data_array_len, 1);
239 ASSERT_EQ(synode_eq(result.synode_app_data_array_val[0].synode, synode), 1);
240 ASSERT_EQ(synode_eq(result.synode_app_data_array_val[0].origin, origin), 1);
241 ASSERT_EQ(result.synode_app_data_array_val[0].data.data_len,
242 p->a->body.app_u_u.data.data_len);
243 ASSERT_EQ(std::strcmp(result.synode_app_data_array_val[0].data.data_val,
244 p->a->body.app_u_u.data.data_val),
245 0);
246
247 /* Cleanup */
248 a->body.app_u_u.data.data_len = 0;
249 a->body.app_u_u.data.data_val = nullptr;
250
251 unchecked_replace_pax_msg(&paxos->learner.msg, nullptr);
252
253 xdr_free(reinterpret_cast<xdrproc_t>(xdr_synode_app_data_array),
254 reinterpret_cast<char *>(&result));
255 }
256
257 TEST_F(XcomBase, GetSynodeAppDataTooManySynodes) {
258 /*
259 Bypass protocol negotiation because we are not actually connected to
260 anything.
261 */
262 connection_descriptor con;
263 con.connected_ = CON_PROTO;
264 con.x_proto = get_latest_common_proto();
265
266 constexpr uint32_t group_id = 1;
267 /* Unserializable message. Exceeds array size. */
268 u_int constexpr nr_synodes = MAX_SYNODE_ARRAY + 1;
269
270 synode_no_array synodes;
271 synodes.synode_no_array_len = nr_synodes;
272 synodes.synode_no_array_val =
273 static_cast<synode_no *>(std::calloc(nr_synodes, sizeof(synode_no)));
274 ASSERT_NE(synodes.synode_no_array_val, nullptr);
275
276 synode_app_data_array reply;
277 ASSERT_EQ(xcom_client_get_synode_app_data(&con, group_id, &synodes, &reply),
278 0);
279
280 std::free(synodes.synode_no_array_val);
281 }
282
283 /* Disable on Windows. The test outcome varies wildly on our test environment,
284 * likely due to different configurations of the stack size. */
285 #if !defined(_WIN32)
286 TEST_F(XcomBase, ProposerBatchDeserialization) {
287 pax_msg *p = nullptr;
288 unchecked_replace_pax_msg(&p, pax_msg_new_0(null_synode));
289
290 for (auto i = 0; i < MAX_BATCH_APP_DATA; i++) {
291 app_data_ptr a = new_app_data();
292 a->body.c_t = app_type;
293 a->next = p->a;
294
295 p->a = a;
296 }
297
298 char *buffer = nullptr;
299 uint32_t buffer_len = 0;
300
301 int const serialized =
302 serialize_msg(p, get_latest_common_proto(), &buffer_len, &buffer);
303 ASSERT_EQ(serialized, 1);
304
305 unchecked_replace_pax_msg(&p, pax_msg_new_0(null_synode));
306
307 int const deserialized =
308 deserialize_msg(p, get_latest_common_proto(), buffer, buffer_len);
309 ASSERT_EQ(deserialized, 1);
310
311 std::free(p);
312 std::free(buffer);
313 }
314 #endif // !defined(_WIN32)
315
316 // clang-format off
317 /*
318 This test validates the fix of
319 Bug #28966455 APPLIER LOG MISSES A TRANSACTION IN GR.
320
321 Situation
322 ---------
323 S0 is the leader, trying to get consensus on a transaction T for its own slot.
324 S1 is the follower, trying to take over the slot and get consensus on a no_op.
325
326 Legend
327 ------
328 SX: Server X
329 PX: Proposer of SX
330 ALX: Acceptor/learner of SX
331 O: Event on the respective server
332 X->: Message sent from the server on X to the server on ->
333 ###: Comment/observation
334 E: The part where P1 is deviating from the Paxos protocol
335
336 Diagram
337 -------
338 S0 S1 S2
339 P0 AL0 P1 AL1 AL2
340 | O | O O AL{0,1,2}.promise = (0,0)
341 | | | | |
342 ############################ P0 starts trying consensus for T
343 | | | | |
344 O | | | | P0.ballot = (0,0); P0.value = T
345 X--->|-------|--->|------->| accept_op[ballot=(0,0),
346 | | | | | value=T (P0.value)]
347 | | | | |
348 | O | O O AL{0,1,2}.value = T
349 |<---X-------|----X--------X ack_accept_op[ballot=(0,0)]
350 | | | | |
351 ############################ P0 got majority of accepts for (0,0) T
352 | | | | |
353 ############################ P1 starts trying consensus for no_op
354 | | | | |
355 | | O | | P1.ballot = (1,1); P1.value = no_op
356 | |<------X--->|------->| prepare_op[ballot=(1,1)]
357 | | | | |
358 | O | O O AL{0,1,2}.promise = (1,1)
359 | X------>|<---X--------X ack_prepare_op[ballot=(1,1),
360 | | | | | accepted={(0,0) T}]
361 | | | | |
362 ############################ P1 got a majority of prepares for (1,1)
363 | | | | |
364 | | E | | P1.value should be set to T here.
365 | | E | | According to the Paxos protocol, if any
366 | | E | | acceptor replies with a previously
367 | | E | | accepted value, one must use it. But
368 | | E | | handle_ack_prepare did not do it because
369 | | E | | handle_ack_prepare has the following code:
370 | | E | |
371 | | E | | if (gt_ballot(m->proposal,
372 | | E | | p->proposer.msg->proposal))
373 | | E | | {
374 | | E | | replace_pax_msg(&p->proposer.msg, m);
375 | | E | | ...
376 | | E | | }
377 | | E | |
378 | | E | | And p->proposer.msg->proposal was
379 | | E | | initialized to (0,1) on P1, meaning that:
380 | | E | |
381 | | E | | if (0,0) > (0,1): P1.value = T
382 | | E | |
383 | | E | | Therefore, P1.value = no_op.
384 | | E | | (see handle_ack_prepare)
385 | | | | |
386 | | ...--X--->|------->| accept_op[ballot=(1,1),
387 | | | | | value=no_op (P1.value)]
388 | | | | |
389 | | | O O AL{1,2}.value = no_op
390 | | |<---X--------X ack_accept_op[ballot=(1,1)]
391 | | | | |
392 ############################ P1 got majority of accepts for (1,1) no_op
393 ############################ Values accepted for P{0,1} don't agree
394 | | | | |
395 | | ...--X--->|------->| tiny_learn_op[ballot=(1,1), no_op]
396 | | | | |
397 | | | O O AL{1,2} learn no_op
398 | | | O O Executor task of S{1,2} delivers no_op
399 | | | | |
400 X--->|--... | | | tiny_learn_op[ballot=(0,0)]
401 | | | | |
402 | O | | | AL0 learns T
403 | O | | | Executor task of S0 delivers T
404 | | | | |
405 ############################ S0 delivered T, S{1,2} delivered no_op
406 | | | | |
407 */
408 // clang-format on
409 TEST_F(XcomBase, PaxosLearnSameValue) {
410 // Synod (42, 0).
411 synode_no synod;
412 synod.group_id = 1;
413 synod.msgno = 42;
414 synod.node = 0;
415
416 // pax_machine for each "server."
417 auto *s0_paxos =
418 static_cast<pax_machine *>(std::calloc(1, sizeof(pax_machine)));
419 init_pax_machine(s0_paxos, nullptr, synod);
420
421 auto *s1_paxos =
422 static_cast<pax_machine *>(std::calloc(1, sizeof(pax_machine)));
423 init_pax_machine(s1_paxos, nullptr, synod);
424
425 auto *s2_paxos =
426 static_cast<pax_machine *>(std::calloc(1, sizeof(pax_machine)));
427 init_pax_machine(s2_paxos, nullptr, synod);
428
429 // site_def for each "server."
430 auto *s0_config = new_site_def();
431 s0_config->nodeno = 0;
432 s0_config->nodes.node_list_len = 3;
433 s0_config->global_node_set.node_set_len = 3;
434
435 auto *s1_config = new_site_def();
436 s1_config->nodeno = 1;
437 s1_config->nodes.node_list_len = 3;
438 s1_config->global_node_set.node_set_len = 3;
439
440 auto *s2_config = new_site_def();
441 s2_config->nodeno = 2;
442 s2_config->nodes.node_list_len = 3;
443 s2_config->global_node_set.node_set_len = 3;
444
445 // clang-format off
446 /****************************************************************************
447 S0 S1 S2
448 P0 AL0 P1 AL1 AL2
449 | | | | |
450 O | | | | P0.ballot = (0,0); P0.value = T
451 X--->|-------|--->|------->| accept_op[ballot=(0,0),
452 | | | | | value=T (P0.value)]
453 | | | | |
454 | O | O O AL{0,1,2}.value = T
455 |<---X-------|----X--------X ack_accept_op[ballot=(0,0)]
456 | | | | |
457 ****************************************************************************/
458 // clang-format on
459 pax_msg *tx = pax_msg_new(synod, nullptr);
460 tx->a = new_app_data();
461 tx->a->body.c_t = app_type;
462 tx->a->body.app_u_u.data.data_len = 1;
463 tx->a->body.app_u_u.data.data_val = static_cast<char *>(malloc(sizeof(char)));
464 replace_pax_msg(&s0_paxos->proposer.msg, tx);
465 prepare_push_2p(s0_config, s0_paxos);
466 pax_msg *s0_accept_tx = s0_paxos->proposer.msg;
467 init_propose_msg(s0_accept_tx);
468 s0_accept_tx->from = 0;
469
470 ballot ballot_tx;
471 ballot_tx.cnt = 0;
472 ballot_tx.node = 0;
473 ASSERT_TRUE(eq_ballot(s0_paxos->proposer.msg->proposal, ballot_tx));
474
475 // S0 sends s0_accept_tx to AL{0,1,2}
476
477 // AL{0,1,2} receive s0_accept_tx
478
479 pax_msg *s0_accept_tx_s0 = clone_pax_msg(s0_accept_tx);
480 pax_msg *s0_ack_accept_tx =
481 handle_simple_accept(s0_paxos, s0_accept_tx_s0, s0_accept_tx_s0->synode);
482 ASSERT_NE(nullptr, s0_ack_accept_tx);
483 s0_ack_accept_tx->from = 0;
484
485 pax_msg *s0_accept_tx_s1 = clone_pax_msg(s0_accept_tx);
486 pax_msg *s1_ack_accept_tx =
487 handle_simple_accept(s1_paxos, s0_accept_tx_s1, s0_accept_tx_s1->synode);
488 ASSERT_NE(nullptr, s1_ack_accept_tx);
489 s1_ack_accept_tx->from = 1;
490
491 pax_msg *s0_accept_tx_s2 = clone_pax_msg(s0_accept_tx);
492 pax_msg *s2_ack_accept_tx =
493 handle_simple_accept(s2_paxos, s0_accept_tx_s2, s0_accept_tx_s2->synode);
494 ASSERT_NE(nullptr, s2_ack_accept_tx);
495 s2_ack_accept_tx->from = 2;
496
497 // AL{0,1,2} send s{0,1,2}_ack_accept_tx to P0
498
499 // P0 receives s{0,1,2}_ack_accept_tx
500
501 pax_msg *s0_ack_accept_tx_s0 = clone_pax_msg(s0_ack_accept_tx);
502 ASSERT_EQ(nullptr,
503 handle_simple_ack_accept(s0_config, s0_paxos, s0_ack_accept_tx_s0));
504
505 pax_msg *s1_ack_accept_tx_s0 = clone_pax_msg(s1_ack_accept_tx);
506 pax_msg *s0_learn_tx =
507 handle_simple_ack_accept(s0_config, s0_paxos, s1_ack_accept_tx_s0);
508 ASSERT_NE(nullptr, s0_learn_tx);
509 ASSERT_EQ(tiny_learn_op, s0_learn_tx->op);
510 s0_learn_tx->from = 0;
511
512 pax_msg *s2_ack_accept_tx_s0 = clone_pax_msg(s2_ack_accept_tx);
513 ASSERT_EQ(nullptr,
514 handle_simple_ack_accept(s0_config, s0_paxos, s2_ack_accept_tx_s0));
515
516 // clang-format off
517 /****************************************************************************
518 S0 S1 S2
519 P0 AL0 P1 AL1 AL2
520 | | | | |
521 | | O | | P1.ballot = (1,1); P1.value = no_op
522 | |<------X--->|------->| prepare_op[ballot=(1,1)]
523 | | | | |
524 | | | | |
525 | O | O O AL{0,1,2}.promise = (1,1)
526 | X------>|<---X--------X ack_prepare_op[ballot=(1,1),
527 | | | | | accepted={(0,0) T}]
528 | | | | |
529 ****************************************************************************/
530 // clang-format on
531 replace_pax_msg(&s1_paxos->proposer.msg, pax_msg_new(synod, s1_config));
532 create_noop(s1_paxos->proposer.msg);
533 pax_msg *s1_prepare_noop = clone_pax_msg(s1_paxos->proposer.msg);
534 prepare_push_3p(s1_config, s1_paxos, s1_prepare_noop, synod, no_op);
535 init_prepare_msg(s1_prepare_noop);
536 s1_prepare_noop->from = 1;
537
538 ballot ballot_noop;
539 ballot_noop.cnt = 1;
540 ballot_noop.node = 1;
541 ASSERT_TRUE(eq_ballot(s1_prepare_noop->proposal, ballot_noop));
542
543 // P1 sends s1_prepare_noop to AL{0,1,2}
544
545 // AL{0,1,2} receive s1_prepare_noop
546
547 pax_msg *s1_prepare_noop_s0 = clone_pax_msg(s1_prepare_noop);
548 pax_msg *s0_ack_prepare_noop =
549 handle_simple_prepare(s0_paxos, s1_prepare_noop_s0, synod);
550 ASSERT_NE(nullptr, s0_ack_prepare_noop);
551 ASSERT_EQ(ack_prepare_op, s0_ack_prepare_noop->op);
552 ASSERT_TRUE(eq_ballot(s0_ack_prepare_noop->proposal, ballot_tx));
553 ASSERT_EQ(normal, s0_ack_prepare_noop->msg_type);
554 s0_ack_prepare_noop->from = 0;
555
556 pax_msg *s1_prepare_noop_s1 = clone_pax_msg(s1_prepare_noop);
557 pax_msg *s1_ack_prepare_noop =
558 handle_simple_prepare(s1_paxos, s1_prepare_noop_s1, synod);
559 ASSERT_NE(nullptr, s1_ack_prepare_noop);
560 ASSERT_EQ(ack_prepare_op, s1_ack_prepare_noop->op);
561 ASSERT_TRUE(eq_ballot(s1_ack_prepare_noop->proposal, ballot_tx));
562 ASSERT_EQ(normal, s1_ack_prepare_noop->msg_type);
563 s1_ack_prepare_noop->from = 1;
564
565 pax_msg *s1_prepare_noop_s2 = clone_pax_msg(s1_prepare_noop);
566 pax_msg *s2_ack_prepare_noop =
567 handle_simple_prepare(s2_paxos, s1_prepare_noop_s2, synod);
568 ASSERT_NE(nullptr, s2_ack_prepare_noop);
569 ASSERT_EQ(ack_prepare_op, s2_ack_prepare_noop->op);
570 ASSERT_TRUE(eq_ballot(s2_ack_prepare_noop->proposal, ballot_tx));
571 ASSERT_EQ(normal, s2_ack_prepare_noop->msg_type);
572 s2_ack_prepare_noop->from = 2;
573
574 // AL{0,1,2} send s{0,1,2}_ack_prepare_noop to P1
575
576 // P1 receives s{0,1,2}_ack_prepare_noop
577
578 pax_msg *s0_ack_prepare_noop_s1 = clone_pax_msg(s0_ack_prepare_noop);
579 ASSERT_FALSE(
580 handle_simple_ack_prepare(s1_config, s1_paxos, s0_ack_prepare_noop_s1));
581
582 pax_msg *s1_ack_prepare_noop_s1 = clone_pax_msg(s1_ack_prepare_noop);
583 bool can_send_accept =
584 handle_simple_ack_prepare(s1_config, s1_paxos, s1_ack_prepare_noop_s1);
585 ASSERT_TRUE(can_send_accept);
586 pax_msg *s1_accept_noop = s1_paxos->proposer.msg;
587 ASSERT_NE(nullptr, s1_accept_noop);
588 ASSERT_EQ(accept_op, s1_accept_noop->op);
589 s1_accept_noop->from = 1;
590
591 pax_msg *s2_ack_prepare_noop_s1 = clone_pax_msg(s2_ack_prepare_noop);
592 ASSERT_FALSE(
593 handle_simple_ack_prepare(s1_config, s1_paxos, s2_ack_prepare_noop_s1));
594
595 // clang-format off
596 /****************************************************************************
597 S0 S1 S2
598 P0 AL0 P1 AL1 AL2
599 | | | | |
600 | | E | | P1.value should be set to T here.
601 | | E | | According to the Paxos protocol, if any
602 | | E | | acceptor replies with a previously
603 | | E | | accepted value, one must use it. But
604 | | E | | handle_ack_prepare will not do it because
605 | | E | | handle_ack_prepare has the following code:
606 | | E | |
607 | | E | | if (gt_ballot(m->proposal,
608 | | E | | p->proposer.msg->proposal))
609 | | E | | {
610 | | E | | replace_pax_msg(&p->proposer.msg, m);
611 | | E | | ...
612 | | E | | }
613 | | E | |
614 | | E | | However, p->proposer.msg->proposal is initialized
615 | | E | | to (0,1) on P1, meaning that:
616 | | E | |
617 | | E | | if (0,0) > (0,1): P1.value = no_op
618 | | E | |
619 | | E | | Therefore, P1.value = no_op.
620 | | E | | (see handle_ack_prepare)
621 | | | | |
622 | | ...--X--->|------->| accept_op[ballot=(1,1),
623 | | | | | value=no_op (P1.value)]
624 | | | | |
625 | | | O O AL{0,1,2}.value = no_op
626 | | |<---X--------X ack_accept_op[ballot=(1,1)]
627 | | | | |
628 | | | | |
629 | | ...--X--->|------->| tiny_learn_op[ballot=(1,1), no_op]
630 | | | | |
631 | | | O O AL{1,2} learn no_op
632 | | | O O Executor task of S{1,2} delivers no_op
633 | | | | |
634 ****************************************************************************/
635 // clang-format on
636 /*
637 Here was the problem. P1 should have inherited T from one of AL{0,1,2}. But
638 it did not because, s1_paxos->proposer.msg->proposal was initialized to
639 (0,1).
640 This lead to gt_ballot(m->proposal, p->proposer.msg->proposal) being false:
641
642 gt_ballot(m->proposal, p->proposer.msg->proposal) <=>
643 gt_ballot((0,0), (0,1)) <=>
644 false
645
646 The assert below would fire on mysql-trunk before the fix for
647 Bug #28966455 APPLIER LOG MISSES A TRANSACTION IN GR.
648 */
649 // assert(s1_paxos->proposer.msg->msg_type != no_op);
650
651 // P1 sends s1_accept_noop to AL{1,2}
652 // P1 alsos sends s1_accept_noop to AL0, but it gets delayed
653
654 // AL{1,2} receive s1_accept_noop
655 pax_msg *s1_ack_accept_noop =
656 handle_simple_accept(s1_paxos, clone_pax_msg(s1_accept_noop), synod);
657 s1_ack_accept_noop->from = 1;
658
659 pax_msg *s2_ack_accept_noop =
660 handle_simple_accept(s2_paxos, clone_pax_msg(s1_accept_noop), synod);
661 s2_ack_accept_noop->from = 2;
662
663 // AL{1,2} send s{1,2}_ack_accept_noop to P1
664
665 // P1 receives s{1,2}_ack_accept_noop
666 pax_msg *s1_ack_accept_noop_s1 = clone_pax_msg(s1_ack_accept_noop);
667 ASSERT_EQ(nullptr, handle_simple_ack_accept(s1_config, s1_paxos,
668 s1_ack_accept_noop_s1));
669
670 pax_msg *s2_ack_accept_noop_s1 = clone_pax_msg(s2_ack_accept_noop);
671 pax_msg *s1_learn_noop =
672 handle_simple_ack_accept(s1_config, s1_paxos, s2_ack_accept_noop_s1);
673 ASSERT_NE(nullptr, s1_learn_noop);
674 ASSERT_EQ(tiny_learn_op, s1_learn_noop->op);
675 s1_learn_noop->from = 1;
676
677 // P1 sends s1_learn_noop to AL{1,2}
678 // P1 alsos sends s1_learn_noop to AL0, but it gets delayed
679
680 // AL{1,2} receive s1_learn_noop
681 pax_msg *s1_learn_noop_s1 = clone_pax_msg(s1_learn_noop);
682 handle_learn(s1_config, s1_paxos, s1_learn_noop_s1);
683
684 pax_msg *s1_learn_noop_s2 = clone_pax_msg(s1_learn_noop);
685 handle_learn(s2_config, s2_paxos, s1_learn_noop_s2);
686
687 ASSERT_TRUE(pm_finished(s1_paxos));
688
689 ASSERT_TRUE(pm_finished(s2_paxos));
690
691 // S1 and S2 would deliver no_op... (but deliver tx after the fix)
692
693 // clang-format off
694 /****************************************************************************
695 S0 S1 S2
696 P0 AL0 P1 AL1 AL2
697 | | | | |
698 X--->|--... | | | tiny_learn_op[ballot=(0,0)]
699 | | | | |
700 | O | | | AL0 learns T
701 | O | | | Executor task of S0 delivers T
702 | | | | |
703 ****************************************************************************/
704 // clang-format on
705
706 // P0 sends s0_learn_tx to AL0
707 // P1 alsos sends s0_learn_tx to AL{1,2}, but it doesn't matter
708
709 // AL0 receive s0_learn_tx
710 pax_msg *s0_learn_tx_s0 = clone_pax_msg(s0_learn_tx);
711 handle_tiny_learn(s0_config, s0_paxos, s0_learn_tx_s0);
712
713 ASSERT_TRUE(pm_finished(s0_paxos));
714
715 // ...and S0 delivers tx
716
717 bool const every_executor_delivered_same_value =
718 (s0_paxos->learner.msg->msg_type == s1_paxos->learner.msg->msg_type &&
719 s1_paxos->learner.msg->msg_type == s2_paxos->learner.msg->msg_type);
720 ASSERT_TRUE(every_executor_delivered_same_value);
721
722 // Cleanup.
723 auto free_pax_msg = [](pax_msg *p) {
724 p->refcnt = 1;
725 replace_pax_msg(&p, nullptr);
726 };
727
728 init_pax_machine(s0_paxos, nullptr, synod);
729 std::free(s0_paxos->proposer.prep_nodeset->bits.bits_val);
730 std::free(s0_paxos->proposer.prep_nodeset);
731 std::free(s0_paxos->proposer.prop_nodeset->bits.bits_val);
732 std::free(s0_paxos->proposer.prop_nodeset);
733 std::free(s0_paxos);
734 std::free(s0_config);
735 free_pax_msg(s0_ack_accept_tx);
736 free_pax_msg(s0_ack_accept_tx_s0);
737 free_pax_msg(s0_learn_tx);
738 free_pax_msg(s1_prepare_noop_s0);
739 free_pax_msg(s0_ack_prepare_noop);
740 free_pax_msg(s0_learn_tx_s0);
741
742 init_pax_machine(s1_paxos, nullptr, synod);
743 std::free(s1_paxos->proposer.prep_nodeset->bits.bits_val);
744 std::free(s1_paxos->proposer.prep_nodeset);
745 std::free(s1_paxos->proposer.prop_nodeset->bits.bits_val);
746 std::free(s1_paxos->proposer.prop_nodeset);
747 std::free(s1_paxos);
748 std::free(s1_config);
749 free_pax_msg(s1_ack_accept_tx);
750 free_pax_msg(s1_ack_accept_tx_s0);
751 free_pax_msg(s1_prepare_noop);
752 free_pax_msg(s1_prepare_noop_s1);
753 free_pax_msg(s1_ack_prepare_noop);
754 free_pax_msg(s1_ack_prepare_noop_s1);
755 free_pax_msg(s2_ack_prepare_noop_s1);
756 free_pax_msg(s1_ack_accept_noop);
757 free_pax_msg(s1_ack_accept_noop_s1);
758 free_pax_msg(s2_ack_accept_noop_s1);
759 free_pax_msg(s1_learn_noop);
760
761 init_pax_machine(s2_paxos, nullptr, synod);
762 std::free(s2_paxos->proposer.prep_nodeset->bits.bits_val);
763 std::free(s2_paxos->proposer.prep_nodeset);
764 std::free(s2_paxos->proposer.prop_nodeset->bits.bits_val);
765 std::free(s2_paxos->proposer.prop_nodeset);
766 std::free(s2_paxos);
767 std::free(s2_config);
768 free_pax_msg(s2_ack_accept_tx);
769 free_pax_msg(s2_ack_accept_tx_s0);
770 free_pax_msg(s1_prepare_noop_s2);
771 free_pax_msg(s2_ack_prepare_noop);
772 free_pax_msg(s2_ack_accept_noop);
773 }
774
775 TEST_F(XcomBase, HandleBootWithoutIdentity) {
776 // Synod (42, 0).
777 synode_no synod;
778 synod.group_id = 1;
779 synod.msgno = 42;
780 synod.node = 0;
781
782 // Fake node information.
783 char const *names[]{"127.0.0.1:10001"};
784 blob uuid;
785 uuid.data.data_len = 1;
786 uuid.data.data_val = const_cast<char *>("1");
787 blob uuids[] = {uuid};
788
789 // site_def for the "server."
790 auto *config = new_site_def();
791 config->nodeno = 0;
792 config->nodes.node_list_len = 1;
793 config->nodes.node_list_val = ::new_node_address_uuid(1, names, uuids);
794
795 pax_msg *need_boot = pax_msg_new(synod, nullptr);
796 // need_boot_op without an identity.
797 init_need_boot_op(need_boot, nullptr);
798 ASSERT_TRUE(should_handle_need_boot(config, need_boot));
799
800 // Cleanup.
801 need_boot->refcnt = 1;
802 replace_pax_msg(&need_boot, nullptr);
803
804 ::delete_node_address(1, config->nodes.node_list_val);
805
806 std::free(config);
807 }
808
809 TEST_F(XcomBase, HandleBootWithIdentityOfExistingMember) {
810 // Synod (42, 0).
811 synode_no synod;
812 synod.group_id = 1;
813 synod.msgno = 42;
814 synod.node = 0;
815
816 // Fake node information.
817 char const *names[]{"127.0.0.1:10001"};
818 blob uuid;
819 uuid.data.data_len = 1;
820 uuid.data.data_val = const_cast<char *>("1");
821 blob uuids[] = {uuid};
822
823 // site_def for the "server."
824 auto *config = new_site_def();
825 config->nodeno = 0;
826 config->nodes.node_list_len = 1;
827 config->nodes.node_list_val = ::new_node_address_uuid(1, names, uuids);
828
829 pax_msg *need_boot = pax_msg_new(synod, nullptr);
830 // need_boot_op with an identity.
831 node_address *identity = ::new_node_address_uuid(1, names, uuids);
832 init_need_boot_op(need_boot, identity);
833 ASSERT_TRUE(should_handle_need_boot(config, need_boot));
834
835 // Cleanup.
836 need_boot->refcnt = 1;
837 replace_pax_msg(&need_boot, nullptr);
838
839 ::delete_node_address(1, config->nodes.node_list_val);
840 ::delete_node_address(1, identity);
841
842 std::free(config);
843 }
844
845 TEST_F(XcomBase, HandleBootWithIdentityOfNonExistingMember) {
846 // Synod (42, 0).
847 synode_no synod;
848 synod.group_id = 1;
849 synod.msgno = 42;
850 synod.node = 0;
851
852 // Fake node information.
853 char const *names[]{"127.0.0.1:10001"};
854 blob uuid;
855 uuid.data.data_len = 1;
856 uuid.data.data_val = const_cast<char *>("1");
857 blob uuids[] = {uuid};
858
859 // site_def for the "server."
860 auto *config = new_site_def();
861 config->nodeno = 0;
862 config->nodes.node_list_len = 1;
863 config->nodes.node_list_val = ::new_node_address_uuid(1, names, uuids);
864
865 pax_msg *need_boot = pax_msg_new(synod, nullptr);
866 // need_boot_op with an identity.
867 blob unknown_uuid;
868 unknown_uuid.data.data_len = 1;
869 unknown_uuid.data.data_val = const_cast<char *>("2");
870 blob unknown_uuids[] = {unknown_uuid};
871 node_address *identity = ::new_node_address_uuid(1, names, unknown_uuids);
872 init_need_boot_op(need_boot, identity);
873 ASSERT_FALSE(should_handle_need_boot(config, need_boot));
874
875 // Cleanup.
876 need_boot->refcnt = 1;
877 replace_pax_msg(&need_boot, nullptr);
878
879 ::delete_node_address(1, config->nodes.node_list_val);
880 ::delete_node_address(1, identity);
881
882 std::free(config);
883 }
884
885 TEST_F(XcomBase, HandleBootWithMoreThanOneIdentity) {
886 // Synod (42, 0).
887 synode_no synod;
888 synod.group_id = 1;
889 synod.msgno = 42;
890 synod.node = 0;
891
892 // Fake node information.
893 char const *name{"127.0.0.1:10001"};
894 char const *names[]{name};
895 blob uuid;
896 uuid.data.data_len = 1;
897 uuid.data.data_val = const_cast<char *>("1");
898 blob uuids[] = {uuid};
899
900 // site_def for the "server."
901 auto *config = new_site_def();
902 config->nodeno = 0;
903 config->nodes.node_list_len = 1;
904 config->nodes.node_list_val = ::new_node_address_uuid(1, names, uuids);
905
906 pax_msg *need_boot = pax_msg_new(synod, nullptr);
907 // need_boot_op with two identities.
908 char const *other_name{"127.0.0.1:10002"};
909 char const *two_names[] = {name, other_name};
910 blob two_uuids[] = {uuid, uuid};
911 node_address *identity = ::new_node_address_uuid(2, two_names, two_uuids);
912 need_boot->op = need_boot_op;
913 if (identity != nullptr) {
914 need_boot->a = new_app_data();
915 need_boot->a->body.c_t = xcom_boot_type;
916 init_node_list(2, identity, &need_boot->a->body.app_u_u.nodes);
917 }
918 ASSERT_FALSE(should_handle_need_boot(config, need_boot));
919
920 // Cleanup.
921 need_boot->refcnt = 1;
922 replace_pax_msg(&need_boot, nullptr);
923
924 ::delete_node_address(1, config->nodes.node_list_val);
925 ::delete_node_address(2, identity);
926
927 std::free(config);
928 }
929
930 /**
931 * This test will check the logic implemented in pre_process_incoming_ping
932 *
933 * It will create all necessary support structures and:
934 * - Call pre_process_incoming_ping 4 times
935 * - On the first and second try it must:
936 * -- increment the number of pings
937 * -- Make sure that we do not shutdown the connection
938 * - On the third attempt it must:
939 * -- Have incremented the number of pings
940 * -- Shutdown the connection
941 * - On the fourth attempt
942 * -- Have incremented the number of pings
943 * -- Make sure that we do not shutdown the connection
944 */
945 TEST_F(XcomBase, ProcessPingToUsFullSmokeTest) {
946 site_def site;
947 pax_msg pm;
948
949 server srv_from;
950 srv_from.last_ping_received = 0.0;
951 srv_from.number_of_pings_received = 0;
952
953 srv_from.con = new_connection(0, nullptr);
954 srv_from.con->connected_ = CON_PROTO;
955
956 char srv_addr[1024] = "test";
957 srv_from.srv = &srv_addr[0];
958 srv_from.port = 12345;
959
960 site.nodeno = 1;
961 site.global_node_set.node_set_len = 3;
962 site.nodes.node_list_len = 3;
963 site.servers[0] = &srv_from;
964
965 pm.from = 0;
966 pm.op = are_you_alive_op;
967
968 bool has_disconnected = false;
969 has_disconnected = pre_process_incoming_ping(&site, &pm, true, 1.0);
970 ASSERT_EQ(1, srv_from.number_of_pings_received);
971 ASSERT_FALSE(has_disconnected);
972
973 has_disconnected = pre_process_incoming_ping(&site, &pm, true, 2.0);
974 ASSERT_EQ(2, srv_from.number_of_pings_received);
975 ASSERT_FALSE(has_disconnected);
976
977 has_disconnected = pre_process_incoming_ping(&site, &pm, true, 3.0);
978 ASSERT_EQ(3, srv_from.number_of_pings_received);
979 ASSERT_TRUE(has_disconnected);
980
981 has_disconnected = pre_process_incoming_ping(&site, &pm, true, 5.0);
982 ASSERT_EQ(4, srv_from.number_of_pings_received);
983 ASSERT_FALSE(has_disconnected);
984
985 free(srv_from.con);
986 }
987
988 /**
989 * This test will check the logic implemented in pre_process_incoming_ping when
990 * the node has not booted
991 *
992 * It will create all necessary support structures and:
993 * - Call pre_process_incoming_ping 4 times
994 * - On every time it must:
995 * -- NOT increment the number of pings
996 * -- Make sure that we do NOT shutdown the connection
997 */
998 TEST_F(XcomBase, ProcessPingToUsDoNothingIfNodeIsBooting) {
999 site_def site;
1000 pax_msg pm;
1001
1002 server srv_from;
1003 srv_from.last_ping_received = 0.0;
1004 srv_from.number_of_pings_received = 0;
1005 srv_from.con = new_connection(0, nullptr);
1006 srv_from.con->connected_ = CON_PROTO;
1007
1008 char srv_addr[1024] = "test";
1009 srv_from.srv = &srv_addr[0];
1010 srv_from.port = 12345;
1011
1012 site.nodeno = 1;
1013 site.global_node_set.node_set_len = 3;
1014 site.nodes.node_list_len = 3;
1015 site.servers[0] = &srv_from;
1016
1017 pm.from = 0;
1018 pm.op = are_you_alive_op;
1019
1020 bool has_disconnected = false;
1021 has_disconnected = pre_process_incoming_ping(&site, &pm, false, 1.0);
1022 ASSERT_EQ(0, srv_from.number_of_pings_received);
1023 ASSERT_FALSE(has_disconnected);
1024
1025 has_disconnected = pre_process_incoming_ping(&site, &pm, false, 2.0);
1026 ASSERT_EQ(0, srv_from.number_of_pings_received);
1027 ASSERT_FALSE(has_disconnected);
1028
1029 has_disconnected = pre_process_incoming_ping(&site, &pm, false, 3.0);
1030 ASSERT_EQ(0, srv_from.number_of_pings_received);
1031 ASSERT_FALSE(has_disconnected);
1032
1033 has_disconnected = pre_process_incoming_ping(&site, &pm, false, 5.0);
1034 ASSERT_EQ(0, srv_from.number_of_pings_received);
1035 ASSERT_FALSE(has_disconnected);
1036
1037 free(srv_from.con);
1038 }
1039
1040 /**
1041 * This test will check the logic implemented in pre_process_incoming_ping
1042 * with an inactive connection
1043 *
1044 * It will create all necessary support structures and:
1045 * - Call pre_process_incoming_ping 4 times
1046 * - On the first and second try it must:
1047 * -- increment the number of pings
1048 * -- Make sure that we do not shutdown the connection
1049 * - On the third attempt it must:
1050 * -- Have incremented the number of pings
1051 * -- DO NOT Shutdown the connection
1052 * - On the fourth attempt
1053 * -- Have incremented the number of pings
1054 * -- Make sure that we do not shutdown the connection
1055 */
1056 TEST_F(XcomBase, ProcessPingToUsDoNotShutdownInactiveConnection) {
1057 site_def site;
1058 pax_msg pm;
1059
1060 server srv_from;
1061 srv_from.last_ping_received = 0.0;
1062 srv_from.number_of_pings_received = 0;
1063 srv_from.con = new_connection(-1, nullptr);
1064 srv_from.con->connected_ = CON_NULL;
1065
1066 site.nodeno = 1;
1067 site.global_node_set.node_set_len = 3;
1068 site.nodes.node_list_len = 3;
1069 site.servers[0] = &srv_from;
1070
1071 pm.from = 0;
1072 pm.op = are_you_alive_op;
1073
1074 bool has_disconnected = false;
1075 has_disconnected = pre_process_incoming_ping(&site, &pm, true, 1.0);
1076 ASSERT_EQ(1, srv_from.number_of_pings_received);
1077 ASSERT_FALSE(has_disconnected);
1078
1079 has_disconnected = pre_process_incoming_ping(&site, &pm, true, 2.0);
1080 ASSERT_EQ(2, srv_from.number_of_pings_received);
1081 ASSERT_FALSE(has_disconnected);
1082
1083 has_disconnected = pre_process_incoming_ping(&site, &pm, true, 3.0);
1084 ASSERT_EQ(3, srv_from.number_of_pings_received);
1085 ASSERT_FALSE(has_disconnected);
1086
1087 has_disconnected = pre_process_incoming_ping(&site, &pm, true, 5.0);
1088 ASSERT_EQ(4, srv_from.number_of_pings_received);
1089 ASSERT_FALSE(has_disconnected);
1090
1091 free(srv_from.con);
1092 }
1093
1094 /**
1095 * This test will check the logic implemented in pre_process_incoming_ping
1096 * making sure that we are able to reset the ping number value
1097 *
1098 * It will create all necessary support structures and:
1099 * - Call pre_process_incoming_ping 3 times
1100 * - On the first and second try it must:
1101 * -- increment the number of pings
1102 * -- Make sure that we do not shutdown the connection
1103 * - Wait for 6 seconds
1104 * - On the third attempt it must:
1105 * -- Have reset number of pings
1106 * -- DO NOT Shutdown the connection
1107 */
1108 TEST_F(XcomBase, ProcessPingToUsDoNotShutdownResetPings) {
1109 site_def site;
1110 pax_msg pm;
1111
1112 server srv_from;
1113 srv_from.last_ping_received = 0.0;
1114 srv_from.number_of_pings_received = 0;
1115 srv_from.con = new_connection(-1, nullptr);
1116 srv_from.con->connected_ = CON_NULL;
1117
1118 site.nodeno = 1;
1119 site.global_node_set.node_set_len = 3;
1120 site.nodes.node_list_len = 3;
1121 site.servers[0] = &srv_from;
1122
1123 pm.from = 0;
1124 pm.op = are_you_alive_op;
1125
1126 bool has_disconnected = false;
1127 has_disconnected = pre_process_incoming_ping(&site, &pm, true, 1.0);
1128 ASSERT_EQ(1, srv_from.number_of_pings_received);
1129 ASSERT_FALSE(has_disconnected);
1130
1131 has_disconnected = pre_process_incoming_ping(&site, &pm, true, 2.0);
1132 ASSERT_EQ(2, srv_from.number_of_pings_received);
1133 ASSERT_FALSE(has_disconnected);
1134
1135 has_disconnected = pre_process_incoming_ping(&site, &pm, true, 10.0);
1136 ASSERT_EQ(1, srv_from.number_of_pings_received);
1137 ASSERT_FALSE(has_disconnected);
1138
1139 free(srv_from.con);
1140 }
1141
1142 /**
1143 * This test will check the logic implemented in pre_process_incoming_ping
1144 * and it will receive pings from 2 different servers.
1145 *
1146 * It will create all necessary support structures and:
1147 * - Call pre_process_incoming_ping 4 times using server 1
1148 * - On the first and second try using server 1 it must:
1149 * -- increment the number of pings
1150 * -- Make sure that we do not shutdown the connection
1151 * - Call pre_process_incoming_ping once using server 2
1152 * - On the first and second try it must:
1153 * -- increment the number of pings
1154 * -- Make sure that we do not shutdown the connection
1155 * - On the third attempt using server 1 it must:
1156 * -- Have incremented the number of pings
1157 * -- Shutdown the connection
1158 * - On the fourth attempt using server 1
1159 * -- Have incremented the number of pings
1160 * -- Make sure that we do not shutdown the connection
1161 */
1162 TEST_F(XcomBase, ProcessPingToUsTwoServersSendingPings) {
1163 site_def site;
1164 pax_msg pm1, pm2;
1165
1166 char srv_addr[1024] = "test";
1167
1168 server srv_from1, srv_from2;
1169 srv_from1.last_ping_received = 0.0;
1170 srv_from1.number_of_pings_received = 0;
1171 srv_from1.con = new_connection(0, nullptr);
1172 srv_from1.con->connected_ = CON_PROTO;
1173
1174 srv_from1.srv = &srv_addr[0];
1175 srv_from1.port = 12345;
1176
1177 srv_from2.last_ping_received = 0.0;
1178 srv_from2.number_of_pings_received = 0;
1179 srv_from2.con = new_connection(0, nullptr);
1180 srv_from2.con->connected_ = CON_PROTO;
1181
1182 srv_from2.srv = &srv_addr[0];
1183 srv_from2.port = 12346;
1184
1185 site.nodeno = 1;
1186 site.global_node_set.node_set_len = 3;
1187 site.nodes.node_list_len = 3;
1188 site.servers[0] = &srv_from1;
1189 site.servers[2] = &srv_from2;
1190
1191 pm1.from = 0;
1192 pm1.op = are_you_alive_op;
1193
1194 pm2.from = 2;
1195 pm2.op = are_you_alive_op;
1196
1197 bool has_disconnected = false;
1198 has_disconnected = pre_process_incoming_ping(&site, &pm1, true, 1.0);
1199 ASSERT_EQ(1, srv_from1.number_of_pings_received);
1200 ASSERT_FALSE(has_disconnected);
1201
1202 has_disconnected = pre_process_incoming_ping(&site, &pm1, true, 2.0);
1203 ASSERT_EQ(2, srv_from1.number_of_pings_received);
1204 ASSERT_FALSE(has_disconnected);
1205
1206 has_disconnected = pre_process_incoming_ping(&site, &pm2, true, 3.0);
1207 ASSERT_EQ(1, srv_from2.number_of_pings_received);
1208 ASSERT_FALSE(has_disconnected);
1209
1210 has_disconnected = pre_process_incoming_ping(&site, &pm1, true, 4.0);
1211 ASSERT_EQ(3, srv_from1.number_of_pings_received);
1212 ASSERT_TRUE(has_disconnected);
1213
1214 has_disconnected = pre_process_incoming_ping(&site, &pm1, true, 5.0);
1215 ASSERT_EQ(4, srv_from1.number_of_pings_received);
1216 ASSERT_FALSE(has_disconnected);
1217
1218 free(srv_from1.con);
1219 free(srv_from2.con);
1220 }
1221
1222 } // namespace xcom_base_unittest