Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tune examples to cover some cases #453

Merged
merged 1 commit into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ Style/GlobalVars:

Style/SingleLineMethods:
Enabled: false

Style/SpecialGlobalVars:
Enabled: false
12 changes: 9 additions & 3 deletions examples/net_http/05_circuit_in_threads.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,25 @@
Net::HTTP.start("example.com", 81, open_timeout: 3) do |http|
http.request_get(bad_host)
end
rescue => e
rescue Net::OpenTimeout => e
puts "[thread=#{thread_id}] >> Could not connect: #{e.message}".brown
end
puts

sleep(2)
sleep(1.5)

puts "[thread=#{thread_id}] >> 4. Request to http://example.com:81/index.html - fail".magenta
begin
Net::HTTP.start("example.com", 81, open_timeout: 3) do |http|
http.request_get(bad_host)
end
rescue => e
rescue Net::OpenTimeout => e
puts "[thread=#{thread_id}] >> Could not connect: #{e.message}".brown
end

resource = Semian["nethttp_example_com"]
raise "The state should be open - because expected 2 failed requests in last 5 seconds." unless resource.open?

puts "[thread=#{thread_id}] !!! Semian changed state from `closed` to `open` and record last error exception !!!".red.bold
puts

Expand All @@ -111,6 +115,8 @@
end
rescue Net::CircuitOpenError => e
puts "[thread=#{thread_id}] >> Semian is open: #{e.message}".brown
rescue => e
raise "Unexpected exception: #{e.messge} (#{e.class}). Check if Semian resource error_threshold_reached?"
end
puts

Expand Down
9 changes: 6 additions & 3 deletions examples/net_http/06_circuit_in_fork.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,19 @@
Net::HTTP.start("example.com", 81, open_timeout: 3) do |http|
http.request_get(bad_host)
end
rescue => e
rescue Net::OpenTimeout => e
puts "[pid=#{pid}] >> Could not connect: #{e.message}".brown
end
puts

sleep(2)
sleep(1.5)

puts "[pid=#{pid}] >> 4. Request to http://example.com:81/index.html - fail".magenta
begin
Net::HTTP.start("example.com", 81, open_timeout: 3) do |http|
http.request_get(bad_host)
end
rescue => e
rescue Net::OpenTimeout => e
puts "[pid=#{pid}] >> Could not connect: #{e.message}".brown
end
puts "[pid=#{pid}] !!! Semian changed state from `closed` to `open` and record last error exception !!!".red.bold
Expand All @@ -125,6 +125,9 @@
end

Process.waitpid(worker_bar)
exit($?.exitstatus) if $?.exitstatus != 0

Process.waitpid(worker_foo)
exit($?.exitstatus) if $?.exitstatus != 0

puts "> That's all Folks!".green
6 changes: 3 additions & 3 deletions examples/net_http/11_bulkhead_in_forks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
Net::HTTP.start("example.com", 81, open_timeout: 5) do |http|
http.request_get(bad_host)
end
rescue Errno::EADDRNOTAVAIL => e
puts "[pid=#{pid}] Expected networking problem that blocked the last ticket: #{e.class}: #{e.message}".blue
rescue Errno::EADDRNOTAVAIL, Net::OpenTimeout => e
puts "[pid=#{pid}] EXPECTED networking problem that blocked the last ticket: #{e.class}: #{e.message}".blue
end

2.times do
Expand All @@ -58,7 +58,7 @@
Net::HTTP.get_response(uri)
raise "Should not get to this line."
rescue Net::ResourceBusyError => e
puts "[pid=#{pid}] Out of tickets: #{e.class}: #{e.message}\n #{e.backtrace.join("\n ")}".brown
puts "[pid=#{pid}] EXPECTED: Out of tickets: #{e.class}: #{e.message}".brown
end
end

Expand Down
5 changes: 3 additions & 2 deletions examples/net_http/12_bulkhead_quotes_in_forks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ def print_semaphore_information(resource = nil)
Net::HTTP.start("example.com", 81, open_timeout: 5) do |http|
http.request_get(bad_host)
end
rescue Errno::EADDRNOTAVAIL => e
puts "[pid=#{pid}] Expected networking problem that blocked the last ticket: #{e.class}: #{e.message}".blue
raise "Should not get to this line."
rescue Errno::EADDRNOTAVAIL, Net::OpenTimeout => e
puts "[pid=#{pid}] EXPECTED networking problem that blocked the last ticket: #{e.class}: #{e.message}".blue
end

5.times do |_i|
Expand Down