#NEWLINE# def test_contextual_lifecycle( ) : #NEWLINE# #INDENT# events = set ( ) #NEWLINE# class Container ( object ) : #NEWLINE# #INDENT# def __init__( self , service_cls , worker_ctx_cls , config ) : #NEWLINE# #INDENT# self . service_name = service_cls . __name__ #NEWLINE# self . service_cls = service_cls #NEWLINE# self . worker_ctx_cls = worker_ctx_cls #NEWLINE# #UNINDENT# def start( self ) : #NEWLINE# #INDENT# events . add ( ( 'start' , self . service_cls . name , self . service_cls ) ) #NEWLINE# #UNINDENT# def stop( self ) : #NEWLINE# #INDENT# events . add ( ( 'stop' , self . service_cls . name , self . service_cls ) ) #NEWLINE# #UNINDENT# def kill( self , exc = None ) : #NEWLINE# #INDENT# events . add ( ( 'kill' , self . service_cls . name , self . service_cls ) ) #NEWLINE# #UNINDENT# def wait( self ) : #NEWLINE# #INDENT# events . add ( ( 'wait' , self . service_cls . name , self . service_cls ) ) #NEWLINE# #UNINDENT# #UNINDENT# config = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# with run_services ( config , TestService1 , TestService2 , container_cls = Container ) : #NEWLINE# #INDENT# assert ( events == { ( 'start' , 'foobar_1' , TestService1 ) , ( 'start' , 'foobar_2' , TestService2 ) } ) #NEWLINE# #UNINDENT# assert ( events == { ( 'start' , 'foobar_1' , TestService1 ) , ( 'start' , 'foobar_2' , TestService2 ) , ( 'stop' , 'foobar_1' , TestService1 ) , ( 'stop' , 'foobar_2' , TestService2 ) } ) #NEWLINE# events = set ( ) #NEWLINE# with run_services ( config , TestService1 , TestService2 , container_cls = Container , kill_on_exit = True ) : #NEWLINE# #INDENT# assert ( events == { ( 'start' , 'foobar_1' , TestService1 ) , ( 'start' , 'foobar_2' , TestService2 ) } ) #NEWLINE# #UNINDENT# assert ( events == { ( 'kill' , 'foobar_1' , TestService1 ) , ( 'kill' , 'foobar_2' , TestService2 ) , ( 'start' , 'foobar_1' , TestService1 ) , ( 'start' , 'foobar_2' , TestService2 ) } )