4848# is received in order, or that OWNERSHIP works properly, etc...
4949MAX_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