#NEWLINE# def test_connection_refused( self ) : #NEWLINE# #INDENT# ( server_socket , port ) = bind_unused_port ( ) #NEWLINE# server_socket . close ( ) #NEWLINE# stream = IOStream ( socket . socket ( ) , self . io_loop ) #NEWLINE# self . connect_called = False #NEWLINE# def connect_callback( ) : #NEWLINE# #INDENT# self . connect_called = True #NEWLINE# #UNINDENT# stream . set_close_callback ( connect_callback . stop ) #NEWLINE# with ExpectLog ( gen_log , '.*' , required = False ) : #NEWLINE# #INDENT# stream . connect ( ( 'localhost' , port ) , connect_callback ) #NEWLINE# self . wait ( ) #NEWLINE# #UNINDENT# self . assertFalse ( self . connect_called ) #NEWLINE# self . assertTrue ( isinstance ( stream . error , socket . error ) , stream . error ) #NEWLINE# if ( sys . platform != 'cygwin' ) : #NEWLINE# #INDENT# _ERRNO_CONNREFUSED = ( errno . ECONNREFUSED , ) #NEWLINE# if hasattr ( errno , 'WSAECONNREFUSED' ) : #NEWLINE# #INDENT# _ERRNO_CONNREFUSED += ( errno . WSAECONNREFUSED , ) #NEWLINE# #UNINDENT# self . assertTrue ( ( stream . error . args [ 0 ] in _ERRNO_CONNREFUSED ) )