diff options
author | Paul Berry <paul@puppetlabs.com> | 2010-09-17 17:59:56 -0700 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2010-09-23 09:21:09 +1000 |
commit | 2b50f30c703aca5c4f3e89961d64a94d886296bd (patch) | |
tree | 1a3ab423cf49ae44dca69cb7b88904a1b615b3de /spec | |
parent | 7b8cb741596c7a20a25caf4250d86d7e1c24f319 (diff) | |
download | puppet-2b50f30c703aca5c4f3e89961d64a94d886296bd.tar.gz puppet-2b50f30c703aca5c4f3e89961d64a94d886296bd.tar.xz puppet-2b50f30c703aca5c4f3e89961d64a94d886296bd.zip |
[#4771] Import of manifests with the same name only happens once
The function import_if_possible, which was supposed to be responsible
for making sure that no two threads tried to import the same file at
the same time, was not making this decision based on the full pathname
of the file, since it was being invoked before pathnames were
resolved. As a result, if we attempted to import two distinct files
with the same name at the same time (either in two threads or in a
single thread due to recursion), one of the files would not always get
imported.
Fixed this problem by moving the thread-safety logic to happen after
filenames are resolved to absolute paths. This made it possible to
simplify the thread-safety logic significantly.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/puppet_spec/files.rb | 1 | ||||
-rw-r--r-- | spec/unit/parser/type_loader_spec.rb | 19 |
2 files changed, 4 insertions, 16 deletions
diff --git a/spec/lib/puppet_spec/files.rb b/spec/lib/puppet_spec/files.rb index cab4a1e47..52ed903ec 100644 --- a/spec/lib/puppet_spec/files.rb +++ b/spec/lib/puppet_spec/files.rb @@ -1,4 +1,5 @@ require 'fileutils' +require 'tempfile' # A support module for testing files. module PuppetSpec::Files diff --git a/spec/unit/parser/type_loader_spec.rb b/spec/unit/parser/type_loader_spec.rb index 83006b37b..02d543b02 100644 --- a/spec/unit/parser/type_loader_spec.rb +++ b/spec/unit/parser/type_loader_spec.rb @@ -77,13 +77,6 @@ describe Puppet::Parser::TypeLoader do @loader.load_until(["foo"], "bar") { |f| false }.should be_nil end - it "should know when a given name has been loaded" do - @loader.expects(:name2files).returns %w{file} - @loader.expects(:import).with("file",nil) - @loader.load_until(["foo"], "bar") { |f| true } - @loader.should be_loaded("file") - end - it "should set the module name on any created resource types" do type = Puppet::Resource::Type.new(:hostclass, "mytype") @@ -113,7 +106,8 @@ describe Puppet::Parser::TypeLoader do describe "when importing" do before do Puppet::Parser::Files.stubs(:find_manifests).returns ["modname", %w{file}] - @loader.stubs(:parse_file) + Puppet::Parser::Parser.any_instance.stubs(:parse) + Puppet::Parser::Parser.any_instance.stubs(:file=) end it "should return immediately when imports are being ignored" do @@ -154,16 +148,9 @@ describe Puppet::Parser::TypeLoader do @loader.import("myfile", "/current/file") end - it "should know when a given file has been imported" do - Puppet::Parser::Files.expects(:find_manifests).returns ["modname", %w{/one}] - @loader.import("myfile") - - @loader.should be_imported("/one") - end - it "should not attempt to import files that have already been imported" do Puppet::Parser::Files.expects(:find_manifests).returns ["modname", %w{/one}] - @loader.expects(:parse_file).once + Puppet::Parser::Parser.any_instance.expects(:parse).once @loader.import("myfile") # This will fail if it tries to reimport the file. |