Skip to content

Instantly share code, notes, and snippets.

@robotarmy
Created November 18, 2010 23:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robotarmy/705850 to your computer and use it in GitHub Desktop.
Save robotarmy/705850 to your computer and use it in GitHub Desktop.
BEST TEST EVER!
require 'test/unit'
require 'rubygems'
require 'wrong'
require 'wrong/adapters/test_unit'
require 'memory_watch'
class MemoryWatchTest < Test::Unit::TestCase
def test_watches_self
cmd = %q{ruby memory_watch.rb --delay 999999 --num_cycles 9900000099}
pid = fork { %x{#{cmd}} }
Process.detach(pid)
wm = MemoryWatch.new(:watch => cmd , :high_water_mb => 0.01,:delay => 0.1, :num_cycles => 1)
wm.cycle
assert {
wm.high_water_pids.size == 1
}
wm.pids.each do |pid|
%x{kill -9 #{pid}}
end
end
def test_runs_callback
test_magiggy = false
wm = MemoryWatch.new(:watch => File.basename(__FILE__),
:high_water_mb => 0,
:num_cycles => 1,
:delay => 0.01,
:num_over_marks => 0,
:callback => lambda {|pid|
test_magiggy = pid
})
wm.cycle
assert {
wm.high_water_pids.include? test_magiggy
}
end
end
@robotarmy
Copy link
Author

art.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment