Skip to content

Commit 4abf6b8

Browse files
committed
tests with Unicorn and Thin for out-of-sync responses
1 parent 76730d4 commit 4abf6b8

File tree

7 files changed

+98
-0
lines changed

7 files changed

+98
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ benchmark
1414
*#*
1515
*.class
1616
*.swp
17+
*.pid
18+
*.log
19+
test/load/unicorn/unicorn.rb
20+
test/load/thin/config.yml

test/load/thin/config.ru

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require "rubygems"
2+
require "sinatra"
3+
4+
require File.join(File.dirname(__FILE__), 'load.rb')
5+
6+
run Load

test/load/thin/config.yml.template

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require "rubygems"
2+
require "sinatra"
3+
4+
require File.join(File.dirname(__FILE__), 'load.rb')
5+
6+
run Load

test/load/thin/load.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'mongo')
2+
require 'logger'
3+
4+
$con = Mongo::Connection.new
5+
$db = $con['foo']
6+
7+
class Load < Sinatra::Base
8+
9+
configure do
10+
LOGGER = Logger.new("sinatra.log")
11+
enable :logging, :dump_errors
12+
set :raise_errors, true
13+
end
14+
15+
get '/' do
16+
3.times do |n|
17+
if (v=$db.eval("1 + #{n}")) != 1 + n
18+
STDERR << "#{1 + n} expected but got #{v}"
19+
raise StandardError, "#{1 + n} expected but got #{v}"
20+
end
21+
end
22+
end
23+
24+
end

test/load/unicorn/config.ru

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require "rubygems"
2+
require "sinatra"
3+
4+
require File.join(File.dirname(__FILE__), 'load.rb')
5+
6+
run Load

test/load/unicorn/load.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'mongo')
2+
3+
$con = Mongo::Connection.new
4+
$db = $con['foo']
5+
6+
class Load < Sinatra::Base
7+
8+
configure do
9+
LOGGER = Logger.new("sinatra.log")
10+
enable :logging, :dump_errors
11+
set :raise_errors, true
12+
end
13+
14+
get '/' do
15+
3.times do |n|
16+
if (v=$db.eval("1 + #{n}")) != 1 + n
17+
STDERR << "#{1 + n} expected but got #{v}"
18+
raise StandardError, "#{1 + n} expected but got #{v}"
19+
end
20+
end
21+
end
22+
23+
end

test/load/unicorn/unicorn.rb.template

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# set path to app that will be used to configure unicorn,
2+
# # note the trailing slash in this example
3+
@dir = "/home/kyle/work/10gen/ruby-driver/test/load/"
4+
5+
worker_processes 10
6+
working_directory @dir
7+
8+
preload_app true
9+
10+
timeout 30
11+
12+
# Specify path to socket unicorn listens to,
13+
# we will use this in our nginx.conf later
14+
listen "#{@dir}tmp/sockets/unicorn.sock", :backlog => 64
15+
16+
# Set process id path
17+
pid "#{@dir}tmp/pids/unicorn.pid"
18+
19+
# # Set log file paths
20+
stderr_path "#{@dir}log/unicorn.stderr.log"
21+
stdout_path "#{@dir}log/unicorn.stdout.log"
22+
23+
# NOTE: You need this when using forking web servers!
24+
after_fork do |server, worker|
25+
$con.close if $con
26+
$con = Mongo::Connection.new
27+
$db = $con['foo']
28+
STDERR << "FORKED #{server} #{worker}"
29+
end

0 commit comments

Comments
 (0)