Repository: puma/puma
File: test/test_integration_cluster.rb (Ruby)

Code before:
  end

  def test_hook_data
    cli_server "-C test/config/hook_data.rb test/rackup/hello.ru"
    get_worker_pids 0, 2 # make sure workers are booted
    stop_server

    ary = Array.new(2) do |_index|
      wait_for_server_to_match(/(index \d data \d)/, 1)
    end.sort

    assert 'index 0 data 0', ary[0]
    assert 'index 1 data 1', ary[1]
  end

  def test_after_worker_shutdown_hook
    cli_server "-C test/config/after_shutdown_hook.rb test/rackup/hello.ru"
    get_worker_pids 0, 2 # make sure workers are booted
    stop_server

    ary = Array.new(2) do |_index|
      wait_for_server_to_match(/(after_worker_shutdown worker=\d status=\d+)/, 1)
    end.sort

    assert 'after_worker_shutdown worker=0 status=0', ary[0]
    assert 'after_worker_shutdown worker=1 status=0', ary[1]
  end

  def test_worker_hook_warning_cli
    cli_server "-w2 test/rackup/hello.ru", config: <<~CONFIG
      before_worker_boot(:test) do |index, data|
        data[:test] = index
      end
    CONFIG

    get_worker_pids
    line = @server_log[/^Warning.+before_worker_boot.+/]
    refute line, "Warning below should not be shown!\n#{line}"
  end

  def test_worker_hook_warning_web_concurrency
    cli_server "test/rackup/hello.ru",
      env: { 'WEB_CONCURRENCY' => '2'},
      config: <<~CONFIG
        before_worker_boot(:test) do |index, data|
          data[:test] = index
        end
      CONFIG

    get_worker_pids
    line = @server_log[/^Warning.+.+before_worker_boot.+/]

Review comment (suggestion):
```suggestion
    assert_equal 'after_worker_shutdown worker=0 status=0', ary[0]
    assert_equal 'after_worker_shutdown worker=1 status=0', ary[1]
```

Code after:
  def test_culling_strategy_oldest_fork_worker
    cli_server "-w 2 test/rackup/hello.ru", config: <<~CONFIG
      worker_culling_strategy :oldest
      fork_worker
    CONFIG

    get_worker_pids # to consume server logs

    Process.kill :TTIN, @pid

    assert wait_for_server_to_match(/Worker 2 \(PID: \d+\) booted in/)

    Process.kill :TTOU, @pid

    assert wait_for_server_to_match(/Worker 1 \(PID: \d+\) terminating/)
  end

  def test_hook_data
    cli_server "-C test/config/hook_data.rb test/rackup/hello.ru"
    get_worker_pids 0, 2 # make sure workers are booted
    stop_server

    ary = Array.new(2) do |_index|
      wait_for_server_to_match(/(index \d data \d)/, 1)
    end.sort

    assert 'index 0 data 0', ary[0]
    assert 'index 1 data 1', ary[1]
  end

  def test_after_worker_shutdown_hook
    cli_server "-C test/config/after_shutdown_hook.rb test/rackup/hello.ru"
    get_worker_pids 0, 2 # make sure workers are booted
    stop_server

    ary = Array.new(2) do |_index|
      wait_for_server_to_match(/(after_worker_shutdown worker=\d status=\d+)/, 1)
    end.sort

    assert_equal 'after_worker_shutdown worker=0 status=0', ary[0]
    assert_equal 'after_worker_shutdown worker=1 status=0', ary[1]
  end

  def test_worker_hook_warning_cli
    cli_server "-w2 test/rackup/hello.ru", config: <<~CONFIG
      before_worker_boot(:test) do |index, data|
        data[:test] = index
      end
    CONFIG

    get_worker_pids