Sha256: a52c7f5bf80254540c42ada8fa8c191636f492f03baf69d9edf093fe37313dc1

Contents?: true

Size: 1.52 KB

Versions: 8

Compression:

Stored size: 1.52 KB

Contents

#!/usr/bin/env rspec
require 'spec_helper'

require 'puppet/util/file_locking'

describe Puppet::Util::FileLocking, :'fails_on_ruby_1.9.2' => true do
  before :each do
    @file = Tempfile.new("puppetspec")
    filepath = @file.path
    @file.close!()
    @file = filepath
    @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) }
  end

  it "should be able to keep file corruption from happening when there are multiple writers threads" do
    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

  it "should be able to keep file corruption from happening when there are multiple writers processes", :unless => Puppet.features.microsoft_windows? do
    unless Process.fork
      50.times { |b|
        Puppet::Util::FileLocking.writelock(@file) { |f|
          f.puts YAML.dump(@data)
        }
        sleep 0.01
      }
      Kernel.exit!
    end

    50.times { |c|
      Puppet::Util::FileLocking.readlock(@file) { |f|
        YAML.load(f.read).should == @data
      }
    }
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
puppet-2.7.26 spec/integration/util/file_locking_spec.rb
puppet-2.7.25 spec/integration/util/file_locking_spec.rb
puppet-2.7.24 spec/integration/util/file_locking_spec.rb
puppet-2.7.23 spec/integration/util/file_locking_spec.rb
puppet-2.7.22 spec/integration/util/file_locking_spec.rb
puppet-2.7.21 spec/integration/util/file_locking_spec.rb
puppet-2.7.20 spec/integration/util/file_locking_spec.rb
puppet-2.7.20.rc1 spec/integration/util/file_locking_spec.rb