Sha256: 2a44227e2af07667d4a3074ec6b079565b0f971db7571a80c275e1c5687fd259

Contents?: true

Size: 1019 Bytes

Versions: 89

Compression:

Stored size: 1019 Bytes

Contents

require 'em_test_helper'
require 'socket'

class TestUnbindReason < Test::Unit::TestCase

  class StubConnection < EM::Connection
    attr_reader :error
    def unbind(reason = nil)
      @error = reason
      EM.stop
    end
  end

  def test_connect_timeout
    error = nil
    EM.run {
      conn = EM.connect 'google.com', 81, Module.new{ |m|
        m.send(:define_method, :unbind) do |reason|
          error = reason
          EM.stop
        end
      }
      conn.pending_connect_timeout = 0.1
    }
    assert_equal Errno::ETIMEDOUT, error
  end

  def test_connect_refused
    error = nil
    EM.run {
      EM.connect '127.0.0.1', 12388, Module.new{ |m|
        m.send(:define_method, :unbind) do |reason|
          error = reason
          EM.stop
        end
      }
    }
    assert_equal Errno::ECONNREFUSED, error
  end

  def test_optional_argument
    conn = nil
    EM.run {
      conn = EM.connect '127.0.0.1', 12388, StubConnection
    }
    assert_equal Errno::ECONNREFUSED, conn.error
  end
end

Version data entries

89 entries across 89 versions & 6 rubygems

Version Path
eventmachine-1.0.0.rc.2 tests/test_unbind_reason.rb
eventmachine-1.0.0.rc.1-x86-mswin32-60 tests/test_unbind_reason.rb
eventmachine-1.0.0.rc.1-x86-mingw32 tests/test_unbind_reason.rb
eventmachine-1.0.0.rc.1-java tests/test_unbind_reason.rb
eventmachine-1.0.0.rc.1 tests/test_unbind_reason.rb
eventmachine-le-1.1.0 tests/test_unbind_reason.rb
eventmachine-le-1.1.0.beta.2 tests/test_unbind_reason.rb
eventmachine-le-1.1.0.beta.1 tests/test_unbind_reason.rb
eventmachine-with-ipv6-1.0.0.beta.4.ipv6.0 tests/test_unbind_reason.rb