#NEWLINE# @ mock . patch ( 'os.read' ) #NEWLINE# @ mock . patch ( 'select.poll' ) #NEWLINE# @ mock . patch ( 'ironic_python_agent.agent._time' ) #NEWLINE# @ mock . patch ( 'random.uniform' ) #NEWLINE# def test_heartbeat( self , mocked_uniform , mocked_time , mock_poll , mock_read ) : #NEWLINE# #INDENT# time_responses = [ ] #NEWLINE# uniform_responses = [ ] #NEWLINE# heartbeat_responses = [ ] #NEWLINE# poll_responses = [ ] #NEWLINE# expected_poll_calls = [ ] #NEWLINE# expected_poll_calls . append ( mock . call ( 0 ) ) #NEWLINE# poll_responses . append ( False ) #NEWLINE# heartbeat_responses . append ( 100 ) #NEWLINE# uniform_responses . append ( 0.5 ) #NEWLINE# time_responses . append ( 50 ) #NEWLINE# expected_poll_calls . append ( mock . call ( ( 1000 * 25.0 ) ) ) #NEWLINE# poll_responses . append ( False ) #NEWLINE# heartbeat_responses . append ( 180 ) #NEWLINE# uniform_responses . append ( 0.4 ) #NEWLINE# time_responses . append ( 80 ) #NEWLINE# expected_poll_calls . append ( mock . call ( ( 1000 * 20.0 ) ) ) #NEWLINE# poll_responses . append ( False ) #NEWLINE# heartbeat_responses . append ( Exception ( 'uh oh!' ) ) #NEWLINE# time_responses . append ( 125 ) #NEWLINE# uniform_responses . append ( 0.5 ) #NEWLINE# time_responses . append ( 125.5 ) #NEWLINE# expected_poll_calls . append ( mock . call ( ( 1000 * 25.0 ) ) ) #NEWLINE# poll_responses . append ( True ) #NEWLINE# mock_read . return_value = 'a' #NEWLINE# mocked_time . side_effect = time_responses #NEWLINE# mocked_uniform . side_effect = uniform_responses #NEWLINE# self . mock_agent . heartbeat_timeout = 50 #NEWLINE# self . heartbeater . api . heartbeat . side_effect = heartbeat_responses #NEWLINE# mock_poll . return_value . poll . side_effect = poll_responses #NEWLINE# self . heartbeater . run ( ) #NEWLINE# self . assertEqual ( expected_poll_calls , mock_poll . return_value . poll . call_args_list ) #NEWLINE# self . assertEqual ( 2.7 , mock_poll . heartbeater . error_delay )