File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ require 'spec_helper'
2
+ require 'puppet/concurrent/thread_local_singleton'
3
+
4
+ class PuppetSpec ::Singleton
5
+ extend Puppet ::Concurrent ::ThreadLocalSingleton
6
+ end
7
+
8
+ # Use the `equal?` matcher to ensure we get the same object
9
+ describe Puppet ::Concurrent ::ThreadLocalSingleton do
10
+ it 'returns the same object for a single thread' do
11
+ expect ( PuppetSpec ::Singleton . singleton ) . to equal ( PuppetSpec ::Singleton . singleton )
12
+ end
13
+
14
+ it 'is not inherited for a newly created thread' do
15
+ main_thread_local = PuppetSpec ::Singleton . singleton
16
+ Thread . new do
17
+ expect ( main_thread_local ) . to_not equal ( PuppetSpec ::Singleton . singleton )
18
+ end . join
19
+ end
20
+
21
+ it 'does not leak outside a thread' do
22
+ thread_local = nil
23
+ Thread . new do
24
+ thread_local = PuppetSpec ::Singleton . singleton
25
+ end . join
26
+ expect ( thread_local ) . to_not equal ( PuppetSpec ::Singleton . singleton )
27
+ end
28
+
29
+ it 'is different for each thread' do
30
+ locals = [ ]
31
+ Thread . new do
32
+ locals << PuppetSpec ::Singleton . singleton
33
+ end . join
34
+ Thread . new do
35
+ locals << PuppetSpec ::Singleton . singleton
36
+ end . join
37
+ expect ( locals . first ) . to_not equal ( locals . last )
38
+ end
39
+ end
You can’t perform that action at this time.
0 commit comments