diff options
| author | James Turnbull <james@lovedthanlost.net> | 2008-12-27 12:43:52 +1100 |
|---|---|---|
| committer | James Turnbull <james@lovedthanlost.net> | 2008-12-27 12:43:52 +1100 |
| commit | 4c648bb1e7428806550f57160f72892709b0a30f (patch) | |
| tree | feb1108c0608a95ec088554dae7753d2c9609a14 /spec/integration | |
| parent | 34335b7a2e6950d4bb3dcaaf2bfe88cbc684007e (diff) | |
| parent | 7403330c4f63c290ba3cc5992706a3f0b1c9caa0 (diff) | |
| download | puppet-4c648bb1e7428806550f57160f72892709b0a30f.tar.gz puppet-4c648bb1e7428806550f57160f72892709b0a30f.tar.xz puppet-4c648bb1e7428806550f57160f72892709b0a30f.zip | |
Merge branch '0.24.x'
Conflicts:
CHANGELOG
Diffstat (limited to 'spec/integration')
| -rwxr-xr-x | spec/integration/util/file_locking.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/spec/integration/util/file_locking.rb b/spec/integration/util/file_locking.rb new file mode 100755 index 000000000..680b3d1ed --- /dev/null +++ b/spec/integration/util/file_locking.rb @@ -0,0 +1,36 @@ +#!/usr/bin/env ruby + +Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") } + +require 'puppet/util/file_locking' + +describe Puppet::Util::FileLocking do + it "should be able to keep file corruption from happening when there are multiple writers" do + file = Tempfile.new("puppetspec") + file.close!() + file = file.path + data = {:a => :b, :c => "A string", :d => "another string", :e => %w{an array of strings}} + File.open(file, "w") { |f| f.puts YAML.dump(data) } + + threads = [] + sync = Sync.new + 9.times { |a| + threads << Thread.new { + 9.times { |b| + sync.synchronize(Sync::SH) { + Puppet::Util::FileLocking.readlock(file) { |f| + YAML.load(f.read).should == data + } + } + sleep 0.01 + sync.synchronize(Sync::EX) { + Puppet::Util::FileLocking.writelock(file) { |f| + f.puts YAML.dump(data) + } + } + } + } + } + threads.each { |th| th.join } + end +end |
