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

Invalidate memorized object http on host changes #43

Merged
merged 1 commit into from
Mar 15, 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
11 changes: 11 additions & 0 deletions lib/toxiproxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def self.all
# Sets the toxiproxy host to use.
def self.host=(host)
@uri = host.is_a?(::URI) ? host : ::URI.parse(host)
reset_http_client!
@uri
end

# Convenience method to create a proxy.
Expand Down Expand Up @@ -223,6 +225,15 @@ def toxics
}
end

def self.reset_http_client!
if defined? @http
@http.finish() if @http && @http.started?
@http = nil
end

@http
end

private

def self.http_request(request)
Expand Down
9 changes: 9 additions & 0 deletions test/toxiproxy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,15 @@ def test_whitelisting_webmock_does_not_override_other_configuration
end
end

def test_invalidate_cache_http_on_host
old_value = Toxiproxy.uri
assert_equal 8474, Toxiproxy.http.port
Toxiproxy.host = "http://127.0.0.1:8475"
assert_equal 8475, Toxiproxy.http.port
ensure
Toxiproxy.host = old_value
end

private

def with_webmock_enabled
Expand Down