Sha256: 937bc134fcc34dbc7f5358e17c3fbb75bd90cb74920fef0ae419fea7f67a4a63

Contents?: true

Size: 1.12 KB

Versions: 104

Compression:

Stored size: 1.12 KB

Contents

require 'spec_helper'
require 'puppet/concurrent/thread_local_singleton'

class PuppetSpec::Singleton
  extend Puppet::Concurrent::ThreadLocalSingleton
end

# Use the `equal?` matcher to ensure we get the same object
describe Puppet::Concurrent::ThreadLocalSingleton do
  it 'returns the same object for a single thread' do
    expect(PuppetSpec::Singleton.singleton).to equal(PuppetSpec::Singleton.singleton)
  end

  it 'is not inherited for a newly created thread' do
    main_thread_local = PuppetSpec::Singleton.singleton
    Thread.new do
      expect(main_thread_local).to_not equal(PuppetSpec::Singleton.singleton)
    end.join
  end

  it 'does not leak outside a thread' do
    thread_local = nil
    Thread.new do
      thread_local = PuppetSpec::Singleton.singleton
    end.join
    expect(thread_local).to_not equal(PuppetSpec::Singleton.singleton)
  end

  it 'is different for each thread' do
    locals = []
    Thread.new do
      locals << PuppetSpec::Singleton.singleton
    end.join
    Thread.new do
      locals << PuppetSpec::Singleton.singleton
    end.join
    expect(locals.first).to_not equal(locals.last)
  end
end

Version data entries

104 entries across 104 versions & 1 rubygems

Version Path
puppet-8.3.0 spec/unit/concurrent/thread_local_singleton_spec.rb
puppet-8.3.0-x86-mingw32 spec/unit/concurrent/thread_local_singleton_spec.rb
puppet-8.3.0-x64-mingw32 spec/unit/concurrent/thread_local_singleton_spec.rb
puppet-8.3.0-universal-darwin spec/unit/concurrent/thread_local_singleton_spec.rb
puppet-8.4.0 spec/unit/concurrent/thread_local_singleton_spec.rb
puppet-8.4.0-x86-mingw32 spec/unit/concurrent/thread_local_singleton_spec.rb
puppet-8.4.0-x64-mingw32 spec/unit/concurrent/thread_local_singleton_spec.rb
puppet-8.4.0-universal-darwin spec/unit/concurrent/thread_local_singleton_spec.rb
puppet-7.28.0 spec/unit/concurrent/thread_local_singleton_spec.rb
puppet-7.28.0-x86-mingw32 spec/unit/concurrent/thread_local_singleton_spec.rb
puppet-7.28.0-x64-mingw32 spec/unit/concurrent/thread_local_singleton_spec.rb
puppet-7.28.0-universal-darwin spec/unit/concurrent/thread_local_singleton_spec.rb
puppet-8.3.1 spec/unit/concurrent/thread_local_singleton_spec.rb
puppet-8.3.1-x86-mingw32 spec/unit/concurrent/thread_local_singleton_spec.rb
puppet-8.3.1-x64-mingw32 spec/unit/concurrent/thread_local_singleton_spec.rb
puppet-8.3.1-universal-darwin spec/unit/concurrent/thread_local_singleton_spec.rb
puppet-7.27.0 spec/unit/concurrent/thread_local_singleton_spec.rb
puppet-7.27.0-x86-mingw32 spec/unit/concurrent/thread_local_singleton_spec.rb
puppet-7.27.0-x64-mingw32 spec/unit/concurrent/thread_local_singleton_spec.rb
puppet-7.27.0-universal-darwin spec/unit/concurrent/thread_local_singleton_spec.rb