diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2017-12-06 19:58:00 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-06 19:58:00 -0800 |
commit | 804d61eecefd9b9d87e42f5cde5386be511a044b (patch) | |
tree | 518645fff2791c0174fd9ba42b3c76ba17b54cea | |
parent | 983385347d74535bab9d4ed6cf1f2692b110106a (diff) | |
parent | b2e89e61260475a282e6d256843cf81d244a82cd (diff) | |
download | chef-804d61eecefd9b9d87e42f5cde5386be511a044b.tar.gz |
Merge pull request #6625 from chef/lcg/lwrp-test-speedup
speedup lwrp tests
-rw-r--r-- | spec/integration/recipes/noop_resource_spec.rb | 2 | ||||
-rw-r--r-- | spec/integration/recipes/recipe_dsl_spec.rb | 60 | ||||
-rw-r--r-- | spec/integration/recipes/resource_action_spec.rb | 2 | ||||
-rw-r--r-- | spec/spec_helper.rb | 19 | ||||
-rw-r--r-- | spec/unit/lwrp_spec.rb | 8 |
5 files changed, 56 insertions, 35 deletions
diff --git a/spec/integration/recipes/noop_resource_spec.rb b/spec/integration/recipes/noop_resource_spec.rb index e0cf47c371..db6b668553 100644 --- a/spec/integration/recipes/noop_resource_spec.rb +++ b/spec/integration/recipes/noop_resource_spec.rb @@ -4,7 +4,7 @@ describe "Resources with a no-op provider" do include IntegrationSupport context "with noop provider providing foo" do - before(:context) do + before(:each) do class NoOpFoo < Chef::Resource resource_name "hi_there" default_action :update diff --git a/spec/integration/recipes/recipe_dsl_spec.rb b/spec/integration/recipes/recipe_dsl_spec.rb index f7a0e8b6e8..f9970afc92 100644 --- a/spec/integration/recipes/recipe_dsl_spec.rb +++ b/spec/integration/recipes/recipe_dsl_spec.rb @@ -12,7 +12,7 @@ describe "Recipe DSL methods" do before { Namer.current_index += 1 } context "with resource 'base_thingy' declared as BaseThingy" do - before(:context) do + before(:each) do class BaseThingy < Chef::Resource resource_name "base_thingy" @@ -66,7 +66,7 @@ describe "Recipe DSL methods" do end context "nameless resources" do - before(:context) do + before(:each) do class NamelessThingy < BaseThingy resource_name :nameless_thingy provides :nameless_thingy @@ -91,7 +91,7 @@ describe "Recipe DSL methods" do end context "with a resource named RecipeDSLSpecNamespace::Bar::BarThingy" do - before(:context) do + before(:each) do class RecipeDSLSpecNamespace::Bar::BarThingy < BaseThingy end @@ -106,7 +106,7 @@ describe "Recipe DSL methods" do end context "with a resource named Chef::Resource::NoNameThingy with resource_name nil" do - before(:context) do + before(:each) do class Chef::Resource::NoNameThingy < BaseThingy resource_name nil @@ -122,7 +122,7 @@ describe "Recipe DSL methods" do end context "with a resource named AnotherNoNameThingy with resource_name :another_thingy_name" do - before(:context) do + before(:each) do class AnotherNoNameThingy < BaseThingy resource_name :another_thingy_name @@ -146,7 +146,7 @@ describe "Recipe DSL methods" do end context "with a resource named AnotherNoNameThingy2 with resource_name :another_thingy_name2; resource_name :another_thingy_name3" do - before(:context) do + before(:each) do class AnotherNoNameThingy2 < BaseThingy resource_name :another_thingy_name2 @@ -178,7 +178,7 @@ describe "Recipe DSL methods" do context "provides overriding resource_name" do context "with a resource named AnotherNoNameThingy3 with provides :another_no_name_thingy3, os: 'blarghle'" do - before(:context) do + before(:each) do class AnotherNoNameThingy3 < BaseThingy resource_name :another_no_name_thingy_3 @@ -207,7 +207,7 @@ describe "Recipe DSL methods" do end context "with a resource named AnotherNoNameThingy4 with two provides" do - before(:context) do + before(:each) do class AnotherNoNameThingy4 < BaseThingy resource_name :another_no_name_thingy_4 @@ -247,7 +247,7 @@ describe "Recipe DSL methods" do end context "with a resource named AnotherNoNameThingy5, a different resource_name, and a provides with the original resource_name" do - before(:context) do + before(:each) do class AnotherNoNameThingy5 < BaseThingy resource_name :another_thingy_name_for_another_no_name_thingy5 @@ -284,7 +284,7 @@ describe "Recipe DSL methods" do end context "with a resource named AnotherNoNameThingy6, a provides with the original resource name, and a different resource_name" do - before(:context) do + before(:each) do class AnotherNoNameThingy6 < BaseThingy provides :another_no_name_thingy6, os: "blarghle" @@ -321,7 +321,7 @@ describe "Recipe DSL methods" do end context "with a resource named AnotherNoNameThingy7, a new resource_name, and provides with that new resource name" do - before(:context) do + before(:each) do class AnotherNoNameThingy7 < BaseThingy resource_name :another_thingy_name_for_another_no_name_thingy7 @@ -359,7 +359,7 @@ describe "Recipe DSL methods" do # opposite order from the previous test (provides, then resource_name) context "with a resource named AnotherNoNameThingy8, a provides with a new resource name, and resource_name with that new resource name" do - before(:context) do + before(:each) do class AnotherNoNameThingy8 < BaseThingy provides :another_thingy_name_for_another_no_name_thingy8, os: "blarghle" @@ -399,7 +399,7 @@ describe "Recipe DSL methods" do context "provides" do context "when MySupplier provides :hemlock" do - before(:context) do + before(:each) do class RecipeDSLSpecNamespace::MySupplier < BaseThingy resource_name :hemlock @@ -422,7 +422,7 @@ describe "Recipe DSL methods" do end context "when Thingy3 has resource_name :thingy3" do - before(:context) do + before(:each) do class RecipeDSLSpecNamespace::Thingy3 < BaseThingy resource_name :thingy3 @@ -438,7 +438,7 @@ describe "Recipe DSL methods" do end context "and Thingy4 has resource_name :thingy3" do - before(:context) do + before(:each) do class RecipeDSLSpecNamespace::Thingy4 < BaseThingy resource_name :thingy3 @@ -466,7 +466,7 @@ describe "Recipe DSL methods" do end context "when Thingy5 has resource_name :thingy5 and provides :thingy5reverse, :thingy5_2 and :thingy5_2reverse" do - before(:context) do + before(:each) do class RecipeDSLSpecNamespace::Thingy5 < BaseThingy resource_name :thingy5 @@ -485,7 +485,7 @@ describe "Recipe DSL methods" do end context "and Thingy6 provides :thingy5" do - before(:context) do + before(:each) do class RecipeDSLSpecNamespace::Thingy6 < BaseThingy resource_name :thingy6 @@ -513,7 +513,7 @@ describe "Recipe DSL methods" do end context "and AThingy5 provides :thingy5reverse" do - before(:context) do + before(:each) do class RecipeDSLSpecNamespace::AThingy5 < BaseThingy resource_name :thingy5reverse @@ -530,7 +530,7 @@ describe "Recipe DSL methods" do end context "and ZRecipeDSLSpecNamespace::Thingy5 provides :thingy5_2" do - before(:context) do + before(:each) do module ZRecipeDSLSpecNamespace class Thingy5 < BaseThingy @@ -549,7 +549,7 @@ describe "Recipe DSL methods" do end context "and ARecipeDSLSpecNamespace::Thingy5 provides :thingy5_2" do - before(:context) do + before(:each) do module ARecipeDSLSpecNamespace class Thingy5 < BaseThingy @@ -569,7 +569,7 @@ describe "Recipe DSL methods" do end context "when Thingy3 has resource_name :thingy3" do - before(:context) do + before(:each) do class RecipeDSLSpecNamespace::Thingy3 < BaseThingy resource_name :thingy3 @@ -585,7 +585,7 @@ describe "Recipe DSL methods" do end context "and Thingy4 has resource_name :thingy3" do - before(:context) do + before(:each) do class RecipeDSLSpecNamespace::Thingy4 < BaseThingy resource_name :thingy3 @@ -612,7 +612,7 @@ describe "Recipe DSL methods" do end context "and Thingy4 has resource_name :thingy3" do - before(:context) do + before(:each) do class RecipeDSLSpecNamespace::Thingy4 < BaseThingy resource_name :thingy3 @@ -642,7 +642,7 @@ describe "Recipe DSL methods" do end context "when Thingy7 provides :thingy8" do - before(:context) do + before(:each) do class RecipeDSLSpecNamespace::Thingy7 < BaseThingy resource_name :thingy7 @@ -652,7 +652,7 @@ describe "Recipe DSL methods" do end context "and Thingy8 has resource_name :thingy8" do - before(:context) do + before(:each) do class RecipeDSLSpecNamespace::Thingy8 < BaseThingy resource_name :thingy8 @@ -681,7 +681,7 @@ describe "Recipe DSL methods" do end context "when Thingy12 provides :thingy12, :twizzle and :twizzle2" do - before(:context) do + before(:each) do class RecipeDSLSpecNamespace::Thingy12 < BaseThingy resource_name :thingy12 @@ -714,7 +714,7 @@ describe "Recipe DSL methods" do end context "with platform-specific resources 'my_super_thingy_foo' and 'my_super_thingy_bar'" do - before(:context) do + before(:each) do class MySuperThingyFoo < BaseThingy resource_name :my_super_thingy_foo provides :my_super_thingy, platform: "foo" @@ -760,7 +760,7 @@ describe "Recipe DSL methods" do end context "when Thingy10 provides :thingy10" do - before(:context) do + before(:each) do class RecipeDSLSpecNamespace::Thingy10 < BaseThingy resource_name :thingy10 end @@ -775,7 +775,7 @@ describe "Recipe DSL methods" do end context "when Thingy11 provides :thingy11" do - before(:context) do + before(:each) do class RecipeDSLSpecNamespace::Thingy11 < BaseThingy resource_name :thingy10 end @@ -1309,7 +1309,7 @@ describe "Recipe DSL methods" do end context "with UTF-8 provides" do - before(:context) do + before(:each) do class UTF8Thingy < BaseThingy resource_name :Straße provides :Straße diff --git a/spec/integration/recipes/resource_action_spec.rb b/spec/integration/recipes/resource_action_spec.rb index f5f2d4a764..53f25cb35b 100644 --- a/spec/integration/recipes/resource_action_spec.rb +++ b/spec/integration/recipes/resource_action_spec.rb @@ -229,7 +229,7 @@ module ResourceActionSpec end context "And 'action_jackgrandson' inheriting from ActionJackson and changing nothing" do - before(:context) do + before(:each) do class ActionJackgrandson < ActionJackson use_automatic_resource_name end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index bace94fcbe..10e9818834 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -111,6 +111,11 @@ TEST_PLATFORM = TEST_NODE["platform"] TEST_PLATFORM_VERSION = TEST_NODE["platform_version"] TEST_PLATFORM_FAMILY = TEST_NODE["platform_family"] +provider_priority_map ||= nil +resource_priority_map ||= nil +provider_handler_map ||= nil +resource_handler_map ||= nil + RSpec.configure do |config| config.include(Matchers) config.include(MockShellout::RSpec) @@ -233,6 +238,20 @@ RSpec.configure do |config| # Set environment variable so the setting persists in child processes ENV["CHEF_TREAT_DEPRECATION_WARNINGS_AS_ERRORS"] = "1" + + # we don't perfectly reset the priority/handler maps here, but by dup'ing the top level hash we + # throw away all the garbage resources and providers that we setup. if we mutate something like + # :package then that'll carry over from test-to-test, but the solution would be to deep-dup on every + # single test we run which is much more expensive. by throwing away the garbage top level keys we + # significantly speed up test runs. + provider_handler_map ||= Chef.provider_handler_map.send(:map).dup + resource_handler_map ||= Chef.resource_handler_map.send(:map).dup + provider_priority_map ||= Chef.provider_priority_map.send(:map).dup + resource_priority_map ||= Chef.resource_priority_map.send(:map).dup + Chef.provider_handler_map.instance_variable_set(:@map, provider_handler_map.dup) + Chef.resource_handler_map.instance_variable_set(:@map, resource_handler_map.dup) + Chef.provider_priority_map.instance_variable_set(:@map, provider_priority_map.dup) + Chef.resource_priority_map.instance_variable_set(:@map, resource_priority_map.dup) end # raise if anyone commits any test to CI with :focus set on it diff --git a/spec/unit/lwrp_spec.rb b/spec/unit/lwrp_spec.rb index 75ebbb8f02..009bc5f4b1 100644 --- a/spec/unit/lwrp_spec.rb +++ b/spec/unit/lwrp_spec.rb @@ -571,14 +571,16 @@ describe "LWRP" do context "resource class created" do let(:test_lwrp_class) { @test_lwrp_class } - before(:context) do - @tmpdir = Dir.mktmpdir("lwrp_test") + before(:each) do + @tmpparent = Dir.mktmpdir("lwrp_test") + @tmpdir = File.join(@tmpparent, "lwrp") + Dir.mkdir(@tmpdir) resource_path = File.join(@tmpdir, "once.rb") IO.write(resource_path, "default_action :create") @test_lwrp_class = Chef::Resource::LWRPBase.build_from_file("lwrp", resource_path, nil) end - after(:context) do + after(:each) do FileUtils.remove_entry @tmpdir end |