Sha256: 1d0d298a2dc0a0ba6cbc004bacedb85339ec85a2732c17d669c99ec66fbe22ec

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

Bundler.require

require 'test/unit'

class PumaRemote

  attr_accessor :path, :frequency, :config, :log, :ram, :pid

  def initialize(options = {})
    @path      = options[:path]      || fixture_path("app.ru")
    @frequency = options[:frequency] || 1
    @config    = options[:config]    || fixture_path("config.rb")
    @log       = options[:log]       || new_log_file
    @ram       = options[:ram]       || 512
  end

  def wait
    until log.read.match %r{booted}
      sleep 1
    end
    sleep 1
    self
  end

  def shutdown
    if pid
      Process.kill('TERM', pid)
      Process.wait(pid)
    end

    FileUtils.remove_entry_secure log
  end

  def spawn
    FileUtils.mkdir_p(log.dirname)
    FileUtils.touch(log)
    @pid = Process.spawn("exec env PUMA_FREQUENCY=#{frequency} PUMA_RAM=#{ram} bundle exec puma #{path} -C #{config} > #{log}")
    self
  end

  def new_log_file
    Pathname.new("test/logs/puma_#{rand(1...2000)}_#{Time.now.to_f}.log")
  end

  def fixture_path(name = nil)
    path = Pathname.new(File.expand_path("../fixtures", __FILE__))
    return path.join(name) if name
    path
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
puma_auto_tune-0.0.1 test/test_helper.rb