<s> """<STR_LIT>""" <EOL> import unittest <EOL> from datetime import datetime , timedelta <EOL> import time <EOL> import thespian . test . helpers <EOL> from thespian . actors import * <EOL> from thespian . test import ActorSystemTestCase <EOL> wakeupAfterPeriod = timedelta ( seconds = <NUM_LIT> ) <EOL> sleepLongerThanWakeup = lambda : time . sleep ( <NUM_LIT> ) <EOL> sleepPartOfWakeupPeriod = lambda : time . sleep ( <NUM_LIT:0.1> ) <EOL> class RetryActor ( Actor ) : <EOL> def __init__ ( self ) : <EOL> self . _numWakeups = <NUM_LIT:0> <EOL> def receiveMessage ( self , msg , sender ) : <EOL> if "<STR_LIT>" == msg : <EOL> self . wakeupAfter ( wakeupAfterPeriod ) <EOL> elif isinstance ( msg , WakeupMessage ) : <EOL> self . _numWakeups += <NUM_LIT:1> <EOL> elif "<STR_LIT>" == msg : <EOL> self . send ( sender , self . _numWakeups ) <EOL> class TestASimpleSystem ( ActorSystemTestCase ) : <EOL> testbase = '<STR_LIT>' <EOL> scope = '<STR_LIT>' <EOL> def test_oneWakeup ( self ) : <EOL> aS = ActorSystem ( ) <EOL> waiter = aS . createActor ( RetryActor ) <EOL> self . assertEqual ( aS . ask ( waiter , '<STR_LIT>' , <NUM_LIT:1> ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( aS . ask ( waiter , '<STR_LIT>' , <NUM_LIT:1> ) , <NUM_LIT:0> ) <EOL> aS . tell ( waiter , '<STR_LIT>' ) <EOL> self . assertEqual ( aS . ask ( waiter , '<STR_LIT>' , <NUM_LIT:1> ) , <NUM_LIT:0> ) <EOL> sleepLongerThanWakeup ( ) <EOL> self . assertEqual ( aS . ask ( waiter , '<STR_LIT>' , <NUM_LIT:1> ) , <NUM_LIT:1> ) <EOL> def test_threeWakeupsInSequence ( self ) : <EOL> aS = ActorSystem ( ) <EOL> waiter = aS . createActor ( RetryActor ) <EOL> self . assertEqual ( aS . ask ( waiter , '<STR_LIT>' , <NUM_LIT:1> ) , <NUM_LIT:0> ) <EOL> aS . tell ( waiter , '<STR_LIT>' ) <EOL> self . assertEqual ( aS . ask ( waiter , '<STR_LIT>' , <NUM_LIT:1> ) , <NUM_LIT:0> ) <EOL> sleepLongerThanWakeup ( ) <EOL> self . assertEqual ( aS . ask ( waiter , '<STR_LIT>' , <NUM_LIT:1> ) , <NUM_LIT:1> ) <EOL> aS . tell ( waiter , '<STR_LIT>' ) <EOL> self . assertEqual ( aS . ask ( waiter , '<STR_LIT>' , <NUM_LIT:1> ) , <NUM_LIT:1> ) <EOL> sleepLongerThanWakeup ( ) <EOL> aS . tell ( waiter , '<STR_LIT>' ) <EOL> self . assertEqual ( aS . ask ( waiter , '<STR_LIT>' , <NUM_LIT:1> ) , <NUM_LIT:2> ) <EOL> sleepLongerThanWakeup ( ) <EOL> self . assertEqual ( aS . ask ( waiter , '<STR_LIT>' , <NUM_LIT:1> ) , <NUM_LIT:3> ) <EOL> def test_multipleWakeupsPending ( self ) : <EOL> aS = ActorSystem ( ) <EOL> waiter = aS . createActor ( RetryActor ) <EOL> self . assertEqual ( aS . ask ( waiter , '<STR_LIT>' , <NUM_LIT:1> ) , <NUM_LIT:0> ) <EOL> aS . tell ( waiter , '<STR_LIT>' ) <EOL> aS . tell ( waiter , '<STR_LIT>' ) <EOL> self . assertEqual ( aS . ask ( waiter , '<STR_LIT>' , <NUM_LIT:1> ) , <NUM_LIT:0> ) <EOL> sleepLongerThanWakeup ( ) <EOL> self . assertEqual ( aS . ask ( waiter , '<STR_LIT>' , <NUM_LIT:1> ) , <NUM_LIT:2> ) <EOL> aS . tell ( waiter , '<STR_LIT>' ) <EOL> sleepPartOfWakeupPeriod ( ) <EOL> aS . tell ( waiter , '<STR_LIT>' ) <EOL> sleepPartOfWakeupPeriod ( ) <EOL> aS . tell ( waiter , '<STR_LIT>' ) <EOL> sleepLongerThanWakeup ( ) <EOL> self . assertEqual ( aS . ask ( waiter , '<STR_LIT>' , <NUM_LIT:1> ) , <NUM_LIT:5> ) <EOL> def test_exitWithWakeupsPending ( self ) : <EOL> aS = ActorSystem ( ) <EOL> waiter = aS . createActor ( RetryActor ) <EOL> self . assertEqual ( aS . ask ( waiter , '<STR_LIT>' , <NUM_LIT:1> ) , <NUM_LIT:0> ) <EOL> aS . tell ( waiter , '<STR_LIT>' ) <EOL> sleepPartOfWakeupPeriod ( ) <EOL> aS . tell ( waiter , ActorExitRequest ( ) ) <EOL> self . assertTrue ( True ) <EOL> class TestMultiprocUDPSystem ( TestASimpleSystem ) : <EOL> testbase = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> self . setSystemBase ( '<STR_LIT>' ) <EOL> super ( TestMultiprocUDPSystem , self ) . setUp ( ) <EOL> class TestMultiprocTCPSystem ( TestASimpleSystem ) : <EOL> testbase = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> self . setSystemBase ( '<STR_LIT>' ) <EOL> super ( TestMultiprocTCPSystem , self ) . setUp ( ) <EOL> class TestMultiprocQueueSystem ( TestASimpleSystem ) : <EOL> testbase = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> self . setSystemBase ( '<STR_LIT>' ) <EOL> super ( TestMultiprocQueueSystem , self ) . setUp ( ) </s>
