<s> import uuid <EOL> import threading <EOL> from compactor . context import Context <EOL> from compactor . process import Process <EOL> import logging <EOL> logging . basicConfig ( level = logging . DEBUG ) <EOL> log = logging . getLogger ( __name__ ) <EOL> def test_simple_process ( ) : <EOL> parameter = [ ] <EOL> event = threading . Event ( ) <EOL> class DerpProcess ( Process ) : <EOL> def __init__ ( self , ** kw ) : <EOL> super ( DerpProcess , self ) . __init__ ( '<STR_LIT>' , ** kw ) <EOL> @ Process . install ( '<STR_LIT>' ) <EOL> def ping ( self , value ) : <EOL> parameter . append ( value ) <EOL> event . set ( ) <EOL> context = Context ( ) <EOL> context . start ( ) <EOL> derp = DerpProcess ( ) <EOL> pid = context . spawn ( derp ) <EOL> context . dispatch ( pid , '<STR_LIT>' , <NUM_LIT> ) <EOL> event . wait ( timeout = <NUM_LIT:1.0> ) <EOL> assert event . is_set ( ) <EOL> assert parameter == [ <NUM_LIT> ] <EOL> context . stop ( ) <EOL> MAX_TIMEOUT = <NUM_LIT:10> <EOL> def test_link_race_condition ( ) : <EOL> context1 = Context ( ) <EOL> context1 . start ( ) <EOL> context2 = Context ( ) <EOL> context2 . start ( ) <EOL> class Leader ( Process ) : <EOL> def __init__ ( self ) : <EOL> super ( Leader , self ) . __init__ ( '<STR_LIT>' ) <EOL> self . uuid = None <EOL> @ Process . install ( '<STR_LIT>' ) <EOL> def register ( self , from_pid , uuid ) : <EOL> log . debug ( '<STR_LIT>' % ( from_pid , uuid ) ) <EOL> self . send ( from_pid , '<STR_LIT>' , uuid ) <EOL> class Follower ( Process ) : <EOL> def __init__ ( self , leader ) : <EOL> super ( Follower , self ) . __init__ ( '<STR_LIT>' ) <EOL> self . leader = leader <EOL> self . uuid = uuid . uuid4 ( ) . bytes <EOL> self . registered = threading . Event ( ) <EOL> def initialize ( self ) : <EOL> super ( Follower , self ) . initialize ( ) <EOL> self . link ( self . leader . pid ) <EOL> self . send ( self . leader . pid , '<STR_LIT>' , self . uuid ) <EOL> @ Process . install ( '<STR_LIT>' ) <EOL> def registered ( self , from_pid , uuid ) : <EOL> log . debug ( '<STR_LIT>' % ( from_pid , uuid ) ) <EOL> assert uuid == self . uuid <EOL> assert from_pid == self . leader . pid <EOL> self . registered . set ( ) <EOL> leader = Leader ( ) <EOL> context1 . spawn ( leader ) <EOL> follower = Follower ( leader ) <EOL> context2 . spawn ( follower ) <EOL> follower . registered . wait ( timeout = MAX_TIMEOUT ) <EOL> assert follower . registered . is_set ( ) <EOL> context1 . stop ( ) <EOL> context2 . stop ( ) </s>
