11"""FSM Base tests."""
22
33import os
4- import queue
54import threading
65from datetime import timedelta
76from unittest import mock
@@ -337,17 +336,17 @@ def hacky_error_call(self, *args, **kwargs):
337336
338337def test_locking ():
339338 """Testing locking system."""
340- hold_triggered = queue . Queue ()
341- shutdown = queue . Queue ()
339+ hold_triggered = threading . Event ()
340+ shutdown = threading . Event ()
342341
343342 class TestFSM (FSM ):
344343 """Dumb class."""
345344
346345 # pylint: disable=no-self-use
347346 def hold (self ):
348347 """Hold the state machine."""
349- hold_triggered .put ( True )
350- shutdown .get ()
348+ hold_triggered .set ( )
349+ shutdown .wait ()
351350
352351 new = properties .State (events = [properties .Event ('Hold' , 'final_state' , commands = [hold ])])
353352 final_state = properties .FinalState ()
@@ -361,29 +360,29 @@ def lock_it_all():
361360 worker .start ()
362361
363362 # Hold until the machine is really locked.
364- hold_triggered .get (timeout = 1 )
363+ hold_triggered .wait (timeout = 1 )
365364
366365 with pytest .raises (TucoAlreadyLockedError ):
367366 with TestFSM (StateHolder ()):
368367 pass
369368
370- shutdown .put ( True )
369+ shutdown .set ( )
371370 worker .join ()
372371
373372
374373def test_locking_without_id ():
375374 """Make sure that items without id won't get locked."""
376- hold_triggered = queue . Queue ()
377- shutdown = queue . Queue ()
375+ hold_triggered = threading . Event ()
376+ shutdown = threading . Event ()
378377
379378 class TestFSM (FSM ):
380379 """Dumb class."""
381380
382381 # pylint: disable=no-self-use
383382 def hold (self ):
384383 """Hold the state machine."""
385- hold_triggered .put ( True )
386- shutdown .get ()
384+ hold_triggered .set ( )
385+ shutdown .wait ()
387386
388387 new = properties .State (events = [
389388 properties .Event ('Hold' , 'final_state' , commands = [hold ]),
@@ -403,20 +402,20 @@ def lock_it_all():
403402 worker .start ()
404403
405404 # Hold until the machine is really locked.
406- hold_triggered .get ()
405+ hold_triggered .wait ()
407406
408407 with TestFSM (state_holder ) as fsm :
409408 fsm .trigger ('Finish' )
410409 assert fsm .current_state == 'final_state'
411410
412- shutdown .put ( True )
411+ shutdown .set ( )
413412 worker .join ()
414413
415414
416415def test_redis_locking ():
417416 """Testing redis locking system."""
418- hold_triggered = queue . Queue ()
419- shutdown = queue . Queue ()
417+ hold_triggered = threading . Event ()
418+ shutdown = threading . Event ()
420419
421420 class ConfiguredRedisLock (RedisLock ):
422421 def __init__ (self , * args , ** kwargs ):
@@ -434,20 +433,20 @@ class TestFSM(FSM):
434433 def lock_it_all ():
435434 """Lock the state machine to test it."""
436435 with TestFSM (StateHolder ()):
437- hold_triggered .put ( True )
438- shutdown .get ()
436+ hold_triggered .set ( )
437+ shutdown .wait ()
439438
440439 worker = threading .Thread (target = lock_it_all , daemon = True )
441440 worker .start ()
442441
443442 # Hold until the machine is really locked.
444- hold_triggered .get (timeout = 1.5 ) # It it timeout it means that the thread broke somehow
443+ hold_triggered .wait (timeout = 1.5 ) # It it timeout it means that the thread broke somehow
445444
446445 with pytest .raises (TucoAlreadyLockedError ):
447446 with TestFSM (StateHolder ()):
448447 pass
449448
450- shutdown .put ( True )
449+ shutdown .set ( )
451450 worker .join ()
452451
453452
0 commit comments