@@ -24,11 +24,18 @@ module Concurrent
2424 actor . argv . should be_empty
2525 end
2626
27- it 'passes all :args option to the constructor' do
27+ it 'passes all :args option to the actor constructor' do
2828 subject = shared_actor_test_class . spawn ( args : [ 1 , 2 , 3 , 4 ] )
2929 actor = subject . instance_variable_get ( :@actor )
3030 actor . argv . should eq [ 1 , 2 , 3 , 4 ]
3131 end
32+
33+ it 'passes the options hash to the ActorRef constructor' do
34+ subject # prevent the after(:all) block from breaking this test
35+ opts = { foo : :bar , hello : :world }
36+ described_class . should_receive ( :new ) . once . with ( anything , opts )
37+ shared_actor_test_class . spawn ( opts )
38+ end
3239 end
3340
3441 context 'supervision' do
@@ -82,7 +89,7 @@ module Concurrent
8289 subject << :foo
8390 end
8491
85- it 'calls #on_reset when the thread is reseted ' do
92+ it 'calls #on_reset when the thread is started after the first time ' do
8693 actor = subject . instance_variable_get ( :@actor )
8794 actor . should_receive ( :on_reset ) . once . with ( no_args )
8895 subject << :terminate
@@ -91,6 +98,112 @@ module Concurrent
9198 end
9299 end
93100
101+ context 'abort_on_exception' do
102+
103+ after ( :each ) do
104+ @ref . shutdown if @ref
105+ end
106+
107+ it 'gets set on the actor thread' do
108+ @ref = shared_actor_test_class . spawn ( abort_on_exception : true )
109+ @ref << :foo
110+ sleep ( 0.1 )
111+ @ref . instance_variable_get ( :@thread ) . abort_on_exception . should be_true
112+
113+ @ref = shared_actor_test_class . spawn ( abort_on_exception : false )
114+ @ref << :foo
115+ sleep ( 0.1 )
116+ @ref . instance_variable_get ( :@thread ) . abort_on_exception . should be_false
117+ end
118+
119+ it 'defaults to true' do
120+ @ref = shared_actor_test_class . spawn
121+ @ref << :foo
122+ sleep ( 0.1 )
123+ @ref . instance_variable_get ( :@thread ) . abort_on_exception . should be_true
124+ end
125+ end
126+
127+ context 'reset_on_error' do
128+
129+ after ( :each ) do
130+ @ref . shutdown if @ref
131+ end
132+
133+ it 'causes #on_reset to be called on exception when true' do
134+ @ref = shared_actor_test_class . spawn ( reset_on_error : true )
135+ actor = @ref . instance_variable_get ( :@actor )
136+ actor . should_receive ( :on_reset ) . once . with ( no_args )
137+ @ref << :poison
138+ sleep ( 0.1 )
139+ end
140+
141+ it 'prevents #on_reset form being called on exception when false' do
142+ @ref = shared_actor_test_class . spawn ( reset_on_error : false )
143+ actor = @ref . instance_variable_get ( :@actor )
144+ actor . should_not_receive ( :on_reset ) . with ( any_args )
145+ @ref << :poison
146+ sleep ( 0.1 )
147+ end
148+
149+ it 'defaults to true' do
150+ @ref = shared_actor_test_class . spawn
151+ actor = @ref . instance_variable_get ( :@actor )
152+ actor . should_receive ( :on_reset ) . once . with ( no_args )
153+ @ref << :poison
154+ sleep ( 0.1 )
155+ end
156+ end
157+
158+ context 'rescue_exception' do
159+
160+ after ( :each ) do
161+ @ref . shutdown if @ref
162+ end
163+
164+ it 'rescues Exception in the actor thread when true' do
165+ @ref = shared_actor_test_class . spawn (
166+ abort_on_exception : false ,
167+ rescue_exception : true
168+ )
169+
170+ ivar = @ref . post ( :poison )
171+ sleep ( 0.1 )
172+ ivar . reason . should be_a StandardError
173+
174+ ivar = @ref . post ( :bullet )
175+ sleep ( 0.1 )
176+ ivar . reason . should be_a Exception
177+ end
178+
179+ it 'rescues StandardError in the actor thread when false' do
180+ @ref = shared_actor_test_class . spawn (
181+ abort_on_exception : false ,
182+ rescue_exception : false
183+ )
184+
185+ ivar = @ref . post ( :poison )
186+ sleep ( 0.1 )
187+ ivar . reason . should be_a StandardError
188+
189+ ivar = @ref . post ( :bullet )
190+ sleep ( 0.1 )
191+ ivar . reason . should be_nil
192+ end
193+
194+ it 'defaults to false' do
195+ @ref = shared_actor_test_class . spawn ( abort_on_exception : false )
196+
197+ ivar = @ref . post ( :poison )
198+ sleep ( 0.1 )
199+ ivar . reason . should be_a StandardError
200+
201+ ivar = @ref . post ( :bullet )
202+ sleep ( 0.1 )
203+ ivar . reason . should be_nil
204+ end
205+ end
206+
94207 context '#shutdown' do
95208
96209 it 'calls #on_shutdown when shutdown' do
0 commit comments