Commit
- introduced separate task for acceptance tests - split acceptance scenario into two separate - moved units to test/unit/ directory - declare default driver in test user - sleep in tests if for the weak
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
require 'rubygems' | ||
require 'ffi-rzmq' | ||
require 'multi_json' | ||
require 'tnetstring' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,21 @@ | ||
require 'acceptance_helper' | ||
require 'test_helper' | ||
|
||
module M2R | ||
class AcceptanceTest < MiniTest::Unit::TestCase | ||
include ProcessHelper | ||
|
||
def test_requests | ||
pid = Process.spawn("bundle exec foreman start --procfile=example/Procfile", pgroup: true, out: "/dev/null", err: "/dev/null") | ||
sleep(1) | ||
user = TestUser.new(:driver => :mechanize) | ||
def test_rack_example | ||
user = TestUser.new | ||
user.visit("/handler") | ||
user.see!("SENDER", "PATH", "HEADERS", "x-forwarded-for", "x-forwarded-for", "BODY") | ||
end | ||
|
||
def test_handler_example | ||
user = TestUser.new | ||
user.visit("/rack") | ||
assert user.find("pre").text.include?(" {{{{{{ { ( ( ( ( (-----:=") | ||
|
||
user.click_on("flip!") | ||
assert user.find("pre").text.include?("=:-----( ( ( ( ( { {{{{{{") | ||
ensure | ||
Process.kill("SIGTERM", pid) if pid | ||
sleep(1) | ||
end | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,5 @@ | ||
require 'test_helper' | ||
require 'bbq/test' | ||
require 'support/test_user' | ||
require 'capybara' | ||
require 'capybara/mechanize' | ||
|
||
Capybara.app_host = "http://localhost:6767/" | ||
Capybara.current_driver = :mechanize | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require 'timeout' | ||
|
||
module ProcessHelper | ||
attr_accessor :pid | ||
|
||
def setup | ||
Process.spawn("bundle exec foreman start --procfile=example/Procfile", pgroup: true, out: "/dev/null", err: "/dev/null") | ||
self.pid = read_pid_from_file('example/tmp/mongrel2.pid') | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
paneq
Collaborator
|
||
end | ||
|
||
def teardown | ||
Process.kill("SIGTERM", pid) if pid | ||
end | ||
|
||
def read_pid_from_file(pidfile) | ||
pid = nil | ||
Timeout.timeout(2) do | ||
loop do | ||
begin | ||
pid = File.read(pidfile) | ||
break unless pid.empty? | ||
rescue Errno::ENOENT | ||
sleep(0.1) | ||
next | ||
end | ||
end | ||
pid.to_i | ||
end | ||
rescue Timeout::Error | ||
raise "Unable to read PID from file #{pidfile}." | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
require 'bbq/test' | ||
require 'bbq/test_user' | ||
|
||
class TestUser < Bbq::TestUser | ||
include MiniTest::Assertions | ||
|
||
def initialize | ||
super(:driver => :mechanize) | ||
end | ||
|
||
def see!(*args) | ||
args.each do |arg| | ||
assert has_content?(arg), %Q/Expected to see "#{arg}" but not found./ | ||
end | ||
msg = "Expected to see %s but not found" | ||
args.each { |arg| assert has_content?(arg), msg % arg } | ||
end | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
require 'minitest/autorun' | ||
require 'mocha' | ||
require 'm2r' | ||
|
||
require 'support/test_handler' | ||
require 'support/test_user' | ||
require 'support/capybara' | ||
require 'support/process_helper' |
If we read pid of mongrel2 instead of taking foreman pid and send SIGTERM to it then what stops handler processes started by foreman ?
I can't figure it out.