Sha256: 6d718a1e15e6e90dac0953c727879ecadbf423ca2a0bafb9fa81cf041cadbb66
Contents?: true
Size: 1.7 KB
Versions: 2
Compression:
Stored size: 1.7 KB
Contents
require 'test_helper' class PumaWorkerKillerTest < Test::Unit::TestCase def test_starts app_path = fixture_path.join("app.ru") port = 0 # http://stackoverflow.com/questions/200484/how-do-you-find-a-free-tcp-server-port-using-ruby puma_log = Pathname.new "puma.log" `rm #{puma_log}; touch #{puma_log}` pid = Process.spawn("PUMA_FREQUENCY=1 bundle exec puma #{app_path} -t 1:1 -w 5 --preload --debug -p #{port} > #{puma_log}") sleep 5 assert_match "PumaWorkerKiller:", puma_log.read ensure Process.kill('TERM', pid) if pid end 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 = rand(75..100) #mb cluster = FakeCluster.new reaper = PumaWorkerKiller::Reaper.new(ram, cluster) while reaper.get_total_memory < (ram * 0.80) cluster.add_worker sleep 0.01 end reaper.reap assert_equal 0, cluster.workers.select {|w| w.is_term? }.count until reaper.get_total_memory > ram cluster.add_worker sleep 0.01 end reaper.reap assert_equal 1, cluster.workers.select {|w| w.is_term? }.count ensure cluster.workers.map(&:term) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
puma_worker_killer-0.0.3 | test/puma_worker_killer_test.rb |
puma_worker_killer-0.0.2 | test/puma_worker_killer_test.rb |