Skip to content
This repository has been archived by the owner on Aug 29, 2018. It is now read-only.

Commit

Permalink
Bug 1104902 - Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jwhonce authored and Andy Grimm committed Jun 17, 2014
1 parent 115b72f commit 4a5e999
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions node/test/unit/oom_plugin_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

require 'date'

# if File.exist? '../../../node-util/conf/watchman/plugins.d/oom_plugin.rb'
require_relative '../../../node-util/conf/watchman/plugins.d/oom_plugin'

class OomPluginTest < OpenShift::NodeBareTestCase
Expand All @@ -30,49 +29,53 @@ def setup
@gears.stubs(:ids).returns @uuids
@gears.stubs(:empty?).returns @uuids.empty?

@operation = mock
@operation = mock('operation')

templates = {
default: {'foo' => '1', 'bar' => '2', 'baz' => '3', 'a' => 'c'},
}

parameters = templates[:default]

@libcgroup_mock = mock('OpenShift::Runtime::Utils::Cgroups::Libcgroup')
@libcgroup_mock.stubs(:parameters).returns(parameters)
end

def test_no_oom_control
cgroup = mock
cgroup.expects(:fetch).
@libcgroup_mock.expects(:fetch).
with('memory.oom_control').
returns({'memory.oom_control' => {'under_oom' => '0'}}).
times(@uuids.length)
OpenShift::Runtime::Utils::Cgroups::Libcgroup.expects(:new).
with(any_of(*@uuids)).
returns(cgroup).
returns(@libcgroup_mock).
times(@uuids.length)
@operation.expects(:call).never

OomPlugin.new(nil, nil, @gears, @operation).apply(nil)
end

def test_oom_control
cgroup = mock
cgroup.expects(:fetch).
@libcgroup_mock.expects(:fetch).
with('memory.oom_control').
returns({'memory.oom_control' =>
{'under_oom' => '1',
'oom_kill_disable' => '0'}}).
times(@uuids.length)
cgroup.expects(:fetch).with(OomPlugin::MEMSW_LIMIT).returns({OomPlugin::MEMSW_LIMIT => 1024}).times(3)
cgroup.expects(:fetch).with(OomPlugin::MEMSW_USAGE).returns({OomPlugin::MEMSW_LIMIT => 1024}).times(3)
cgroup.expects(:store).with(OomPlugin::MEMSW_LIMIT, kind_of(Fixnum)).times(@uuids.length * 2)
@libcgroup_mock.expects(:fetch).with(OomPlugin::MEMSW_LIMIT).returns({OomPlugin::MEMSW_LIMIT => 1024}).times(3)
@libcgroup_mock.expects(:fetch).with(OomPlugin::MEMSW_USAGE).returns({OomPlugin::MEMSW_LIMIT => 1024}).times(3)
@libcgroup_mock.expects(:store).with(OomPlugin::MEMSW_LIMIT, kind_of(Fixnum)).times(@uuids.length * 2)

OpenShift::Runtime::ApplicationContainer.expects(:from_uuid).
OpenShift::Runtime::ApplicationContainer.stubs(:from_uuid).
with(any_of(*@uuids)).
returns(nil).
times(@uuids.length)
returns(nil)

OpenShift::Runtime::Utils::Cgroups::Libcgroup.expects(:new).
OpenShift::Runtime::Utils::Cgroups::Libcgroup.stubs(:new).
with(any_of(*@uuids)).
returns(cgroup).
times(@uuids.length)
returns(@libcgroup_mock)

@operation.expects(:call).with(:restart, any_of(*@uuids)).times(3)
@operation.expects(:call).with(:start, any_of(*@uuids)).times(3)

OomPlugin.new(nil, nil, @gears, @operation, 0).apply(nil)
end
end
# end

0 comments on commit 4a5e999

Please sign in to comment.