Skip to content
This repository
tag: v3.1.8
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 214 lines (179 sloc) 4.98 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
#!/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, port = 3210
  @tests += 1
  if `curl -S 'localhost:#{port}/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_all_in_one
  puts "Installing the Sinatra/Unicorn client/server."
  system "picky generate all_in_one 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_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_classic_server
  puts "Installing the Picky/Unicorn server."
  system "picky generate classic_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 port = 3210
  puts
  puts "Running search requests on the client directly"
  client "alan", "author", port
  client "ALAN", "title", port
  client "pinchn~", "pynchon", port
  client "sp", "title", port
  client "sp", "author", port
  client "title:lyterature~+2002", "literature", port
  client "alan", "Alan Turing", port
  puts
  puts
end

def open_client_in_browser port = 3210
  system "open -a 'Google Chrome' http://localhost:#{port}/?q=alan"
  sleep 1
  system "open -a 'Google Chrome' http://localhost:#{port}/?q=a%2A%20b"
  sleep 1
  system "open -a 'Google Chrome' http://localhost:#{port}/configure"
  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
  sleep 1
end

def run_server_rake_task name
  unless system("cd sandbox/server; rake #{name} --trace")
    raise "Integration specs failed!"
  end
end

def run_server_rake_tasks
  puts "Now the server rake tasks"
  run_server_rake_task '-T'
  run_server_rake_task 'analyze'
  run_server_rake_task 'check'
  run_server_rake_task 'routes'
  run_server_rake_task 'todo'
  run_server_rake_task 'try[test]'
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"

  # All in one.
  #
  install_all_in_one
  run_server_rake_tasks

  run_search_requests_on_client 8080 # Since it is just one server.
  open_client_in_browser 8080

  kill_server
  delete_server_directory

  # Sinatra Client.
  #
  install_sinatra_client

  # Sinatra Server.
  #
  install_sinatra_server
  run_search_requests_on_server
  run_server_integration_tests
  run_server_speed_tests
  run_server_rake_tasks

  run_search_requests_on_client
  open_client_in_browser

  kill_server
  delete_server_directory

  # Classic Server.
  #
  install_classic_server
  run_search_requests_on_server
  run_server_integration_tests
  run_server_speed_tests
  run_server_rake_tasks

  run_search_requests_on_client
  open_client_in_browser

  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
Something went wrong with that request. Please try again.