test/test_http.rb in zold-0.16.17 vs test/test_http.rb in zold-0.16.18

- old
+ new

@@ -23,10 +23,11 @@ require 'minitest/autorun' require 'tmpdir' require 'uri' require 'webmock/minitest' require 'zold/score' +require_relative 'test__helper' require_relative '../lib/zold/http' # Http test. # Author:: Yegor Bugayenko (yegor256@gmail.com) # Copyright:: Copyright (c) 2018 Yegor Bugayenko @@ -74,9 +75,29 @@ sleep 100 { body: 'This should never be returned!' } end res = Zold::Http.new(uri: 'http://the-fake-host-99/').get assert_equal('599', res.code) + end + + def test_doesnt_terminate_on_long_call + require 'random-port' + WebMock.allow_net_connect! + RandomPort::Pool::SINGLETON.acquire do |port| + thread = Thread.start do + server = TCPServer.new(port) + loop do + client = server.accept + sleep 1 + client.puts("HTTP/1.1 200 OK\nContent-Length: 4\n\nGood") + client.close + end + end + res = Zold::Http.new(uri: "http://localhost:#{port}/").get(timeout: 2) + assert_equal('200', res.code, res) + thread.kill + thread.join + end end def test_sends_valid_version_header stub_request(:get, 'http://some-host-3/') .with(headers: { 'X-Zold-Version' => Zold::VERSION })