Skip to content

Commit 0fd9cb4

Browse files
committed
Basic fault-injection test code.
1 parent 0190532 commit 0fd9cb4

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

ClientSource/Connection/PABotBase.cpp

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
//using std::cout;
1717
//using std::endl;
1818

19+
20+
// Intentionally drop some messages to test self-recovery.
21+
//#define INTENTIONALLY_DROP_MESSAGES
22+
23+
24+
1925
// #define DEBUG_STACK_TRACE
2026

2127
#ifdef DEBUG_STACK_TRACE
@@ -264,7 +270,7 @@ void PABotBase::clear_all_active_commands(uint64_t seqnum){
264270
seqnum_t seqnum_s = (seqnum_t)iter->first;
265271
memcpy(&message.body[0], &seqnum_s, sizeof(seqnum_t));
266272

267-
// cout << "removing = " << seqnum_s << ", " << (int)iter->second.state << endl;
273+
// cout << "removing = " << seqnum_s << ", " << (int)iter->second.state << endl;
268274

269275
std::pair<std::map<uint64_t, PendingRequest>::iterator, bool> ret = m_pending_requests.emplace(
270276
std::piecewise_construct,
@@ -449,7 +455,15 @@ void PABotBase::process_command_finished(BotBaseMessage message){
449455
std::lock_guard<std::mutex> lg0(m_sleep_lock);
450456
WriteSpinLock lg1(m_state_lock, "PABotBase::process_command_finished() - 0");
451457

458+
#ifdef INTENTIONALLY_DROP_MESSAGES
459+
if (rand() % 10 != 0){
460+
send_message(BotBaseMessage(PABB_MSG_ACK_REQUEST, std::string((char*)&ack, sizeof(ack))), false);
461+
}else{
462+
m_logger.log("Intentionally dropping finish ack: " + std::to_string(seqnum), COLOR_RED);
463+
}
464+
#else
452465
send_message(BotBaseMessage(PABB_MSG_ACK_REQUEST, std::string((char*)&ack, sizeof(ack))), false);
466+
#endif
453467

454468
if (m_pending_commands.empty()){
455469
m_sniffer->log(
@@ -664,7 +678,7 @@ uint64_t PABotBase::try_issue_request(
664678

665679
// Too many unacked requests in flight.
666680
if (inflight_requests() >= queue_limit){
667-
m_logger.log("Message throttled due to too many inflight requests.");
681+
// m_logger.log("Message throttled due to too many inflight requests.");
668682
return 0;
669683
}
670684

@@ -694,7 +708,15 @@ uint64_t PABotBase::try_issue_request(
694708
handle.request = std::move(message);
695709
handle.first_sent = current_time();
696710

711+
#ifdef INTENTIONALLY_DROP_MESSAGES
712+
if (rand() % 10 != 0){
713+
send_message(handle.request, false);
714+
}else{
715+
m_logger.log("Intentionally dropping request: " + std::to_string(seqnum), COLOR_RED);
716+
}
717+
#else
697718
send_message(handle.request, false);
719+
#endif
698720

699721
return seqnum;
700722
}
@@ -735,7 +757,7 @@ uint64_t PABotBase::try_issue_command(
735757

736758
// Too many unacked requests in flight.
737759
if (inflight_requests() >= queue_limit){
738-
m_logger.log("Message throttled due to too many inflight requests.");
760+
// m_logger.log("Message throttled due to too many inflight requests.");
739761
return 0;
740762
}
741763

@@ -765,7 +787,15 @@ uint64_t PABotBase::try_issue_command(
765787
handle.request = std::move(message);
766788
handle.first_sent = current_time();
767789

790+
#ifdef INTENTIONALLY_DROP_MESSAGES
791+
if (rand() % 10 != 0){
792+
send_message(handle.request, false);
793+
}else{
794+
m_logger.log("Intentionally dropping command: " + std::to_string(seqnum), COLOR_RED);
795+
}
796+
#else
768797
send_message(handle.request, false);
798+
#endif
769799

770800
return seqnum;
771801
}

0 commit comments

Comments
 (0)