在我的Google Compute服务器上使用3.75 GB的RAM运行rspec模型测试时,我经常会遇到内存分配错误,而在使用2 GB内存的普通计算机上运行相同的测试时,我无法获得这些错误。我使用的命令是&rs; rspec spec / models'以便所有测试都运行。当我运行任何其他类型的rspec测试时,这不会发生。
在我的普通机器上,584个测试中只有2个失败(目前这是预期的行为)。但是,当我使用Google Compute服务器时会出现148次失败,这是我从顶部获得的输出示例:
Run options: include {:focus=>true}
All examples were filtered out; ignoring {:focus=>true}
....................F.FF.......................................................................................................................FFF.FF.F.............................................................................................................................F..F.F.F..FF.F...F.FF..F..F..F....F.FFF..FF.F.FF.FFFF.F.FFFFF.FF..F.FF.FFF...F.FFF...FFFF.FFFF.F.F.FF...............................................FF..F.F.FF.FF.FF.F...F.F.F..F.F.F.F......F.F...F.F.F.FF..FF.F.FFF..FF.FF.F..F..........FFFFFFFFFFFFFFFFFFFF
An error occurred in an after(:all) hook.
Errno::ENOMEM: Cannot allocate memory - rm -rf /home/patrick/terrabase/imperial/files/test
occurred at /home/patrick/.rvm/gems/ruby-1.9.3-p194@imperialhorizons/gems/activesupport-3.2.22/lib/active_support/core_ext/kernel/agnostics.rb:7:in ``'
.
An error occurred in an after(:all) hook.
Errno::ENOMEM: Cannot allocate memory - rm -rf /home/patrick/terrabase/imperial/files/test
occurred at /home/patrick/.rvm/gems/ruby-1.9.3-p194@imperialhorizons/gems/activesupport-3.2.22/lib/active_support/core_ext/kernel/agnostics.rb:7:in ``'
....
An error occurred in an after(:all) hook.
Errno::ENOMEM: Cannot allocate memory - rm -rf /home/patrick/terrabase/imperial/files/test
occurred at /home/patrick/.rvm/gems/ruby-1.9.3-p194@imperialhorizons/gems/activesupport-3.2.22/lib/active_support/core_ext/kernel/agnostics.rb:7:in ``'
.
An error occurred in an after(:all) hook.
Errno::ENOMEM: Cannot allocate memory - rm -rf /home/patrick/terrabase/imperial/files/test
occurred at /home/patrick/.rvm/gems/ruby-1.9.3-p194@imperialhorizons/gems/activesupport-3.2.22/lib/active_support/core_ext/kernel/agnostics.rb:7:in ``'
.
...继续这样做直到失败'底部的部分:
142) LibraryBarcodeImport#process_row update existing student if the cid matches should set the imported count to 1
Failure/Error: let(:library_barcode_import) { FactoryGirl.build(:library_barcode_import, log_text: "", imported_count: 0) }
Errno::ENOMEM:
Cannot allocate memory - file -b --mime '/home/patrick/terrabase/imperial/spec/testfiles/barcodes.xlsx'
# ./spec/models/library_barcode_import_spec.rb:57:in `block (3 levels) in <top (required)>'
# ./spec/models/library_barcode_import_spec.rb:103:in `block (4 levels) in <top (required)>'
我注意到有些测试在运行之前就失败了。例如,library_barcode_import_spec.rb中的第57行是:
let(:library_barcode_import) { FactoryGirl.build(:library_barcode_import, log_text: "", imported_count: 0) }
...而第103行是在&#39;之前的&#39;语句:
before do
library_barcode_import.process_row(spreadsheet_row, 1, checking )
end
软件:
虚拟机规格:
物理机器规格:
虚拟机上没有可用的RAM,正如您可以从&#39; free -m&#39;
的输出中看到的那样。 total used free shared buffers cached
Mem: 3700 947 2753 14 80 531
-/+ buffers/cache: 336 3364
Swap: 0 0 0
来自&#39; dmesg |的输出grep -i virtual&#39;表明服务器依赖于KVM:
[ 0.000000] Booting paravirtualized kernel on KVM
我在Google上搜索时找不到任何有助于解决问题的方法。有谁知道可能导致这种情况的原因?