Cache MockLoader.connection.

Speeds up test/unit/profile/profile_context_test from 7-8s to 0.5s.

Signed-off-by: Ryan Davis <zenspider@chef.io>
This commit is contained in:
Ryan Davis 2019-12-17 16:42:21 -08:00
parent a0ffa67b71
commit 313f3462ca

View file

@ -42,6 +42,10 @@ class MockLoader
@platform = OPERATING_SYSTEMS[os]
end
def self.connection
@connection ||= Train.create("local", command_runner: :generic).connection
end
def backend
return @backend if defined?(@backend)
@ -52,7 +56,7 @@ class MockLoader
mock = @backend.backend
# create all mock files
local = Train.create("local", command_runner: :generic).connection
local = MockLoader.connection
# set os emulation
mock.mock_os(@platform)