#NEWLINE# @ mock . patch ( 'time.sleep' , autospec = True ) #NEWLINE# @ mock . patch ( 'time.time' , autospec = True ) #NEWLINE# @ mock . patch ( 'paasta_tools.cli.cmds.local_run.run_healthcheck_on_container' , autospec = True ) #NEWLINE# def test_simulate_healthcheck_on_service_enabled_honors_grace_period( mock_run_healthcheck_on_container , mock_time , mock_sleep , capsys ) : #NEWLINE# #INDENT# mock_run_healthcheck_on_container . side_effect = iter ( [ ( False , 'noop' ) , ( False , 'noop' ) , ( True , 'noop' ) ] ) #NEWLINE# mock_time . side_effect = [ 0 , 1 , 5 ] #NEWLINE# mock_docker_client = mock . MagicMock ( spec_set = docker . Client ) #NEWLINE# mock_service_manifest = MarathonServiceConfig ( service = 'fake_name' , cluster = 'fake_cluster' , instance = 'fake_instance' , config_dict = { #NEWLINE# #INDENT# 'healthcheck_grace_period_seconds' : 2 , #NEWLINE# #UNINDENT# } , branch_dict = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# fake_container_id = 'fake_container_id' #NEWLINE# fake_mode = 'http' #NEWLINE# fake_url = 'http://fake_host/fake_status_path' #NEWLINE# assert simulate_healthcheck_on_service ( mock_service_manifest , mock_docker_client , fake_container_id , capsys , fake_url , True ) #NEWLINE# assert ( mock_sleep . call_count == 2 ) #NEWLINE# assert ( mock_run_healthcheck_on_container . call_count == 3 ) #NEWLINE# ( out , _ ) = capsys . readouterr ( ) #NEWLINE# assert ( out . count ( 'Healthcheck failed! (disregarded due to grace period)' ) == 1 ) #NEWLINE# assert ( out . count ( 'Healthcheck failed! (Attempt' ) == 1 ) #NEWLINE# assert ( out . count ( 'Healthcheck succeeded!' ) == 1 )