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
Charles Lowell d969b1cdb9 add back the basics of memory testing.
This adds back the memory tests which ensure The Ruby Racer's
stability. It also includes the changes needed to make these initial
specs pass.

At this point to disallow calling Dispose() directly on the underlying
Isolate. If you do, then you could have all of the Ruby objects happily
sitting in memory, but trying to use them would result in a segfault for
trying to use a dead isolate. In order to avoid that, we'd have to put
in safeguards everywhere to make sure for any operation on any context
or object, that it's isolate was still alive.

In order to reduce the complexity of memory management, the safest thing
is to let the garbage collection hook dispose of the isolate
itself. That way there is no doubt that the isolate is no longer in use.
2015-07-28 18:02:58 +03:00

45 lines
1.3 KiB
Ruby

require 'spec_helper'
describe "A Very blunt test to make sure that we aren't doing stupid leaks", :memory => true do
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::Isolate.new
@start_memory = process_memory
GC.stress = true
end
after do
GC.stress = false
end
it "can create 3 isolates in a row" do
3.times { V8::Isolate.new }
end
it "won't increase process memory by more than 50% no matter how many contexts we create" do
250.times do
isolate = V8::Context.new.isolate.native
isolate.IdleNotificationDeadline(0.1)
end
expect(process_memory).to be <= @start_memory * 1.5
end
it "can eval simple value passing statements repeatedly without significantly increasing memory" do
V8::Context.new do |cxt|
500.times do
cxt.eval('7 * 6')
cxt.isolate.native.IdleNotificationDeadline(0.1)
end
end
expect(process_memory).to be <= @start_memory * 1.1
end
def process_memory
/\w*[ ]*#{Process.pid}[ ]*([.,\d]*)[ ]*([.,\d]*)[ ]*([\d]*)[ ]*([\d]*)/.match(`ps aux`)[4].to_i
end
end