@@ -353,13 +353,12 @@ def test_cancellation_while_waiting_for_write_lock(self):
353
353
writer3_d , _ = self ._start_nonblocking_writer (rwlock , key , "write 3 completed" )
354
354
self .assertFalse (writer3_d .called )
355
355
356
- # 5. The second writer is cancelled.
356
+ # 5. The second writer is cancelled, but continues waiting for the lock .
357
357
# The reader, first writer and third writer should not be cancelled.
358
358
# The first writer should still be waiting on the reader.
359
- # The third writer should still be waiting, even though the second writer has
360
- # been cancelled.
359
+ # The third writer should still be waiting on the second writer.
361
360
writer2_d .cancel ()
362
- self .failureResultOf (writer2_d , CancelledError )
361
+ self .assertNoResult (writer2_d )
363
362
self .assertFalse (reader_d .called , "Reader was unexpectedly cancelled" )
364
363
self .assertFalse (writer1_d .called , "First writer was unexpectedly cancelled" )
365
364
self .assertFalse (
@@ -370,9 +369,10 @@ def test_cancellation_while_waiting_for_write_lock(self):
370
369
371
370
# 6. Unblock the reader, which should complete.
372
371
# The first writer should be given the lock and block.
373
- # The third writer should still be waiting.
372
+ # The third writer should still be waiting on the second writer .
374
373
unblock_reader .callback (None )
375
374
self .assertEqual ("read completed" , self .successResultOf (reader_d ))
375
+ self .assertNoResult (writer2_d )
376
376
self .assertFalse (
377
377
writer3_d .called ,
378
378
"Third writer was unexpectedly given the lock before the first writer "
@@ -383,7 +383,11 @@ def test_cancellation_while_waiting_for_write_lock(self):
383
383
unblock_writer1 .callback (None )
384
384
self .assertEqual ("write 1 completed" , self .successResultOf (writer1_d ))
385
385
386
- # 8. The third writer should take the lock and complete.
386
+ # 8. The second writer should take the lock and release it immediately, since it
387
+ # has been cancelled.
388
+ self .failureResultOf (writer2_d , CancelledError )
389
+
390
+ # 9. The third writer should take the lock and complete.
387
391
self .assertTrue (
388
392
writer3_d .called , "Third writer is stuck waiting for a cancelled writer"
389
393
)
0 commit comments