Skip to content

Commit

Permalink
reuse wait_for_loop in wait_for_zeus
Browse files Browse the repository at this point in the history
  • Loading branch information
ranmocy committed Aug 11, 2015
1 parent 124632e commit fd50e1c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
25 changes: 9 additions & 16 deletions lib/guard/rails/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module Guard
class Rails
class Runner
MAX_WAIT_COUNT = 10
ZEUS_WAIT_TIMEOUT = 15

attr_reader :options

Expand Down Expand Up @@ -73,13 +72,7 @@ def sleep_time
end

def wait_for_zeus
elapsed_time = 0

while not File.exist?(zeus_sockfile) and elapsed_time < ZEUS_WAIT_TIMEOUT
elapsed_time += sleep(1)
end

File.exist?(zeus_sockfile)
wait_for_loop { File.exist?(zeus_sockfile) }
end

private
Expand All @@ -103,10 +96,6 @@ def build_cli_command
"#{options[:CLI]} --pid \"#{pid_file}\""
end

def zeus_sockfile
File.join(@root, '.zeus.sock')
end

def build_zeus_command
zeus_options = [
options[:zeus_plan] || 'server',
Expand Down Expand Up @@ -160,21 +149,21 @@ def unmanaged_pid
end

def wait_for_pid
wait_for_pid_loop { has_pid? }
wait_for_loop { has_pid? }
end

def wait_for_no_pid
wait_for_pid_loop { !has_pid? }
wait_for_loop { !has_pid? }
end

def remove_pid_file_and_wait_for_no_pid
wait_for_pid_loop do
wait_for_loop do
FileUtils.rm pid_file, force: true
!has_pid?
end
end

def wait_for_pid_loop
def wait_for_loop
count = 0
while !yield && count < MAX_WAIT_COUNT
wait_for_pid_action
Expand All @@ -201,6 +190,10 @@ def read_pid
nil
end

def zeus_sockfile
File.join(@root, '.zeus.sock')
end

end
end
end
2 changes: 1 addition & 1 deletion spec/lib/guard/rails/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@
context 'when zeus socket file is present' do
before do
mock(runner).sleep(1).never
mock(File).exist?(File.join(Dir.pwd, '.zeus.sock')) { true }.twice
mock(File).exist?(File.join(Dir.pwd, '.zeus.sock')) { true }.once
end

it "doesn't wait for zeus" do
Expand Down

0 comments on commit fd50e1c

Please sign in to comment.