summaryrefslogtreecommitdiff
path: root/spec/spec_helper.rb
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2017-12-06 14:47:44 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2017-12-06 14:47:44 -0800
commit3ae6fa908e5914113cf9b7c3d99f7eb7d6bd3c04 (patch)
tree450c31c97debe42cdb45acb7c446ce7c48f04785 /spec/spec_helper.rb
parenta987ec745a70ff683e2ee80af044b9f5e32854c9 (diff)
downloadchef-3ae6fa908e5914113cf9b7c3d99f7eb7d6bd3c04.tar.gz
speedup lwrp tests
reset the global resource and provider handler maps before each and every test. note that mutation through the top-level keys will get preserved so this is not perfect, but deep-duping through every single test we run becomes expensive. this is sufficient to flush out the global state of all the test lwrp fixtures that we setup. it discovered several usage bugs where we either relied on this feature or where we were testing different fixtures from the ones we thought we were. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'spec/spec_helper.rb')
-rw-r--r--spec/spec_helper.rb19
1 files changed, 19 insertions, 0 deletions
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