summaryrefslogtreecommitdiffstats
path: root/spec/integration
diff options
context:
space:
mode:
authorJames Turnbull <james@lovedthanlost.net>2008-12-27 12:43:52 +1100
committerJames Turnbull <james@lovedthanlost.net>2008-12-27 12:43:52 +1100
commit4c648bb1e7428806550f57160f72892709b0a30f (patch)
treefeb1108c0608a95ec088554dae7753d2c9609a14 /spec/integration
parent34335b7a2e6950d4bb3dcaaf2bfe88cbc684007e (diff)
parent7403330c4f63c290ba3cc5992706a3f0b1c9caa0 (diff)
downloadpuppet-4c648bb1e7428806550f57160f72892709b0a30f.tar.gz
puppet-4c648bb1e7428806550f57160f72892709b0a30f.tar.xz
puppet-4c648bb1e7428806550f57160f72892709b0a30f.zip
Merge branch '0.24.x'
Conflicts: CHANGELOG
Diffstat (limited to 'spec/integration')
-rwxr-xr-xspec/integration/util/file_locking.rb36
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