Skip to content

Commit

Permalink
Memoize rspec-puppet-facts
Browse files Browse the repository at this point in the history
Collection of facts can be slow. By memoizing subsequent calls are sped
up greatly.

In puppet-nginx test collection was reduced from 1 minute 52 seconds
down to 15 seconds. That has 9 calls to on_supported_os.
  • Loading branch information
ekohl committed Apr 11, 2020
1 parent 1f75cca commit 5fb4475
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/voxpupuli/test/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ def suggest_facter_version
require 'rspec-puppet-facts'
include RspecPuppetFacts

# Generating facts is slow - this memoizes the facts between multiple classes.
# Marshalling is used to get unique instances which helps when tests overrides
# facts.
FACTS_CACHE = {}
def on_supported_os(opts = {})
result = FACTS_CACHE[opts.to_s] ||= super(opts)
Marshal.load(Marshal.dump(result))
end

RSpec.configure do |config|
config.default_facter_version = suggest_facter_version

Expand Down

0 comments on commit 5fb4475

Please sign in to comment.