Skip to content

Commit

Permalink
CI: update test_on_booted_and_on_stopped integration tests (puma#3577)
Browse files Browse the repository at this point in the history
* CI: update `test_on_booted_and_on_stopped` integration tests

* CI: integration.rb - close @config_file io, fixup `wait_server`

* CI: integration.rb - always remove `@config_file` in teardown
  • Loading branch information
MSP-Greg authored Jan 4, 2025
1 parent ae1dc7a commit 584d4e4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 29 deletions.
7 changes: 0 additions & 7 deletions test/config/event_on_booted_and_on_stopped.rb

This file was deleted.

12 changes: 0 additions & 12 deletions test/config/event_on_booted_exit.rb

This file was deleted.

12 changes: 6 additions & 6 deletions test/helpers/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ def teardown
rescue
ensure
@server = nil

if @config_file
File.unlink(@config_file.path) rescue nil
@config_file = nil
end
end
end

if @config_file
File.unlink(@config_file.path) rescue nil
@config_file = nil
end
end

private
Expand Down Expand Up @@ -102,7 +102,7 @@ def cli_server(argv, # rubocop:disable Metrics/ParameterLists
@config_file.syswrite config
# not supported on some OS's, all GitHub Actions OS's support it
@config_file.fsync rescue nil
@ios_to_close << @config_file
@config_file.close
config = "-C #{@config_file.path}"
end

Expand Down
10 changes: 8 additions & 2 deletions test/test_integration_cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,19 @@ def test_term_suppress

def test_on_booted_and_on_stopped
skip_unless_signal_exist? :TERM
cli_server "-w #{workers} -C test/config/event_on_booted_and_on_stopped.rb -C test/config/event_on_booted_exit.rb test/rackup/hello.ru"
cli_server "-w #{workers} test/rackup/hello.ru", config: <<~CONFIG
on_booted { STDOUT.syswrite "on_booted called\n" }
on_stopped { STDOUT.syswrite "on_stopped called\n" }
CONFIG

# above checks 'Ctrl-C', below is logged after workers boot
assert wait_for_server_to_include('on_booted called')

Process.kill :TERM, @pid

assert wait_for_server_to_include('Goodbye!')
# below logged after workers are stopped
assert wait_for_server_to_include('on_stopped called')
wait_server 15
end

def test_term_worker_clean_exit
Expand Down
9 changes: 7 additions & 2 deletions test/test_integration_single.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,15 @@ def test_term_exit_code
def test_on_booted_and_on_stopped
skip_unless_signal_exist? :TERM

cli_server "-C test/config/event_on_booted_and_on_stopped.rb -C test/config/event_on_booted_exit.rb test/rackup/hello.ru",
no_wait: true
cli_server "test/rackup/hello.ru", no_wait: true, config: <<~CONFIG
on_booted { STDOUT.syswrite "on_booted called\n" }
on_stopped { STDOUT.syswrite "on_stopped called\n" }
CONFIG

assert wait_for_server_to_include('on_booted called')

Process.kill :TERM, @pid

assert wait_for_server_to_include('on_stopped called')

wait_server 15
Expand Down

0 comments on commit 584d4e4

Please sign in to comment.