features/support/env.rb in httpthumbnailer-0.3.1 vs features/support/env.rb in httpthumbnailer-1.0.0

- old
+ new

@@ -5,17 +5,16 @@ $stderr.puts e.message $stderr.puts "Run `bundle install` to install missing gems" exit e.status_code end -$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib') require 'rspec/expectations' +require 'multipart_parser/reader' require 'daemon' require 'timeout' require 'httpclient' -require 'httpthumbnailer/multipart_response' require "open3" require "thread" require 'RMagick' def gem_dir @@ -41,32 +40,40 @@ when 'third' then 2 else fail "add more parts?" end end - -def get(url) - HTTPClient.new.get_content(url) +def http_client + client = HTTPClient.new + #client.debug_dev = STDOUT + client end +@@running_cmd = {} def start_server(cmd, pid_file, log_file, test_url) - stop_server(pid_file) + if @@running_cmd[pid_file] + return if @@running_cmd[pid_file] == cmd + stop_server(pid_file) + end fork do Daemon.daemonize(pid_file, log_file) + log_file = Pathname.new(log_file) + log_file.truncate(0) if log_file.exist? exec(cmd) end - Process.wait + @@running_cmd[pid_file] = cmd + ppid = Process.pid at_exit do stop_server(pid_file) if Process.pid == ppid end - Timeout.timeout(20) do + Timeout.timeout(6) do begin - get test_url + http_client.get_content test_url rescue Errno::ECONNREFUSED sleep 0.1 retry end end @@ -74,10 +81,11 @@ def stop_server(pid_file) pid_file = Pathname.new(pid_file) return unless pid_file.exist? + STDERR.puts http_client.get_content("http://localhost:3100/stats") pid = pid_file.read.strip.to_i Timeout.timeout(20) do begin loop do @@ -86,7 +94,12 @@ end rescue Errno::ESRCH pid_file.unlink end end +end + +After do |scenario| + step 'there should be no leaked images' + step 'there should be maximum 3 images loaded during single request' end