Skip to content

Commit

Permalink
+ ci: enable server logs when runner has debug enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan committed Jan 8, 2025
1 parent f6f66de commit 3002685
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test-jruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@ jobs:
# Mark failures as warnings for now due to high level of flakiness
# and occasional OOM-s on CI
continue-on-error: true
env:
DEBUG_NATS_TEST: ${{ runner.debug }}
run: |
bundle exec rspec || DEBUG_NATS_TEST=true bundle exec rspec --only-failures
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ jobs:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run RSpec
env:
DEBUG_NATS_TEST: ${{ runner.debug }}
run: |
bundle exec rspec
Expand Down
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
--require spec_helper
--color
23 changes: 16 additions & 7 deletions spec/support/nats_server_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def init_with_config(config_file)
end

def init_with_config_from_string(config_string, config={})
puts config_string if ENV["DEBUG_NATS_TEST"] == "true"
puts config_string if debug?
config_file = Tempfile.new(['nats-cluster-tests', '.conf'])
File.open(config_file.path, 'w') do |f|
f.puts(config_string)
Expand All @@ -34,6 +34,9 @@ def init_with_config_from_string(config_string, config={})
NatsServerControl.new(uri, config['pid_file'], "-c #{config_file.path}", config_file)
end

def debug?
%w[1 true t].include?(ENV["DEBUG_NATS_TEST"])
end
end

attr_reader :uri
Expand All @@ -45,6 +48,10 @@ def initialize(uri='nats://127.0.0.1:4222', pid_file='/tmp/test-nats.pid', flags
@config_file = config_file
end

def debug?
self.class.debug?
end

def server_pid
@pid ||= File.read(@pid_file).chomp.to_i
end
Expand Down Expand Up @@ -72,7 +79,7 @@ def start_server(wait_for_server=true)
end
args += " #{@flags}" if @flags

if ENV["DEBUG_NATS_TEST"] == "true"
if debug?
system("#{BIN_PATH} #{args} -DV &")
else
system("#{BIN_PATH} #{args} 2> /dev/null &")
Expand All @@ -92,19 +99,21 @@ def kill_server
end

def wait_for_server(uri, max_wait = 5) # :nodoc:
start = Time.now
while (Time.now - start < max_wait) # Wait max_wait seconds max
wait = max_wait.to_f
loop do
return if server_running?(uri)
sleep(0.1)
end
wait -= 0.1

raise "NATS Server did not start in #{max_wait} seconds"
raise "NATS Server did not start in #{max_wait} seconds" if wait <= 0
end
end

def server_running?(uri) # :nodoc:
s = TCPSocket.new(uri.host, uri.port, nil, nil, connect_timeout: 0.5)
true
rescue
rescue => e
puts "Server is not available: #{e}" if debug?
false
ensure
s&.close
Expand Down

0 comments on commit 3002685

Please sign in to comment.