Skip to content
Extraits de code Groupes Projets
Valider e1d86bdd rédigé par Maxwell Salzberg's avatar Maxwell Salzberg
Parcourir les fichiers

some tweaks so it fails gracefully on systems that do not have free command

parent fc941fa8
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -104,8 +104,8 @@ end ...@@ -104,8 +104,8 @@ end
# https://makandracards.com/makandra/950-speed-up-rspec-by-deferring-garbage-collection # https://makandracards.com/makandra/950-speed-up-rspec-by-deferring-garbage-collection
require File.join(File.dirname(__FILE__), "..", "..", "spec", "support", "deferred_garbage_collection") require File.join(File.dirname(__FILE__), "..", "..", "spec", "support", "deferred_garbage_collection")
Before do Before do
DeferredGarbageCollection.start unless ENV['TRAVIS'] DeferredGarbageCollection.start
end end
After do After do
DeferredGarbageCollection.reconsider unless ENV['TRAVIS'] DeferredGarbageCollection.reconsider
end end
...@@ -105,9 +105,9 @@ end ...@@ -105,9 +105,9 @@ end
# https://makandracards.com/makandra/950-speed-up-rspec-by-deferring-garbage-collection # https://makandracards.com/makandra/950-speed-up-rspec-by-deferring-garbage-collection
RSpec.configure do |config| RSpec.configure do |config|
config.before(:all) do config.before(:all) do
DeferredGarbageCollection.start unless ENV['TRAVIS'] DeferredGarbageCollection.start
end end
config.after(:all) do config.after(:all) do
DeferredGarbageCollection.reconsider unless ENV['TRAVIS'] DeferredGarbageCollection.reconsider
end end
end end
...@@ -7,16 +7,27 @@ class DeferredGarbageCollection ...@@ -7,16 +7,27 @@ class DeferredGarbageCollection
@@last_gc_run = Time.now @@last_gc_run = Time.now
def self.start def self.start
return if unsupported_enviroment
GC.disable if DEFERRED_GC_THRESHOLD > 0 GC.disable if DEFERRED_GC_THRESHOLD > 0
end end
def self.reconsider def self.memory_threshold
mem = %x(free).split(" ") mem = %x(free 2>/dev/null).to_s.split(" ")
percent_used = mem[8].to_i / (mem[7].to_i/100) return nil if mem.empty?
mem[8].to_i / (mem[7].to_i/100)
end
puts "percent memory used #{percent_used}" # just for info, as soon as we got some numbers remove it def self.reconsider
return if unsupported_enviroment
if( (DEFERRED_GC_THRESHOLD > 0 && Time.now - @@last_gc_run >= DEFERRED_GC_THRESHOLD) || percent_used > 90 ) if (percent_used = self.memory_threshold)
running_out_of_memory = percent_used > 90
puts "percent memory used #{percent_used}" # just for info, as soon as we got some numbers remove it
else
running_out_of_memory = false
end
if( (DEFERRED_GC_THRESHOLD > 0 && Time.now - @@last_gc_run >= DEFERRED_GC_THRESHOLD) || running_out_of_memory )
GC.enable GC.enable
GC.start GC.start
GC.disable GC.disable
...@@ -24,4 +35,8 @@ class DeferredGarbageCollection ...@@ -24,4 +35,8 @@ class DeferredGarbageCollection
end end
end end
def self.unsupported_enviroment
# ENV['TRAVIS']
end
end end
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter