#NEWLINE# def test_get_running_pids( self ) : #NEWLINE# #INDENT# temp_files = ( ( 'var/run/test-server1.pid' , 1 ) , ( 'var/run/test-server2.pid' , 2 ) , ( 'var/run/test-server3.pid' , 3 ) , ( 'proc/1/cmdline' , 'swift-test-server' ) , ( 'proc/3/cmdline' , 'swift-another-server' ) ) #NEWLINE# with temptree ( * zip ( * temp_files ) ) as t : #NEWLINE# #INDENT# manager . RUN_DIR = os . path . join ( t , 'var/run' ) #NEWLINE# manager . PROC_DIR = os . path . join ( t , 'proc' ) #NEWLINE# server = manager . Server ( 'test-server' , run_dir = manager . RUN_DIR ) #NEWLINE# manager . os = MockOs ( [ 1 , 3 ] ) #NEWLINE# running_pids = server . get_running_pids ( ) #NEWLINE# self . assertEqual ( len ( running_pids ) , 1 ) #NEWLINE# self . assertTrue ( ( 1 in running_pids ) ) #NEWLINE# self . assertTrue ( ( 2 not in running_pids ) ) #NEWLINE# self . assertTrue ( ( 3 not in running_pids ) ) #NEWLINE# self . assertTrue ( os . path . exists ( os . path . join ( manager . RUN_DIR , 'test-server1.pid' ) ) ) #NEWLINE# pid_two = self . join_swift_dir ( 'test-server2.pid' ) #NEWLINE# self . assertFalse ( os . path . exists ( pid_two ) ) #NEWLINE# pid_three = self . join_swift_dir ( 'test-server3.pid' ) #NEWLINE# self . assertFalse ( os . path . exists ( pid_three ) ) #NEWLINE# manager . os = MockOs ( [ ] ) #NEWLINE# running_pids = server . get_running_pids ( ) #NEWLINE# self . assertFalse ( running_pids ) #NEWLINE# pid_one = self . join_run_dir ( 'test-server1.pid' ) #NEWLINE# self . assertFalse ( os . path . exists ( pid_one ) ) #NEWLINE# all_pids = os . listdir ( manager . RUN_DIR ) #NEWLINE# self . assertEqual ( len ( all_pids ) , 0 ) #NEWLINE# #UNINDENT# pid_files = ( ( 'thing-doer.pid' , 1 ) , ( 'thing-sayer.pid' , 2 ) , ( 'other-doer.pid' , 3 ) , ( 'other-sayer.pid' , 4 ) ) #NEWLINE# ( files , pids ) = zip ( * pid_files ) #NEWLINE# with temptree ( files , pids ) as t : #NEWLINE# #INDENT# manager . RUN_DIR = t #NEWLINE# manager . os = MockOs ( pids ) #NEWLINE# server = manager . Server ( 'thing-doer' , run_dir = t ) #NEWLINE# running_pids = server . get_running_pids ( ) #NEWLINE# self . assertEqual ( len ( running_pids ) , 1 ) #NEWLINE# self . assertTrue ( ( 1 in running_pids ) ) #NEWLINE# for n in ( 2 , 3 , 4 ) : #NEWLINE# #INDENT# self . assertTrue ( ( n not in running_pids ) ) #NEWLINE# #UNINDENT# manager . os = MockOs ( [ 1 ] ) #NEWLINE# running_pids = server . get_running_pids ( ) #NEWLINE# for f in ( 'thing-sayer.pid' , 'other-doer.pid' , 'other-sayer.pid' ) : #NEWLINE# #INDENT# self . assertTrue ( os . path . exists , os . path . join ( t , f ) ) #NEWLINE# #UNINDENT# for server_name in ( 'thing-sayer' , 'other-doer' , 'other-sayer' ) : #NEWLINE# #INDENT# server = manager . Server ( server_name , run_dir = t ) #NEWLINE# running_pids = server . get_running_pids ( ) #NEWLINE# self . assertFalse ( running_pids ) #NEWLINE# #UNINDENT# all_pids = os . listdir ( t ) #NEWLINE# self . assertEqual ( len ( all_pids ) , 1 ) #NEWLINE# self . assertTrue ( os . path . exists ( os . path . join ( t , 'thing-doer.pid' ) ) )