Skip to content

Commit 8a23c9b

Browse files
Improve ownership tests (#55)
* Add `last_sample_saved` to `run_publisher_shape_main`. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Add `last_sample_saved` to `run_subscriber_shape_main`. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Pass `last_sample_saved` to check function. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Break the loop in `test_ownership_receivers` when the last sample from a publisher has been processed. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Add some documentation Signed-off-by: Miguel Company <miguelcompany@eprosima.com> --------- Signed-off-by: Miguel Company <miguelcompany@eprosima.com>
1 parent b57f91e commit 8a23c9b

File tree

3 files changed

+60
-11
lines changed

3 files changed

+60
-11
lines changed

interoperability_report.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def run_subscriber_shape_main(
3333
produced_code_index: int,
3434
subscriber_index: int,
3535
samples_sent: "list[multiprocessing.Queue]",
36+
last_sample_saved: "list[multiprocessing.Queue]",
3637
verbosity: bool,
3738
timeout: int,
3839
file: tempfile.TemporaryFile,
@@ -56,6 +57,9 @@ def run_subscriber_shape_main(
5657
samples_sent <<in>>: list of multiprocessing Queues with the samples
5758
the Publishers send. Element 1 of the list is for
5859
Publisher 1, etc.
60+
last_sample_saved <<in>>: list of multiprocessing Queues with the last
61+
sample saved on samples_sent for each Publisher. Element 1 of
62+
the list is for Publisher 1, etc.
5963
verbosity <<in>>: print debug information.
6064
timeout <<in>>: time pexpect waits until it matches a pattern.
6165
file <<inout>>: temporal file to save shape_main application output.
@@ -157,7 +161,7 @@ def run_subscriber_shape_main(
157161
# to the Subscriber. By default it does not check
158162
# anything and returns ReturnCode.OK.
159163
produced_code[produced_code_index] = check_function(
160-
child_sub, samples_sent, timeout)
164+
child_sub, samples_sent, last_sample_saved, timeout)
161165

162166
subscriber_finished.set() # set subscriber as finished
163167
log_message(f'Subscriber {subscriber_index}: Waiting for Publishers to '
@@ -176,6 +180,7 @@ def run_publisher_shape_main(
176180
produced_code_index: int,
177181
publisher_index: int,
178182
samples_sent: multiprocessing.Queue,
183+
last_sample_saved: multiprocessing.Queue,
179184
verbosity: bool,
180185
timeout: int,
181186
file: tempfile.TemporaryFile,
@@ -197,6 +202,8 @@ def run_publisher_shape_main(
197202
publisher it is 1, for the second 2, etc.
198203
samples_sent <<out>>: this variable contains the samples
199204
the Publisher sends.
205+
last_sample_saved <<out>>: this variable contains the last sample
206+
saved on samples_sent.
200207
verbosity <<in>>: print debug information.
201208
timeout <<in>>: time pexpect waits until it matches a pattern.
202209
file <<inout>>: temporal file to save shape_main application output.
@@ -296,12 +303,14 @@ def run_publisher_shape_main(
296303
produced_code[produced_code_index] = ReturnCode.OK
297304
log_message(f'Publisher {publisher_index}: Sending '
298305
'samples', verbosity)
306+
last_sample = ''
299307
for x in range(0, MAX_SAMPLES_SAVED, 1):
300308
# At this point, at least one sample has been printed
301309
# Therefore, that sample is added to samples_sent.
302310
pub_string = re.search('[0-9]+ [0-9]+ \[[0-9]+\]',
303311
child_pub.before + child_pub.after)
304-
samples_sent.put(pub_string.group(0))
312+
last_sample = pub_string.group(0)
313+
samples_sent.put(last_sample)
305314
index = child_pub.expect([
306315
'\[[0-9]+\]', # index = 0
307316
'on_offered_deadline_missed()', # index = 1
@@ -314,6 +323,7 @@ def run_publisher_shape_main(
314323
elif index == 2:
315324
produced_code[produced_code_index] = ReturnCode.DATA_NOT_SENT
316325
break
326+
last_sample_saved.put(last_sample)
317327
else:
318328
produced_code[produced_code_index] = ReturnCode.OK
319329

@@ -395,6 +405,7 @@ def run_test(
395405
return_codes = manager.list(range(num_entities))
396406
samples_sent = [] # used for storing the samples the Publishers send.
397407
# It is a list with one Queue for each Publisher.
408+
last_sample_saved = [] # used for storing the last value sent by each Publisher.
398409

399410
# list of multiprocessing Events used as semaphores to control the end of
400411
# the processes, one for each entity.
@@ -419,6 +430,7 @@ def run_test(
419430
if ('-P ' in element or element.endswith('-P')):
420431
publishers_finished.append(multiprocessing.Event())
421432
samples_sent.append(multiprocessing.Queue())
433+
last_sample_saved.append(multiprocessing.Queue())
422434
elif ('-S ' in element or element.endswith('-S')):
423435
subscribers_finished.append(multiprocessing.Event())
424436
else:
@@ -438,6 +450,7 @@ def run_test(
438450
'produced_code_index':i,
439451
'publisher_index':publisher_number+1,
440452
'samples_sent':samples_sent[publisher_number],
453+
'last_sample_saved':last_sample_saved[publisher_number],
441454
'verbosity':verbosity,
442455
'timeout':timeout,
443456
'file':temporary_file[i],
@@ -461,6 +474,7 @@ def run_test(
461474
'produced_code_index':i,
462475
'subscriber_index':subscriber_number+1,
463476
'samples_sent':samples_sent,
477+
'last_sample_saved':last_sample_saved,
464478
'verbosity':verbosity,
465479
'timeout':timeout,
466480
'file':temporary_file[i],

rtps_test_utilities.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@ def remove_ansi_colors(text):
5050
cleaned_str = ansi_escape.sub('', text)
5151
return cleaned_str
5252

53-
def no_check(child_sub, samples_sent, timeout):
53+
def no_check(child_sub, samples_sent, last_sample_saved, timeout):
5454
return ReturnCode.OK

test_suite.py

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
# is received in order, or that OWNERSHIP works properly, etc...
4949
MAX_SAMPLES_READ = 500
5050

51-
def test_ownership_receivers(child_sub, samples_sent, timeout):
51+
def test_ownership_receivers(child_sub, samples_sent, last_sample_saved, timeout):
5252

5353
"""
5454
This function is used by test cases that have two publishers and one subscriber.
@@ -63,6 +63,9 @@ def test_ownership_receivers(child_sub, samples_sent, timeout):
6363
samples_sent: list of multiprocessing Queues with the samples
6464
the publishers send. Element 1 of the list is for
6565
publisher 1, etc.
66+
last_sample_saved: list of multiprocessing Queues with the last
67+
sample saved on samples_sent for each Publisher. Element 1 of
68+
the list is for Publisher 1, etc.
6669
timeout: time pexpect waits until it matches a pattern.
6770
6871
This functions assumes that the subscriber has already received samples
@@ -76,6 +79,9 @@ def test_ownership_receivers(child_sub, samples_sent, timeout):
7679
list_data_received_first = []
7780
max_samples_received = MAX_SAMPLES_READ
7881
samples_read = 0
82+
list_samples_processed = []
83+
last_first_sample = '';
84+
last_second_sample = '';
7985

8086
while(samples_read < max_samples_received):
8187
# take the topic, color, position and size of the ShapeType.
@@ -110,16 +116,39 @@ def test_ownership_receivers(child_sub, samples_sent, timeout):
110116
except queue.Empty:
111117
pass
112118

119+
# Take the last sample published by each publisher from their queues
120+
# ('last_sample_saved[i]') and save them local variables.
121+
try:
122+
last_first_sample = last_sample_saved[0].get(block=False)
123+
except queue.Empty:
124+
pass
125+
126+
try:
127+
last_second_sample = last_sample_saved[1].get(block=False)
128+
except queue.Empty:
129+
pass
130+
113131
# Determine to which publisher the current sample belong to
114132
if sub_string.group(0) in list_data_received_second:
115133
current_sample_from_publisher = 2
116134
elif sub_string.group(0) in list_data_received_first:
117135
current_sample_from_publisher = 1
118136
else:
119-
# If the sample is not in any queue, wait a bit and continue
137+
# If the sample is not in any queue, break the loop if the
138+
# the last sample for any publisher has already been processed.
139+
if last_first_sample in list_samples_processed:
140+
break
141+
if last_second_sample in list_samples_processed:
142+
break
143+
print(f'Last samples: {last_first_sample}, {last_second_sample}')
144+
# Otherwise, wait a bit and continue
120145
time.sleep(0.1)
121146
continue
122147

148+
# Keep all samples processed in a single list, so we can check whether
149+
# the last sample published by any publisher has already been processed
150+
list_samples_processed.append(sub_string.group(0))
151+
123152
# If the app hit this point, it is because the previous subscriber
124153
# sample has been already read. Then, we can process the next sample
125154
# read by the subscriber.
@@ -172,7 +201,7 @@ def test_ownership_receivers(child_sub, samples_sent, timeout):
172201
print(f'Samples read: {samples_read}')
173202
return ReturnCode.RECEIVING_FROM_ONE
174203

175-
def test_color_receivers(child_sub, samples_sent, timeout):
204+
def test_color_receivers(child_sub, samples_sent, last_sample_saved, timeout):
176205

177206
"""
178207
This function is used by test cases that have two publishers and one
@@ -182,6 +211,7 @@ def test_color_receivers(child_sub, samples_sent, timeout):
182211
183212
child_sub: child program generated with pexpect
184213
samples_sent: not used
214+
last_sample_saved: not used
185215
timeout: time pexpect waits until it matches a pattern.
186216
"""
187217
sub_string = re.search('\w\s+(\w+)\s+[0-9]+ [0-9]+ \[[0-9]+\]',
@@ -217,13 +247,14 @@ def test_color_receivers(child_sub, samples_sent, timeout):
217247
print(f'Samples read: {samples_read}')
218248
return ReturnCode.RECEIVING_FROM_ONE
219249

220-
def test_reliability_order(child_sub, samples_sent, timeout):
250+
def test_reliability_order(child_sub, samples_sent, last_sample_saved, timeout):
221251
"""
222252
This function tests reliability, it checks whether the subscriber receives
223253
the samples in order.
224254
225255
child_sub: child program generated with pexpect
226256
samples_sent: not used
257+
last_sample_saved: not used
227258
timeout: not used
228259
"""
229260

@@ -267,7 +298,7 @@ def test_reliability_order(child_sub, samples_sent, timeout):
267298
return produced_code
268299

269300

270-
def test_reliability_no_losses(child_sub, samples_sent, timeout):
301+
def test_reliability_no_losses(child_sub, samples_sent, last_sample_saved, timeout):
271302
"""
272303
This function tests RELIABLE reliability, it checks whether the subscriber
273304
receives the samples in order and with no losses.
@@ -276,6 +307,7 @@ def test_reliability_no_losses(child_sub, samples_sent, timeout):
276307
samples_sent: list of multiprocessing Queues with the samples
277308
the publishers send. Element 1 of the list is for
278309
publisher 1, etc.
310+
last_sample_saved: not used
279311
timeout: time pexpect waits until it matches a pattern.
280312
"""
281313

@@ -352,7 +384,7 @@ def test_reliability_no_losses(child_sub, samples_sent, timeout):
352384
return produced_code
353385

354386

355-
def test_durability_volatile(child_sub, samples_sent, timeout):
387+
def test_durability_volatile(child_sub, samples_sent, last_sample_saved, timeout):
356388
"""
357389
This function tests the volatile durability, it checks that the sample the
358390
subscriber receives is not the first one. The publisher application sends
@@ -365,6 +397,7 @@ def test_durability_volatile(child_sub, samples_sent, timeout):
365397
366398
child_sub: child program generated with pexpect
367399
samples_sent: not used
400+
last_sample_saved: not used
368401
timeout: not used
369402
"""
370403

@@ -387,7 +420,7 @@ def test_durability_volatile(child_sub, samples_sent, timeout):
387420

388421
return produced_code
389422

390-
def test_durability_transient_local(child_sub, samples_sent, timeout):
423+
def test_durability_transient_local(child_sub, samples_sent, last_sample_saved, timeout):
391424
"""
392425
This function tests the TRANSIENT_LOCAL durability, it checks that the
393426
sample the subscriber receives is the first one. The publisher application
@@ -396,6 +429,7 @@ def test_durability_transient_local(child_sub, samples_sent, timeout):
396429
397430
child_sub: child program generated with pexpect
398431
samples_sent: not used
432+
last_sample_saved: not used
399433
timeout: not used
400434
"""
401435

@@ -416,14 +450,15 @@ def test_durability_transient_local(child_sub, samples_sent, timeout):
416450
return produced_code
417451

418452

419-
def test_deadline_missed(child_sub, samples_sent, timeout):
453+
def test_deadline_missed(child_sub, samples_sent, last_sample_saved, timeout):
420454
"""
421455
This function tests whether the subscriber application misses the requested
422456
deadline or not. This is needed in case the subscriber application receives
423457
some samples and then missed the requested deadline.
424458
425459
child_sub: child program generated with pexpect
426460
samples_sent: not used
461+
last_sample_saved: not used
427462
timeout: time pexpect waits until it matches a pattern
428463
"""
429464

0 commit comments

Comments
 (0)