tests with Unicorn and Thin for out-of-sync responses

This commit is contained in:
Kyle Banker 2011-02-10 14:42:29 -05:00
parent 76730d4a7c
commit 4abf6b8875
7 changed files with 98 additions and 0 deletions

4
.gitignore vendored
View File

@ -14,3 +14,7 @@ benchmark
*#*
*.class
*.swp
*.pid
*.log
test/load/unicorn/unicorn.rb
test/load/thin/config.yml

6
test/load/thin/config.ru Normal file
View File

@ -0,0 +1,6 @@
require "rubygems"
require "sinatra"
require File.join(File.dirname(__FILE__), 'load.rb')
run Load

View File

@ -0,0 +1,6 @@
require "rubygems"
require "sinatra"
require File.join(File.dirname(__FILE__), 'load.rb')
run Load

24
test/load/thin/load.rb Normal file
View File

@ -0,0 +1,24 @@
require File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'mongo')
require 'logger'
$con = Mongo::Connection.new
$db = $con['foo']
class Load < Sinatra::Base
configure do
LOGGER = Logger.new("sinatra.log")
enable :logging, :dump_errors
set :raise_errors, true
end
get '/' do
3.times do |n|
if (v=$db.eval("1 + #{n}")) != 1 + n
STDERR << "#{1 + n} expected but got #{v}"
raise StandardError, "#{1 + n} expected but got #{v}"
end
end
end
end

View File

@ -0,0 +1,6 @@
require "rubygems"
require "sinatra"
require File.join(File.dirname(__FILE__), 'load.rb')
run Load

23
test/load/unicorn/load.rb Normal file
View File

@ -0,0 +1,23 @@
require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'mongo')
$con = Mongo::Connection.new
$db = $con['foo']
class Load < Sinatra::Base
configure do
LOGGER = Logger.new("sinatra.log")
enable :logging, :dump_errors
set :raise_errors, true
end
get '/' do
3.times do |n|
if (v=$db.eval("1 + #{n}")) != 1 + n
STDERR << "#{1 + n} expected but got #{v}"
raise StandardError, "#{1 + n} expected but got #{v}"
end
end
end
end

View File

@ -0,0 +1,29 @@
# set path to app that will be used to configure unicorn,
# # note the trailing slash in this example
@dir = "/home/kyle/work/10gen/ruby-driver/test/load/"
worker_processes 10
working_directory @dir
preload_app true
timeout 30
# Specify path to socket unicorn listens to,
# we will use this in our nginx.conf later
listen "#{@dir}tmp/sockets/unicorn.sock", :backlog => 64
# Set process id path
pid "#{@dir}tmp/pids/unicorn.pid"
# # Set log file paths
stderr_path "#{@dir}log/unicorn.stderr.log"
stdout_path "#{@dir}log/unicorn.stdout.log"
# NOTE: You need this when using forking web servers!
after_fork do |server, worker|
$con.close if $con
$con = Mongo::Connection.new
$db = $con['foo']
STDERR << "FORKED #{server} #{worker}"
end