VaKeR CYBER ARMY
Logo of a company Server : Apache/2.4.41 (Ubuntu)
System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Directory :  /var/lib/gems/2.5.0/gems/eventmachine-1.2.7/tests/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/lib/gems/2.5.0/gems/eventmachine-1.2.7/tests/test_resolver.rb
require 'em_test_helper'

class TestResolver < Test::Unit::TestCase
  def test_nameserver
    assert_kind_of(String, EM::DNS::Resolver.nameserver)
  end

  def test_nameservers
    assert_kind_of(Array, EM::DNS::Resolver.nameservers)
  end

  def test_hosts
    assert_kind_of(Hash, EM::DNS::Resolver.hosts)

    # Make sure that blank or comment lines are skipped
    refute(EM::DNS::Resolver.hosts.include? nil)
  end

  def test_a
    pend('FIXME: this test is broken on Windows') if windows?

    EM.run {
      d = EM::DNS::Resolver.resolve "example.com"
      d.errback { assert false }
      d.callback { |r|
        assert r
        EM.stop
      }
    }
  end

  def test_bad_host
    EM.run {
      d = EM::DNS::Resolver.resolve "asdfasasdf"
      d.callback { assert false }
      d.errback  { assert true; EM.stop }
    }
  end

  def test_garbage
    assert_raises( ArgumentError ) {
      EM.run {
        EM::DNS::Resolver.resolve 123
      }
    }
  end

  # There isn't a public DNS entry like 'example.com' with an A rrset
  def test_a_pair
    pend('FIXME: this test is broken on Windows') if windows?

    EM.run {
      d = EM::DNS::Resolver.resolve "yahoo.com"
      d.errback { |err| assert false, "failed to resolve yahoo.com: #{err}" }
      d.callback { |r|
        assert_kind_of(Array, r)
        assert r.size > 1, "returned #{r.size} results: #{r.inspect}"
        EM.stop
      }
    }
  end

  def test_localhost
    pend('FIXME: this test is broken on Windows') if windows?

    EM.run {
      d = EM::DNS::Resolver.resolve "localhost"
      d.errback { assert false }
      d.callback { |r|
        assert_include(["127.0.0.1", "::1"], r.first)
        assert_kind_of(Array, r)

        EM.stop
      }
    }
  end

  def test_timer_cleanup
    pend('FIXME: this test is broken on Windows') if windows?

    EM.run {
      d = EM::DNS::Resolver.resolve "example.com"
      d.errback { |err| assert false, "failed to resolve example.com: #{err}" }
      d.callback { |r|
        # This isn't a great test, but it's hard to get more canonical
        # confirmation that the timer is cancelled
        assert_nil(EM::DNS::Resolver.socket.instance_variable_get(:@timer))

        EM.stop
      }
    }
  end

  def test_failure_timer_cleanup
    EM.run {
      d = EM::DNS::Resolver.resolve "asdfasdf"
      d.callback { assert false }
      d.errback {
        assert_nil(EM::DNS::Resolver.socket.instance_variable_get(:@timer))

        EM.stop
      }
    }
  end
end

VaKeR 2022