@@ -480,11 +480,13 @@ def calibrated_spin(built):
480480
481481def probe_during_call (call , probes , attempts = 3 ):
482482 """Run call() on the main thread while a worker applies each probe in a loop. Returns
483- (result, {probe_name: (BufferError count, other outcomes)}). Retries `attempts` times when a
484- probe never observed the call (machine too fast or too loaded)."""
483+ (result, {probe_name: (BufferError count, other outcomes, late successes)}). Retries `attempts`
484+ times when a probe never observed the call (machine too fast or too loaded). A late success is a
485+ probe that succeeded only after the call returned: it is not a failure, but its effect stays (an
486+ append left one more element), so callers that check sizes add it back (#401)."""
485487 for _ in range (attempts ):
486488 go , done = threading .Event (), threading .Event ()
487- seen = {name : [0 , []] for name in probes }
489+ seen = {name : [0 , [], 0 ] for name in probes }
488490
489491 def worker ():
490492 go .wait ()
@@ -504,6 +506,8 @@ def worker():
504506 # stays unset for far longer than this grace period.
505507 if not done .wait (0.05 ):
506508 seen [name ][1 ].append ("succeeded" )
509+ else :
510+ seen [name ][2 ] += 1
507511 return
508512 time .sleep (0.001 )
509513
@@ -533,7 +537,7 @@ def test_other_thread_release_and_append_get_bufferror_during_a_memoryview_call(
533537 assert result == float (n )
534538 assert seen ["release" ][0 ] > 0 and seen ["release" ][1 ] == [], seen
535539 assert seen ["append" ][0 ] > 0 and seen ["append" ][1 ] == [], seen
536- assert len (a ) == N # nothing resized under the call
540+ assert len (a ) == N + seen [ "append" ][ 2 ] # nothing resized under the call (#401)
537541 assert release_ok (v ) and can_resize (a ) # held only during the call
538542
539543
@@ -547,7 +551,8 @@ def test_other_thread_append_gets_bufferror_during_an_array_call(built):
547551 assert result == float (n )
548552 for name in ("append" , "extend" , "pop" ):
549553 assert seen [name ][0 ] > 0 and seen [name ][1 ] == [], (name , seen )
550- assert len (a ) == N
554+ # nothing resized under the call; a probe that succeeded after it returned stays applied (#401)
555+ assert len (a ) == N + seen ["append" ][2 ] + seen ["extend" ][2 ] - seen ["pop" ][2 ]
551556 assert can_resize (a )
552557
553558
0 commit comments