aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/ruby/pb/grpc/health/checker.rb14
-rw-r--r--src/ruby/spec/pb/health/checker_spec.rb42
2 files changed, 21 insertions, 35 deletions
diff --git a/src/ruby/pb/grpc/health/checker.rb b/src/ruby/pb/grpc/health/checker.rb
index 0af4c5b0a8..9f1ee65c41 100644
--- a/src/ruby/pb/grpc/health/checker.rb
+++ b/src/ruby/pb/grpc/health/checker.rb
@@ -50,20 +50,20 @@ module Grpc
def check(req, _call)
status = nil
@status_mutex.synchronize do
- status = @statuses["#{req.host}/#{req.service}"]
+ status = @statuses["#{req.service}"]
end
fail GRPC::BadStatus, StatusCodes::NOT_FOUND if status.nil?
HealthCheckResponse.new(status: status)
end
- # Adds the health status for a given host and service.
- def add_status(host, service, status)
- @status_mutex.synchronize { @statuses["#{host}/#{service}"] = status }
+ # Adds the health status for a given service.
+ def add_status(service, status)
+ @status_mutex.synchronize { @statuses["#{service}"] = status }
end
- # Clears the status for the given host or service.
- def clear_status(host, service)
- @status_mutex.synchronize { @statuses.delete("#{host}/#{service}") }
+ # Clears the status for the given service.
+ def clear_status(service)
+ @status_mutex.synchronize { @statuses.delete("#{service}") }
end
# Clears alls the statuses.
diff --git a/src/ruby/spec/pb/health/checker_spec.rb b/src/ruby/spec/pb/health/checker_spec.rb
index fe4e5269bb..9bb79bb4ca 100644
--- a/src/ruby/spec/pb/health/checker_spec.rb
+++ b/src/ruby/spec/pb/health/checker_spec.rb
@@ -87,21 +87,11 @@ describe Grpc::Health::Checker do
success_tests =
[
{
- desc: 'neither host or service are specified',
- host: '',
+ desc: 'the service is not specified',
service: ''
}, {
- desc: 'only the host is specified',
- host: 'test-fake-host',
- service: ''
- }, {
- desc: 'the host and service are specified',
- host: 'test-fake-host',
+ desc: 'the service is specified',
service: 'fake-service-1'
- }, {
- desc: 'only the service is specified',
- host: '',
- service: 'fake-service-2'
}
]
@@ -114,9 +104,8 @@ describe Grpc::Health::Checker do
context 'method `add_status` and `check`' do
success_tests.each do |t|
it "should succeed when #{t[:desc]}" do
- subject.add_status(t[:host], t[:service], ServingStatus::NOT_SERVING)
- got = subject.check(HCReq.new(host: t[:host], service: t[:service]),
- nil)
+ subject.add_status(t[:service], ServingStatus::NOT_SERVING)
+ got = subject.check(HCReq.new(service: t[:service]), nil)
want = HCResp.new(status: ServingStatus::NOT_SERVING)
expect(got).to eq(want)
end
@@ -127,7 +116,7 @@ describe Grpc::Health::Checker do
success_tests.each do |t|
it "should fail with NOT_FOUND when #{t[:desc]}" do
blk = proc do
- subject.check(HCReq.new(host: t[:host], service: t[:service]), nil)
+ subject.check(HCReq.new(service: t[:service]), nil)
end
expected_msg = /#{StatusCodes::NOT_FOUND}/
expect(&blk).to raise_error GRPC::BadStatus, expected_msg
@@ -138,16 +127,14 @@ describe Grpc::Health::Checker do
context 'method `clear_status`' do
success_tests.each do |t|
it "should fail after clearing status when #{t[:desc]}" do
- subject.add_status(t[:host], t[:service], ServingStatus::NOT_SERVING)
- got = subject.check(HCReq.new(host: t[:host], service: t[:service]),
- nil)
+ subject.add_status(t[:service], ServingStatus::NOT_SERVING)
+ got = subject.check(HCReq.new(service: t[:service]), nil)
want = HCResp.new(status: ServingStatus::NOT_SERVING)
expect(got).to eq(want)
- subject.clear_status(t[:host], t[:service])
+ subject.clear_status(t[:service])
blk = proc do
- subject.check(HCReq.new(host: t[:host], service: t[:service]),
- nil)
+ subject.check(HCReq.new(service: t[:service]), nil)
end
expected_msg = /#{StatusCodes::NOT_FOUND}/
expect(&blk).to raise_error GRPC::BadStatus, expected_msg
@@ -158,9 +145,8 @@ describe Grpc::Health::Checker do
context 'method `clear_all`' do
it 'should return NOT_FOUND after being invoked' do
success_tests.each do |t|
- subject.add_status(t[:host], t[:service], ServingStatus::NOT_SERVING)
- got = subject.check(HCReq.new(host: t[:host], service: t[:service]),
- nil)
+ subject.add_status(t[:service], ServingStatus::NOT_SERVING)
+ got = subject.check(HCReq.new(service: t[:service]), nil)
want = HCResp.new(status: ServingStatus::NOT_SERVING)
expect(got).to eq(want)
end
@@ -169,7 +155,7 @@ describe Grpc::Health::Checker do
success_tests.each do |t|
blk = proc do
- subject.check(HCReq.new(host: t[:host], service: t[:service]), nil)
+ subject.check(HCReq.new(service: t[:service]), nil)
end
expected_msg = /#{StatusCodes::NOT_FOUND}/
expect(&blk).to raise_error GRPC::BadStatus, expected_msg
@@ -203,7 +189,7 @@ describe Grpc::Health::Checker do
it 'should receive the correct status', server: true do
@srv.handle(subject)
- subject.add_status('', '', ServingStatus::NOT_SERVING)
+ subject.add_status('', ServingStatus::NOT_SERVING)
t = Thread.new { @srv.run }
@srv.wait_till_running
@@ -221,7 +207,7 @@ describe Grpc::Health::Checker do
@srv.wait_till_running
blk = proc do
stub = CheckerStub.new(@host, :this_channel_is_insecure, **@client_opts)
- stub.check(HCReq.new(host: 'unknown', service: 'unknown'))
+ stub.check(HCReq.new(service: 'unknown'))
end
expected_msg = /#{StatusCodes::NOT_FOUND}/
expect(&blk).to raise_error GRPC::BadStatus, expected_msg