Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 162 lines (136 sloc) 3.697 kb
#!/usr/bin/env ruby
#
@tests = 0
def each_type
yield :full, 20
yield :live, 0
end
def ask_server query
`curl -S 'localhost:8080/books?query=#{query}&ids=20'`
end
def server query, match
@tests += 1
if ask_server(query).chomp.include?(match)
puts "Yay, server returned #{match} for #{query}!"
else
fail "#{query} result does not include #{match}"
end
end
def client query, match
@tests += 1
if `curl -S 'localhost:3210/search/full?query=#{query}&ids=20'`.chomp.include?(match)
puts "Yay, client returned #{match} for #{query}!"
else
fail "#{query} result does not include #{match}"
end
end
def install_sinatra_server
puts "Installing the Sinatra/Unicorn server."
system "picky generate sinatra_server sandbox/server"
system "cd sandbox/server; bundle install --local"
system "cd sandbox/server; bundle exec rake index"
system "cd sandbox/server; bundle exec unicorn -c unicorn.rb &"
sleep 5 # loading
end
def install_unicorn_server
puts "Installing the Picky/Unicorn server."
system "picky generate unicorn_server sandbox/server"
system "cd sandbox/server; bundle install --local"
system "cd sandbox/server; bundle exec rake index"
system "cd sandbox/server; bundle exec rake start &"
sleep 5 # loading
end
def run_search_requests_on_server
puts
puts "Running search requests on the server"
server "alan", "author"
server "ALAN", "title"
server "pinchn~", "pynchon"
server "sp", "title"
server "sp", "author"
server "title:lyterature~+2002", "literature"
puts
puts
end
def install_sinatra_client
puts "Installing the client."
system "picky generate sinatra_client sandbox/client"
system "cd sandbox/client; bundle install --local"
system "cd sandbox/client; unicorn -p 3210 &"
sleep 5 # loading
end
def run_search_requests_on_client
puts
puts "Running search requests on the client directly"
client "alan", "author"
client "ALAN", "title"
client "pinchn~", "pynchon"
client "sp", "title"
client "sp", "author"
client "title:lyterature~+2002", "literature"
client "alan", "Alan Turing"
puts
puts
end
def open_client_in_browser
system "open -a 'Google Chrome' http://localhost:3210/?q=alan"
sleep 1
system "open -a 'Google Chrome' http://localhost:3210/?q=a%2A%20b"
sleep 5
end
def run_server_integration_tests
puts "Now the server integration specs"
if system('cd sandbox/server; bundle exec rake spec')
puts "Yay! Integration specs ran through!"
else
raise "Integration specs failed!"
end
end
def run_server_speed_tests
puts "Now for a speed test"
queries = ['alan', 'pinchn~', 'sp', 'title:lyterature~+2002'].cycle
100.times do
ask_server queries.next
end
end
def kill_server
system "killall 'unicorn master -c unicorn.rb'"
end
def kill_client
system "killall 'unicorn master -p 3210'"
end
def delete_server_directory
system "rm -r sandbox/server"
end
def delete_client_directory
system "rm -r sandbox/client"
end
# Runs a whole integration.
#
begin
puts "Please run using Ruby 1.9" if RUBY_VERSION < '1.9.0'
system "./install"
install_sinatra_server
run_search_requests_on_server
install_sinatra_client
run_search_requests_on_client
open_client_in_browser
kill_server
delete_server_directory
install_unicorn_server
run_search_requests_on_server
run_search_requests_on_client
open_client_in_browser
run_server_integration_tests
run_server_speed_tests
puts
puts "SUCCESS! #{@tests} tests run without a hitch :)"
puts
ensure
puts "Press enter to kill (Break and have mercy with Ctrl-C)"
gets
kill_server
kill_client
delete_server_directory
delete_client_directory
end
Jump to Line
Something went wrong with that request. Please try again.