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

Code before:

    # test multiple
    messages = []
    conf = Puma::Configuration.new do |c|
      c.send(configured_with) do |a|
        messages << "#{hook_name} is called with #{a} one time"
      end

      c.send(configured_with) do |a|
        messages << "#{hook_name} is called with #{a} a second time"
      end
    end
    conf.load

    conf.run_hooks(hook_name, 'ARG', Puma::LogWriter.strings)
    assert_equal messages, ["#{hook_name} is called with ARG one time", "#{hook_name} is called with ARG a second time"]
  end
end

# contains tests that cannot run parallel
class TestConfigFileSingle < TestConfigFileBase
  def test_custom_logger_from_DSL
    conf = Puma::Configuration.new { |c| c.load 'test/config/custom_logger.rb' }

    conf.load
    out, _ = capture_subprocess_io { conf.options[:logger].write 'test' }

    assert_equal 'Custom logging: test', out
  end
end

# Thread unsafe modification of ENV
class TestEnvModifificationConfig < TestConfigFileBase
  def test_double_bind_port
    port = (rand(10_000) + 30_000).to_s
    with_env("PORT" => port) do
      conf = Puma::Configuration.new do |user_config, file_config, default_config|
        user_config.bind "tcp://#{Puma::Configuration::DEFAULTS[:tcp_host]}:#{port}"
        file_config.load "test/config/app.rb"
      end

      conf.load
      assert_equal ["tcp://0.0.0.0:#{port}"], conf.options[:binds]
    end
  end
end

class TestConfigEnvVariables < TestConfigFileBase
  def test_config_loads_correct_min_threads
    assert_equal 0, Puma::Configuration.new.options.default_options[:min_threads]


Review comment (suggestion):
```suggestion
    out, _ = capture_subprocess_io { conf.options[:custom_logger].write 'test' }
```

Code after:

    assert_equal true, conf.options[:silence_fork_callback_warning]
  end

  def test_http_content_length_limit
    assert_nil Puma::Configuration.new.options.default_options[:http_content_length_limit]

    conf = Puma::Configuration.new({ http_content_length_limit: 10000})

    assert_equal 10000, conf.final_options[:http_content_length_limit]
  end

  private

  def assert_run_hooks(hook_name, options = {})
    configured_with = options[:configured_with] || hook_name

    # test single, not an array
    messages = []
    conf = Puma::Configuration.new do |c|
      c.silence_fork_callback_warning
    end
    conf.options[hook_name] = -> (a) {
      messages << "#{hook_name} is called with #{a}"
    }

    conf.run_hooks(hook_name, 'ARG', Puma::LogWriter.strings)
    assert_equal messages, ["#{hook_name} is called with ARG"]

    # test multiple
    messages = []
    conf = Puma::Configuration.new do |c|
      c.silence_fork_callback_warning

      c.send(configured_with) do |a|
        messages << "#{hook_name} is called with #{a} one time"
      end

      c.send(configured_with) do |a|
        messages << "#{hook_name} is called with #{a} a second time"
      end
    end
    conf.load

    conf.run_hooks(hook_name, 'ARG', Puma::LogWriter.strings)
    assert_equal messages, ["#{hook_name} is called with ARG one time", "#{hook_name} is called with ARG a second time"]
  end

  def assert_warning_for_hooks_defined_in_single_mode(hook_name)
    out, _ = capture_io do
      conf = Puma::Configuration.new do |c|