diff options
Diffstat (limited to 'spec/httpunix_spec.rb')
-rw-r--r-- | spec/httpunix_spec.rb | 53 |
1 files changed, 17 insertions, 36 deletions
diff --git a/spec/httpunix_spec.rb b/spec/httpunix_spec.rb index 77235e8..4c59340 100644 --- a/spec/httpunix_spec.rb +++ b/spec/httpunix_spec.rb @@ -1,6 +1,5 @@ require_relative 'spec_helper' require_relative '../lib/httpunix' -require 'webrick' describe URI::HTTPUNIX do describe :parse do @@ -14,47 +13,29 @@ describe URI::HTTPUNIX do end end - -# like WEBrick::HTTPServer, but listens on UNIX socket -class HTTPUNIXServer < WEBrick::HTTPServer - def listen(address, port) - socket = Socket.unix_server_socket(address) - socket.autoclose = false - server = UNIXServer.for_fd(socket.fileno) - socket.close - @listeners << server +describe Net::HTTPUNIX do + def tmp_socket_path + File.join(ROOT_PATH, 'tmp/test-socket') end - # Workaround: - # https://bugs.ruby-lang.org/issues/10956 - # Affecting Ruby 2.2 - # Fix for 2.2 is at https://github.com/ruby/ruby/commit/ab0a64e1 - # However, this doesn't work with 2.1. The following should work for both: - def start(&block) - @shutdown_pipe = IO.pipe - shutdown_pipe = @shutdown_pipe - super(&block) - end + before(:all) do + # "hello world" over unix socket server in background thread + FileUtils.mkdir_p(File.dirname(tmp_socket_path)) + @server = HTTPUNIXServer.new(BindAddress: tmp_socket_path) + @server.mount_proc '/' do |req, resp| + resp.body = "Hello World (at #{req.path})" + end - def cleanup_shutdown_pipe(shutdown_pipe) - @shutdown_pipe = nil - return if !shutdown_pipe - super(shutdown_pipe) - end -end + @webrick_thread = Thread.new { @server.start } -def tmp_socket_path - 'tmp/test-socket' -end + sleep(0.1) while @webrick_thread.alive? && @server.status != :Running + raise "Couldn't start HTTPUNIXServer" unless @server.status == :Running + end -describe Net::HTTPUNIX do - # "hello world" over unix socket server in background thread - FileUtils.mkdir_p(File.dirname(tmp_socket_path)) - server = HTTPUNIXServer.new(:BindAddress => tmp_socket_path) - server.mount_proc '/' do |req, resp| - resp.body = "Hello World (at #{req.path})" + after(:all) do + @server.shutdown if @server + @webrick_thread.join if @webrick_thread end - Thread.start { server.start } it "talks via HTTP ok" do VCR.turned_off do |