Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 235 lines (191 sloc) 5.193 kb
78b416a @floere + integration testing the getting started process
authored
1 #!/usr/bin/env ruby
2 #
af0ceeb @floere + integration test improved
authored
3 @tests = 0
4
0c1922c @floere + scripts improved with choice of where to get gems (REMOTE or not)
authored
5 # Use ./integration REMOTE to use remote gem sources.
6 #
81024ce @floere + make integration tests stabler and more robust, also for others
authored
7 @remote = ARGV.include? 'REMOTE'
8
9 def remote?
10 @remote
11 end
12
3e0efd2 @floere + update all specs
authored
13 puts
14 puts "Running integration tests with #{remote?? 'REMOTE' : 'LOCAL'} gems."
15 puts
ff5e07c @floere + rewrite such that picky can be run in a script, without bundler, + …
authored
16
81024ce @floere + make integration tests stabler and more robust, also for others
authored
17 def bundle_options
18 @remote ? '' : '--local'
19 end
20
21 def gem_options
22 @remote ? '--remote' : '--local'
23 end
0c1922c @floere + scripts improved with choice of where to get gems (REMOTE or not)
authored
24
af0ceeb @floere + integration test improved
authored
25 def each_type
26 yield :full, 20
27 yield :live, 0
28 end
78b416a @floere + integration testing the getting started process
authored
29
dc124a0 @floere + speed test
authored
30 def ask_server query
31 `curl -S 'localhost:8080/books?query=#{query}&ids=20'`
32 end
78b416a @floere + integration testing the getting started process
authored
33 def server query, match
af0ceeb @floere + integration test improved
authored
34 @tests += 1
dc124a0 @floere + speed test
authored
35 if ask_server(query).chomp.include?(match)
78b416a @floere + integration testing the getting started process
authored
36 puts "Yay, server returned #{match} for #{query}!"
37 else
38 fail "#{query} result does not include #{match}"
39 end
40 end
f0d5269 @floere + all in one generation, + all in one integration specs
authored
41 def client query, match, port = 3210
af0ceeb @floere + integration test improved
authored
42 @tests += 1
f0d5269 @floere + all in one generation, + all in one integration specs
authored
43 if `curl -S 'localhost:#{port}/search/full?query=#{query}&ids=20'`.chomp.include?(match)
78b416a @floere + integration testing the getting started process
authored
44 puts "Yay, client returned #{match} for #{query}!"
45 else
46 fail "#{query} result does not include #{match}"
47 end
48 end
49
f0d5269 @floere + all in one generation, + all in one integration specs
authored
50 def install_all_in_one
ff5e07c @floere + rewrite such that picky can be run in a script, without bundler, + …
authored
51 puts "Installing the Sinatra/Unicorn all_in_one client/server."
f0d5269 @floere + all in one generation, + all in one integration specs
authored
52 system "picky generate all_in_one sandbox/server"
81024ce @floere + make integration tests stabler and more robust, also for others
authored
53 system "cd sandbox/server; bundle install #{bundle_options}"
f0d5269 @floere + all in one generation, + all in one integration specs
authored
54 system "cd sandbox/server; bundle exec rake index"
55 system "cd sandbox/server; bundle exec unicorn -c unicorn.rb &"
56
81024ce @floere + make integration tests stabler and more robust, also for others
authored
57 sleep 8 # loading
f0d5269 @floere + all in one generation, + all in one integration specs
authored
58 end
59
e59fc07 @floere + new integration specs
authored
60 def install_sinatra_server
ff5e07c @floere + rewrite such that picky can be run in a script, without bundler, + …
authored
61 # Note: Not using bundler anymore.
62 #
e59fc07 @floere + new integration specs
authored
63 puts "Installing the Sinatra/Unicorn server."
7c53a71 @floere + generators rewrite
authored
64 system "picky generate server sandbox/server"
ff5e07c @floere + rewrite such that picky can be run in a script, without bundler, + …
authored
65 system "cd sandbox/server; rake index"
66 system "cd sandbox/server; unicorn -c unicorn.rb &"
4180ee0 @floere + ability to extend integration test time – to test it manually too
authored
67
81024ce @floere + make integration tests stabler and more robust, also for others
authored
68 sleep 8 # loading
e59fc07 @floere + new integration specs
authored
69 end
78b416a @floere + integration testing the getting started process
authored
70
e59fc07 @floere + new integration specs
authored
71 def run_search_requests_on_server
78b416a @floere + integration testing the getting started process
authored
72 puts
73 puts "Running search requests on the server"
74 server "alan", "author"
75 server "ALAN", "title"
76 server "pinchn~", "pynchon"
77 server "sp", "title"
78 server "sp", "author"
79 server "title:lyterature~+2002", "literature"
80 puts
81 puts
e59fc07 @floere + new integration specs
authored
82 end
78b416a @floere + integration testing the getting started process
authored
83
e59fc07 @floere + new integration specs
authored
84 def install_sinatra_client
78b416a @floere + integration testing the getting started process
authored
85 puts "Installing the client."
7c53a71 @floere + generators rewrite
authored
86 system "picky generate client sandbox/client"
81024ce @floere + make integration tests stabler and more robust, also for others
authored
87 system "cd sandbox/client; bundle install #{bundle_options}"
78b416a @floere + integration testing the getting started process
authored
88 system "cd sandbox/client; unicorn -p 3210 &"
4180ee0 @floere + ability to extend integration test time – to test it manually too
authored
89
78b416a @floere + integration testing the getting started process
authored
90 sleep 5 # loading
e59fc07 @floere + new integration specs
authored
91 end
4180ee0 @floere + ability to extend integration test time – to test it manually too
authored
92
f0d5269 @floere + all in one generation, + all in one integration specs
authored
93 def run_search_requests_on_client port = 3210
66abf22 @floere + preparations for 4.3.0, + completely overhauled JS, + gorgeous new …
authored
94 sleep 3 # loading
95
78b416a @floere + integration testing the getting started process
authored
96 puts
97 puts "Running search requests on the client directly"
f0d5269 @floere + all in one generation, + all in one integration specs
authored
98 client "alan", "author", port
99 client "ALAN", "title", port
100 client "pinchn~", "pynchon", port
101 client "sp", "title", port
102 client "sp", "author", port
103 client "title:lyterature~+2002", "literature", port
104 client "alan", "Alan Turing", port
78b416a @floere + integration testing the getting started process
authored
105 puts
106 puts
e59fc07 @floere + new integration specs
authored
107 end
4180ee0 @floere + ability to extend integration test time – to test it manually too
authored
108
f0d5269 @floere + all in one generation, + all in one integration specs
authored
109 def open_client_in_browser port = 3210
110 system "open -a 'Google Chrome' http://localhost:#{port}/?q=alan"
6cc020c @floere + integration visual test
authored
111 sleep 1
f0d5269 @floere + all in one generation, + all in one integration specs
authored
112 system "open -a 'Google Chrome' http://localhost:#{port}/?q=a%2A%20b"
9f4a75a @floere + integration spec
authored
113 sleep 5
e59fc07 @floere + new integration specs
authored
114 end
4180ee0 @floere + ability to extend integration test time – to test it manually too
authored
115
ff5e07c @floere + rewrite such that picky can be run in a script, without bundler, + …
authored
116 def run_server_integration_tests with_bundle_exec = true
2efe604 @floere + Integration specs run the generated server project's integration specs
authored
117 puts "Now the server integration specs"
ff5e07c @floere + rewrite such that picky can be run in a script, without bundler, + …
authored
118 if system("cd sandbox/server; #{ 'bundle exec' if with_bundle_exec } rake spec")
2efe604 @floere + Integration specs run the generated server project's integration specs
authored
119 puts "Yay! Integration specs ran through!"
120 else
121 raise "Integration specs failed!"
122 end
c17c1d1 @floere + integration specs for rake tasks
authored
123 sleep 1
124 end
125
126 def run_server_rake_task name
127 unless system("cd sandbox/server; rake #{name} --trace")
128 raise "Integration specs failed!"
129 end
130 end
131
132 def run_server_rake_tasks
133 puts "Now the server rake tasks"
7ea534d @floere + use method even with -T
authored
134 run_server_rake_task '-T'
c17c1d1 @floere + integration specs for rake tasks
authored
135 run_server_rake_task 'analyze'
136 run_server_rake_task 'todo'
137 run_server_rake_task 'try[test]'
e59fc07 @floere + new integration specs
authored
138 end
2efe604 @floere + Integration specs run the generated server project's integration specs
authored
139
e59fc07 @floere + new integration specs
authored
140 def run_server_speed_tests
dc124a0 @floere + speed test
authored
141 puts "Now for a speed test"
142 queries = ['alan', 'pinchn~', 'sp', 'title:lyterature~+2002'].cycle
143 100.times do
144 ask_server queries.next
145 end
e59fc07 @floere + new integration specs
authored
146 end
147
ae4916d @floere + 4.0.0pre6
authored
148 def run_statistics
149 # system "picky stats sandbox/server/log/search.log &"
150 # system "open -a 'Google Chrome' http://localhost:4567/"
151 end
152
e59fc07 @floere + new integration specs
authored
153 def kill_server
81024ce @floere + make integration tests stabler and more robust, also for others
authored
154 puts "Killing server (if there)"
ff5e07c @floere + rewrite such that picky can be run in a script, without bundler, + …
authored
155 system "ps ax | grep 'unicorn -c unicorn.rb' | awk '{print $1}' | xargs kill"
e59fc07 @floere + new integration specs
authored
156 end
157
158 def kill_client
81024ce @floere + make integration tests stabler and more robust, also for others
authored
159 puts "Killing client (if there)"
ff5e07c @floere + rewrite such that picky can be run in a script, without bundler, + …
authored
160 system "ps ax | grep 'unicorn -p 3210' | awk '{print $1}' | xargs kill"
e59fc07 @floere + new integration specs
authored
161 end
162
163 def delete_server_directory
164 system "rm -r sandbox/server"
165 end
166
167 def delete_client_directory
168 system "rm -r sandbox/client"
169 end
170
171 # Runs a whole integration.
172 #
173 begin
174 puts "Please run using Ruby 1.9" if RUBY_VERSION < '1.9.0'
175
ff5e07c @floere + rewrite such that picky can be run in a script, without bundler, + …
authored
176 kill_server
177 kill_client
81024ce @floere + make integration tests stabler and more robust, also for others
authored
178
179 system "./install #{ 'REMOTE' if remote? }"
e59fc07 @floere + new integration specs
authored
180
f0d5269 @floere + all in one generation, + all in one integration specs
authored
181 # All in one.
182 #
ff5e07c @floere + rewrite such that picky can be run in a script, without bundler, + …
authored
183 puts "\nALL IN ONE SERVER\n"
184
f0d5269 @floere + all in one generation, + all in one integration specs
authored
185 install_all_in_one
c17c1d1 @floere + integration specs for rake tasks
authored
186 run_server_rake_tasks
f0d5269 @floere + all in one generation, + all in one integration specs
authored
187
ff5e07c @floere + rewrite such that picky can be run in a script, without bundler, + …
authored
188 puts "\nALL IN ONE CLIENT\n"
189
f0d5269 @floere + all in one generation, + all in one integration specs
authored
190 run_search_requests_on_client 8080 # Since it is just one server.
191 open_client_in_browser 8080
192
193 kill_server
194 delete_server_directory
195
196 # Sinatra Client.
197 #
ff5e07c @floere + rewrite such that picky can be run in a script, without bundler, + …
authored
198 puts "\nSINATRA CLIENT\n"
199
e59fc07 @floere + new integration specs
authored
200 install_sinatra_client
201
f0d5269 @floere + all in one generation, + all in one integration specs
authored
202 # Sinatra Server.
203 #
ff5e07c @floere + rewrite such that picky can be run in a script, without bundler, + …
authored
204 puts "\nSINATRA SERVER\n"
205
f0d5269 @floere + all in one generation, + all in one integration specs
authored
206 install_sinatra_server
207 run_search_requests_on_server
ff5e07c @floere + rewrite such that picky can be run in a script, without bundler, + …
authored
208 run_server_integration_tests false
db4c759 @floere ! integration specs of generated project
authored
209 run_server_speed_tests
c17c1d1 @floere + integration specs for rake tasks
authored
210 run_server_rake_tasks
db4c759 @floere ! integration specs of generated project
authored
211
f0d5269 @floere + all in one generation, + all in one integration specs
authored
212 run_search_requests_on_client
213 open_client_in_browser
214
ae4916d @floere + 4.0.0pre6
authored
215 run_statistics
216
e59fc07 @floere + new integration specs
authored
217 kill_server
218 delete_server_directory
219
af0ceeb @floere + integration test improved
authored
220 puts
221 puts "SUCCESS! #{@tests} tests run without a hitch :)"
222 puts
81024ce @floere + make integration tests stabler and more robust, also for others
authored
223 rescue Exception => e
224 puts e.message
225 puts e.backtrace
78b416a @floere + integration testing the getting started process
authored
226 ensure
4180ee0 @floere + ability to extend integration test time – to test it manually too
authored
227 puts "Press enter to kill (Break and have mercy with Ctrl-C)"
228 gets
229
e59fc07 @floere + new integration specs
authored
230 kill_server
231 kill_client
4180ee0 @floere + ability to extend integration test time – to test it manually too
authored
232
e59fc07 @floere + new integration specs
authored
233 delete_server_directory
234 delete_client_directory
78b416a @floere + integration testing the getting started process
authored
235 end
Something went wrong with that request. Please try again.