Skip to content

Commit 1404c7b

Browse files
committed
Add logging to server check
1 parent 88dc86e commit 1404c7b

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

spec/performance/bench.rb

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,20 +140,34 @@ def get_benchmark_routes(app_dir)
140140
# Helper method to check if server is responding
141141
def server_responding?(uri)
142142
response = Net::HTTP.get_response(uri)
143-
response.is_a?(Net::HTTPSuccess)
144-
rescue StandardError
145-
false
143+
{ success: response.is_a?(Net::HTTPSuccess), info: "HTTP #{response.code} #{response.message}" }
144+
rescue StandardError => e
145+
{ success: false, info: "#{e.class.name}: #{e.message}" }
146146
end
147147

148148
# Wait for the server to be ready
149149
TIMEOUT_SEC = 60
150150
puts "Checking server availability at #{BASE_URL}..."
151151
test_uri = URI.parse("http://#{BASE_URL}#{routes.first}")
152152
start_time = Time.now
153+
attempt_count = 0
153154
loop do
154-
break if server_responding?(test_uri)
155+
attempt_count += 1
156+
attempt_start = Time.now
157+
result = server_responding?(test_uri)
158+
attempt_duration = Time.now - attempt_start
159+
elapsed = Time.now - start_time
160+
161+
# rubocop:disable Layout/LineLength
162+
if result[:success]
163+
puts " ✅ Attempt #{attempt_count} at #{elapsed.round(2)}s: SUCCESS - #{result[:info]} (took #{attempt_duration.round(3)}s)"
164+
break
165+
else
166+
puts " ❌ Attempt #{attempt_count} at #{elapsed.round(2)}s: FAILED - #{result[:info]} (took #{attempt_duration.round(3)}s)"
167+
end
168+
# rubocop:enable Layout/LineLength
155169

156-
raise "Server at #{BASE_URL} not responding within #{TIMEOUT_SEC}s" if Time.now - start_time > TIMEOUT_SEC
170+
raise "Server at #{BASE_URL} not responding within #{TIMEOUT_SEC}s" if elapsed > TIMEOUT_SEC
157171

158172
sleep 1
159173
end

0 commit comments

Comments
 (0)