test/test_slow_server.rb in rubydns-0.7.3 vs test/test_slow_server.rb in rubydns-0.8.0

- old
+ new

@@ -18,26 +18,28 @@ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -require 'helper' -require 'pathname' +require 'minitest/autorun' require 'rubydns' -require 'rubydns/resolver' -require 'rubydns/extensions/string' -class SlowServer < RExec::Daemon::Base +require 'process/daemon' + +class SlowServer < Process::Daemon SERVER_PORTS = [[:udp, '127.0.0.1', 5330], [:tcp, '127.0.0.1', 5330]] @@base_directory = File.dirname(__FILE__) - Name = Resolv::DNS::Name + def working_directory + File.join(__dir__, "tmp") + end + IN = Resolv::DNS::Resource::IN - - def self.run + + def startup RubyDNS::run_server(:listen => SERVER_PORTS) do match(/\.*.com/, IN::A) do |transaction| defer do |fiber| # No domain exists, after 2 seconds: EventMachine::Timer.new(2) do @@ -53,19 +55,22 @@ end end end end -class SlowServerTest < Test::Unit::TestCase +class SlowServerTest < MiniTest::Test def setup + SlowServer.controller output: File.open("/dev/null", "w") SlowServer.start end def teardown SlowServer.stop end + IN = Resolv::DNS::Resource::IN + def test_timeout start_time = Time.now end_time = nil got_response = false @@ -80,11 +85,11 @@ EventMachine::stop end end - assert (end_time - start_time) <= 2.5, "Response should fail within timeout period." + assert_operator end_time - start_time, :<=, 2.5, "Response should fail within timeout period." assert_equal RubyDNS::ResolutionFailure, got_response.class, "Response should be resolution failure." end def test_slow_request start_time = Time.now @@ -98,11 +103,11 @@ EventMachine::stop end end - assert (end_time - start_time) > 2.0 + assert_operator end_time - start_time, :>, 2.0, "Response should fail within timeout period." end def test_normal_request start_time = Time.now end_time = nil @@ -115,8 +120,8 @@ EventMachine::stop end end - assert (end_time - start_time) < 2.0 + assert_operator end_time - start_time, :<, 2.0, "Response should fail immediately" end end