1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00
therubyracer/spec/mem/blunt_spec.rb

43 lines
1.1 KiB
Ruby
Raw Normal View History

2012-05-01 11:53:01 -07:00
require 'spec_helper'
describe "A Very blunt test to make sure that we aren't doing stupid leaks", :memory => true do
2012-05-01 11:53:01 -07:00
before do
if Object.const_defined?(:RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
pending 'need to figure out how to do memory sanity checks on rbx'
end
#allocate a single context to make sure that v8 loads its snapshot and
#we pay the overhead.
V8::Context.new
2012-05-01 11:53:01 -07:00
@start_memory = process_memory
GC.stress = true
end
2012-05-01 11:53:01 -07:00
after do
GC.stress = false
end
2012-05-11 10:45:45 -05:00
it "won't increase process memory by more than 50% no matter how many contexts we create" do
2012-05-17 11:04:17 -05:00
500.times do
V8::Context.new
run_v8_gc
2012-05-01 11:53:01 -07:00
end
process_memory.should <= @start_memory * 1.5
2012-05-01 11:53:01 -07:00
end
it "can eval simple value passing statements repeatedly without significantly increasing memory" do
V8::C::Locker() do
cxt = V8::Context.new
500.times do
cxt.eval('7 * 6')
run_v8_gc
end
end
process_memory.should <= @start_memory * 1.1
end
2012-05-01 11:53:01 -07:00
def process_memory
/\w*[ ]*#{Process.pid}[ ]*([.,\d]*)[ ]*([.,\d]*)[ ]*([\d]*)[ ]*([\d]*)/.match(`ps aux`)[4].to_i
end
end