Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Less flaky test BasicSystemTest [13878] #147

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions test/dds/communication/Monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -691,5 +691,7 @@ int main(
// }

std::cerr << "Stop Monitor_" << seed << '\n';
char c;
std::cin >> c;
return 0;
}
17 changes: 13 additions & 4 deletions test/dds/communication/Subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ class ParListener : public DomainParticipantListener
return;
}

g_qos.durability().kind = eprosima::fastdds::dds::TRANSIENT_LOCAL_DURABILITY_QOS;

g_reader = g_subscriber->create_datareader(
g_topic,
g_qos,
Expand Down Expand Up @@ -168,10 +170,13 @@ class ParListener : public DomainParticipantListener
}
};

participant->register_remote_type(
type_information,
type_name.to_string(),
callback);
if (eprosima::fastrtps::types::ReturnCode_t::RETCODE_OK != participant->register_remote_type(
type_information,
type_name.to_string(),
callback))
{
std::cout << "ERROR: Cannot register remote type" << std::endl;
}
}

#if HAVE_SECURITY
Expand Down Expand Up @@ -401,6 +406,10 @@ int main(
});
}

std::cout << "Subscriber finished receiving samples" << std::endl;
char c;
std::cin >> c;

if (g_reader != nullptr)
{
g_subscriber->delete_datareader(g_reader);
Expand Down
42 changes: 32 additions & 10 deletions test/dds/communication/simple_communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,28 @@ def output_reader(proc, outq):
for line in iter(proc.stdout.readline, b''):
outq.put(line.decode('utf-8'))


barrier = threading.Barrier(2, timeout=30)
num_stop_signals = 0
run = True


def communication(monitor_proc, pid):
"""A"""
global num_stop_signals
global run
global barrier
outq = queue.Queue()
t = threading.Thread(target=output_reader, args=(monitor_proc,outq))
t.start()

run = True
try:
time.sleep(0.2)

while run:
try:
line = outq.get(block=False).rstrip()
print(line)

sys.stdout.flush()

Expand All @@ -92,26 +101,39 @@ def communication(monitor_proc, pid):
print("___" + pid + "___Creating subscriber___")
sys.stdout.flush()
subscriber1_proc = subprocess.Popen([subscriber_command, "--seed", pid]
+ (["--xmlfile", real_xml_file_sub] if real_xml_file_sub else []))

+ (["--xmlfile", real_xml_file_sub] if real_xml_file_sub else []),
stdin=subprocess.PIPE, stdout=subprocess.PIPE)

print("___" + pid + "___Creating publisher___")
sys.stdout.flush()
publisher_proc1 = subprocess.Popen([publisher_command, "--seed", pid, "--wait", "1"]
+ (["--xmlfile", real_xml_file_pub] if real_xml_file_pub else [])
+ extra_pub_args)

line = ""
while 'Subscriber finished receiving samples' != line:
line = subscriber1_proc.stdout.readline().decode('utf-8').rstrip()
print(line)
sys.stdout.flush()

print("___" + pid + "___barrier...___")
sys.stdout.flush()
barrier.wait()

print("___" + pid + "___subscriber1 communicate...___")
sys.stdout.flush()
publisher_proc1.communicate()
subscriber1_proc.communicate('a'.encode('utf-8'))

print("___" + pid + "___publisher1 communicate...___")
sys.stdout.flush()
subscriber1_proc.communicate()
publisher_proc1.communicate()

elif (line == ("Stop Monitor_" + pid)):
print("___" + pid + "___Stop Monitor___")
sys.stdout.flush()
run = False
num_stop_signals += 1
if 2 == num_stop_signals:
run = False

else:
print("___" + pid + '_ ' + line)
Expand All @@ -123,7 +145,7 @@ def communication(monitor_proc, pid):

time.sleep(0.1)
finally:
monitor_proc.terminate()
monitor_proc.communicate('a'.encode('utf-8'))
try:
monitor_proc.wait(timeout=0.2)
print("___" + pid + '== subprocess exited with rc =', monitor_proc.returncode)
Expand All @@ -138,10 +160,10 @@ def communication(monitor_proc, pid):
t.join()

monitor_proc_0 = subprocess.Popen([monitor_command, "--seed", str(os.getpid())],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

monitor_proc_1 = subprocess.Popen([monitor_command, "--seed", str(os.getpid() + 1)],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

t_0 = threading.Thread(target=communication, args=(monitor_proc_0,str(os.getpid())))
t_1 = threading.Thread(target=communication, args=(monitor_proc_1,str(os.getpid() + 1)))
Expand Down
Loading