File: lock_spec.rb

package info (click to toggle)
puppet-agent 8.10.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 27,392 kB
  • sloc: ruby: 286,820; sh: 492; xml: 116; makefile: 88; cs: 68
file content (29 lines) | stat: -rw-r--r-- 802 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
require 'spec_helper'
require 'puppet/concurrent/lock'

describe Puppet::Concurrent::Lock do
  if Puppet::Util::Platform.jruby?
    context 'on jruby' do
      it 'synchronizes a block on itself' do
        iterations = 100
        value = 0

        lock = Puppet::Concurrent::Lock.new
        threads = iterations.times.collect do
          Thread.new do
            lock.synchronize do
              tmp = (value += 1)
              sleep(0.001)
              # This update using tmp is designed to lose increments if threads overlap
              value = tmp + 1
            end
          end
        end
        threads.each(&:join)

        # In my testing this always fails by quite a lot when not synchronized (ie on mri)
        expect(value).to eq(iterations * 2)
      end
    end
  end
end