Sha256: dfff4090d93e0287b4505b0d76abd409639a7bb5ffa3694ae7dc4a13f62430df

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

require 'test_helper'

class PumaWorkerKillerTest < Test::Unit::TestCase

  def test_worker_reaped
    ram      = 1 #mb
    cluster = FakeCluster.new
    reaper   = PumaWorkerKiller::Reaper.new(ram, cluster)
    worker_count = 10
    worker_count.times { cluster.add_worker }

    assert_equal worker_count, cluster.workers.count
    refute cluster.workers.detect {|w| w.is_term? }

    reaper.reap
    assert_equal 1, cluster.workers.select {|w| w.is_term? }.count

    reaper.reap
    assert_equal 2, cluster.workers.select {|w| w.is_term? }.count

    reaper.reap
    assert_equal 3, cluster.workers.select {|w| w.is_term? }.count
  ensure
    cluster.workers.map(&:term)
  end

  def test_kills_memory_leak
    ram     = 75 #mb
    cluster = FakeCluster.new
    reaper  = PumaWorkerKiller::Reaper.new(ram, cluster)
    while reaper.get_total_memory < (ram * 0.80)
      cluster.add_worker
    end

    reaper.reap
    assert_equal 0, cluster.workers.select {|w| w.is_term? }.count

    while reaper.get_total_memory < ram
      cluster.add_worker
    end

    reaper.reap
    assert_equal 1, cluster.workers.select {|w| w.is_term? }.count
  ensure
    cluster.workers.map(&:term)
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
puma_worker_killer-0.0.1 test/puma_worker_killer_test.rb