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

Added Service#keep_alive? method #12988

Merged
merged 1 commit into from
Mar 14, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions Library/Homebrew/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ def keep_alive(value = nil)
end
end

# Returns a `Boolean` describing if a service is set to be kept alive.
# @return [Boolean]
sig { returns(T::Boolean) }
def keep_alive?
instance_eval(&@service_block)
@keep_alive == true
end

sig { params(value: T.nilable(T::Boolean)).returns(T.nilable(T::Boolean)) }
def launch_only_once(value = nil)
case T.unsafe(value)
Expand Down
28 changes: 28 additions & 0 deletions Library/Homebrew/test/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,34 @@
end
end

describe "#keep_alive?" do
it "returns true when keep_alive set to true" do
f.class.service do
run [opt_bin/"beanstalkd", "test"]
keep_alive true
end

expect(f.service.keep_alive?).to be(true)
end

it "returns false when keep_alive not set" do
f.class.service do
run [opt_bin/"beanstalkd", "test"]
end

expect(f.service.keep_alive?).to be(false)
end

it "returns false when keep_alive set to false" do
f.class.service do
run [opt_bin/"beanstalkd", "test"]
keep_alive false
end

expect(f.service.keep_alive?).to be(false)
end
end

describe "#command" do
it "returns @run data" do
f.class.service do
Expand Down