Skip to content

Commit a58661c

Browse files
committed
Refs #13877. Robust the test
Signed-off-by: Ricardo González Moreno <[email protected]>
1 parent c250f18 commit a58661c

File tree

3 files changed

+47
-14
lines changed

3 files changed

+47
-14
lines changed

test/dds/communication/Monitor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,5 +691,7 @@ int main(
691691
// }
692692

693693
std::cerr << "Stop Monitor_" << seed << '\n';
694+
char c;
695+
std::cin >> c;
694696
return 0;
695697
}

test/dds/communication/Subscriber.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ class ParListener : public DomainParticipantListener
123123
return;
124124
}
125125

126+
g_qos.durability().kind = eprosima::fastdds::dds::TRANSIENT_LOCAL_DURABILITY_QOS;
127+
126128
g_reader = g_subscriber->create_datareader(
127129
g_topic,
128130
g_qos,
@@ -168,10 +170,13 @@ class ParListener : public DomainParticipantListener
168170
}
169171
};
170172

171-
participant->register_remote_type(
172-
type_information,
173-
type_name.to_string(),
174-
callback);
173+
if (eprosima::fastrtps::types::ReturnCode_t::RETCODE_OK != participant->register_remote_type(
174+
type_information,
175+
type_name.to_string(),
176+
callback))
177+
{
178+
std::cout << "ERROR: Cannot register remote type" << std::endl;
179+
}
175180
}
176181

177182
#if HAVE_SECURITY
@@ -401,6 +406,10 @@ int main(
401406
});
402407
}
403408

409+
std::cout << "Subscriber finished receiving samples" << std::endl;
410+
char c;
411+
std::cin >> c;
412+
404413
if (g_reader != nullptr)
405414
{
406415
g_subscriber->delete_datareader(g_reader);

test/dds/communication/simple_communication.py

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,28 @@ def output_reader(proc, outq):
6868
for line in iter(proc.stdout.readline, b''):
6969
outq.put(line.decode('utf-8'))
7070

71+
72+
barrier = threading.Barrier(2, timeout=30)
73+
num_stop_signals = 0
74+
run = True
75+
76+
7177
def communication(monitor_proc, pid):
7278
"""A"""
79+
global num_stop_signals
80+
global run
81+
global barrier
7382
outq = queue.Queue()
7483
t = threading.Thread(target=output_reader, args=(monitor_proc,outq))
7584
t.start()
7685

77-
run = True
7886
try:
7987
time.sleep(0.2)
80-
88+
8189
while run:
8290
try:
8391
line = outq.get(block=False).rstrip()
92+
print(line)
8493

8594
sys.stdout.flush()
8695

@@ -92,26 +101,39 @@ def communication(monitor_proc, pid):
92101
print("___" + pid + "___Creating subscriber___")
93102
sys.stdout.flush()
94103
subscriber1_proc = subprocess.Popen([subscriber_command, "--seed", pid]
95-
+ (["--xmlfile", real_xml_file_sub] if real_xml_file_sub else []))
96-
104+
+ (["--xmlfile", real_xml_file_sub] if real_xml_file_sub else []),
105+
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
106+
97107
print("___" + pid + "___Creating publisher___")
98108
sys.stdout.flush()
99109
publisher_proc1 = subprocess.Popen([publisher_command, "--seed", pid, "--wait", "1"]
100110
+ (["--xmlfile", real_xml_file_pub] if real_xml_file_pub else [])
101111
+ extra_pub_args)
102112

113+
line = ""
114+
while 'Subscriber finished receiving samples' != line:
115+
line = subscriber1_proc.stdout.readline().decode('utf-8').rstrip()
116+
print(line)
117+
sys.stdout.flush()
118+
119+
print("___" + pid + "___barrier...___")
120+
sys.stdout.flush()
121+
barrier.wait()
122+
103123
print("___" + pid + "___subscriber1 communicate...___")
104124
sys.stdout.flush()
105-
publisher_proc1.communicate()
125+
subscriber1_proc.communicate('a'.encode('utf-8'))
106126

107127
print("___" + pid + "___publisher1 communicate...___")
108128
sys.stdout.flush()
109-
subscriber1_proc.communicate()
129+
publisher_proc1.communicate()
110130

111131
elif (line == ("Stop Monitor_" + pid)):
112132
print("___" + pid + "___Stop Monitor___")
113133
sys.stdout.flush()
114-
run = False
134+
num_stop_signals += 1
135+
if 2 == num_stop_signals:
136+
run = False
115137

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

124146
time.sleep(0.1)
125147
finally:
126-
monitor_proc.terminate()
148+
monitor_proc.communicate('a'.encode('utf-8'))
127149
try:
128150
monitor_proc.wait(timeout=0.2)
129151
print("___" + pid + '== subprocess exited with rc =', monitor_proc.returncode)
@@ -138,10 +160,10 @@ def communication(monitor_proc, pid):
138160
t.join()
139161

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

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

146168
t_0 = threading.Thread(target=communication, args=(monitor_proc_0,str(os.getpid())))
147169
t_1 = threading.Thread(target=communication, args=(monitor_proc_1,str(os.getpid() + 1)))

0 commit comments

Comments
 (0)