diff --git a/.gitignore b/.gitignore index 1d4c5f2..e117d19 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,7 @@ benchmark *#* *.class *.swp +*.pid +*.log +test/load/unicorn/unicorn.rb +test/load/thin/config.yml diff --git a/test/load/thin/config.ru b/test/load/thin/config.ru new file mode 100644 index 0000000..aa6ee91 --- /dev/null +++ b/test/load/thin/config.ru @@ -0,0 +1,6 @@ +require "rubygems" +require "sinatra" + +require File.join(File.dirname(__FILE__), 'load.rb') + +run Load diff --git a/test/load/thin/config.yml.template b/test/load/thin/config.yml.template new file mode 100644 index 0000000..aa6ee91 --- /dev/null +++ b/test/load/thin/config.yml.template @@ -0,0 +1,6 @@ +require "rubygems" +require "sinatra" + +require File.join(File.dirname(__FILE__), 'load.rb') + +run Load diff --git a/test/load/thin/load.rb b/test/load/thin/load.rb new file mode 100644 index 0000000..a29296e --- /dev/null +++ b/test/load/thin/load.rb @@ -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 diff --git a/test/load/unicorn/config.ru b/test/load/unicorn/config.ru new file mode 100644 index 0000000..aa6ee91 --- /dev/null +++ b/test/load/unicorn/config.ru @@ -0,0 +1,6 @@ +require "rubygems" +require "sinatra" + +require File.join(File.dirname(__FILE__), 'load.rb') + +run Load diff --git a/test/load/unicorn/load.rb b/test/load/unicorn/load.rb new file mode 100644 index 0000000..f624cb1 --- /dev/null +++ b/test/load/unicorn/load.rb @@ -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 diff --git a/test/load/unicorn/unicorn.rb.template b/test/load/unicorn/unicorn.rb.template new file mode 100644 index 0000000..ede2ae8 --- /dev/null +++ b/test/load/unicorn/unicorn.rb.template @@ -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