Skip to content

Commit 3ef1b1a

Browse files
committed
Fixed or deprecated all remaining pending specs.
1 parent dc659fe commit 3ef1b1a

File tree

11 files changed

+119
-166
lines changed

11 files changed

+119
-166
lines changed

lib/concurrent/actor/actor_ref.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
require 'concurrent/observable'
2-
31
module Concurrent
42

53
# Base class for classes that encapsulate `ActorContext` objects.
64
#
75
# @see Concurrent::ActorContext
86
module ActorRef
9-
include Concurrent::Observable
107

118
# @!method post(*msg, &block)
129
#

lib/concurrent/actor/simple_actor_ref.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ def initialize(actor, opts = {})
1313
@mutex = Mutex.new
1414
@executor = SingleThreadExecutor.new
1515
@stop_event = Event.new
16-
@reset_on_error = opts.fetch(:reset_on_error, false)
16+
@reset_on_error = opts.fetch(:reset_on_error, true)
1717
@exception_class = opts.fetch(:rescue_exception, false) ? Exception : StandardError
1818
@args = opts.fetch(:args, {})
19-
self.observers = CopyOnNotifyObserverSet.new
2019

2120
@actor.define_singleton_method(:shutdown, &method(:set_stop_event))
2221
@actor.on_start
@@ -89,8 +88,6 @@ def process_message(message)
8988
rescue @exception_class => ex
9089
# suppress
9190
end
92-
93-
observers.notify_observers(now, message.payload, result, ex)
9491
end
9592
end
9693
end

spec/concurrent/actor/actor_ref_shared.rb

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -263,57 +263,4 @@ def receive(*msg)
263263
sleep(0.1)
264264
end
265265
end
266-
267-
context 'observation' do
268-
269-
let(:observer_class) do
270-
Class.new do
271-
attr_reader :time, :msg, :value, :reason
272-
def update(time, msg, value, reason)
273-
@msg = msg
274-
@time = time
275-
@value = value
276-
@reason = reason
277-
end
278-
end
279-
end
280-
281-
it 'notifies observers' do
282-
o1 = observer_class.new
283-
o2 = observer_class.new
284-
285-
subject.add_observer(o1)
286-
subject.add_observer(o2)
287-
288-
subject << :foo
289-
sleep(0.1)
290-
291-
o1.value.should eq :foo
292-
o1.reason.should be_nil
293-
294-
o2.value.should eq :foo
295-
o2.reason.should be_nil
296-
end
297-
298-
it 'does not notify removed observers' do
299-
o1 = observer_class.new
300-
o2 = observer_class.new
301-
302-
subject.add_observer(o1)
303-
subject.add_observer(o2)
304-
305-
subject << :foo
306-
sleep(0.1)
307-
308-
subject.delete_observer(o1)
309-
subject << :bar
310-
sleep(0.1)
311-
o1.value.should_not eq :bar
312-
313-
subject.delete_observers
314-
subject << :baz
315-
sleep(0.1)
316-
o1.value.should_not eq :baz
317-
end
318-
end
319266
end

spec/concurrent/actor/actor_spec.rb

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -132,25 +132,26 @@ def update(time, message, value, reason)
132132
}.new
133133
end
134134

135-
it 'notifies observers when a message is successfully handled' do
136-
pending('intermittently failing; deprecated')
137-
observer.should_receive(:update).exactly(10).times.with(any_args())
138-
subject.add_observer(observer)
139-
@thread = Thread.new{ subject.run }
140-
@thread.join(0.1)
141-
10.times { subject.post(42) }
142-
@thread.join(0.1)
143-
end
144-
145-
it 'notifies observers when a message raises an exception' do
146-
error = StandardError.new
147-
observer.should_receive(:update).exactly(10).times.with(any_args())
148-
subject.add_observer(observer)
149-
@thread = Thread.new{ subject.run }
150-
@thread.join(0.1)
151-
10.times { subject.post(error) }
152-
@thread.join(0.1)
153-
end
135+
#it 'notifies observers when a message is successfully handled' do
136+
#pending('intermittently failing; deprecated')
137+
#observer.should_receive(:update).exactly(10).times.with(any_args())
138+
#subject.add_observer(observer)
139+
#@thread = Thread.new{ subject.run }
140+
#@thread.join(0.1)
141+
#10.times { subject.post(42) }
142+
#@thread.join(0.1)
143+
#end
144+
145+
#it 'notifies observers when a message raises an exception' do
146+
#pending('intermittently failing; deprecated')
147+
#error = StandardError.new
148+
#observer.should_receive(:update).exactly(10).times.with(any_args())
149+
#subject.add_observer(observer)
150+
#@thread = Thread.new{ subject.run }
151+
#@thread.join(0.1)
152+
#10.times { subject.post(error) }
153+
#@thread.join(0.1)
154+
#end
154155

155156
it 'passes the time, message, value, and reason to the observer on success' do
156157
subject.add_observer(observer)
@@ -243,18 +244,18 @@ def update(time, message, value, reason)
243244
@thread.kill
244245
end
245246

246-
it 'posts to the mailbox with Poolbox#<<' do
247-
pending('intermittently failing; deprecated')
248-
@expected = false
249-
mailbox, pool = clazz.pool(1)
250-
@thread = Thread.new{ pool.first.run }
251-
sleep(0.1)
252-
mailbox << 42
253-
sleep(0.1)
254-
pool.first.last_message.should eq [42]
255-
pool.first.stop
256-
@thread.kill
257-
end
247+
#it 'posts to the mailbox with Poolbox#<<' do
248+
#pending('intermittently failing; deprecated')
249+
#@expected = false
250+
#mailbox, pool = clazz.pool(1)
251+
#@thread = Thread.new{ pool.first.run }
252+
#sleep(0.1)
253+
#mailbox << 42
254+
#sleep(0.1)
255+
#pool.first.last_message.should eq [42]
256+
#pool.first.stop
257+
#@thread.kill
258+
#end
258259
end
259260

260261
context 'subclassing' do

spec/concurrent/actor/simple_actor_ref_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ module Concurrent
6262
ref.post(:poison)
6363
end
6464

65-
it 'defaults to false' do
65+
it 'defaults to true' do
6666
clazz = create_actor_test_class
6767
args = [:foo, :bar, :hello, :world]
6868
ref = clazz.spawn(args: args)
69-
clazz.should_not_receive(:new).with(any_args)
69+
clazz.should_receive(:new).once.with(*args)
7070
ref.post(:poison)
7171
end
7272
end

spec/concurrent/atomic/event_spec.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,19 @@ module Concurrent
4444

4545
context '#try?' do
4646

47-
it 'triggers the event if not already set'
47+
it 'triggers the event if not already set' do
48+
subject.try?
49+
subject.should be_set
50+
end
4851

49-
it 'returns true if not previously set'
52+
it 'returns true if not previously set' do
53+
subject.try?.should be_true
54+
end
5055

51-
it 'returns false if previously set'
56+
it 'returns false if previously set' do
57+
subject.set
58+
subject.try?.should be_false
59+
end
5260
end
5361

5462
context '#reset' do

spec/concurrent/executor/safe_task_executor_spec.rb

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,54 +9,94 @@ module Concurrent
99
context 'happy execution' do
1010

1111
let(:task) { Proc.new { 42 } }
12-
let(:executor) { SafeTaskExecutor.new(task) }
12+
subject { SafeTaskExecutor.new(task) }
1313

1414
it 'should return success' do
15-
success, value, reason = executor.execute
15+
success, value, reason = subject.execute
1616
success.should be_true
1717
end
1818

1919
it 'should return task value' do
20-
success, value, reason = executor.execute
20+
success, value, reason = subject.execute
2121
value.should eq 42
2222
end
2323

2424
it 'should return a nil reason' do
25-
success, value, reason = executor.execute
25+
success, value, reason = subject.execute
2626
reason.should be_nil
2727
end
2828

29-
it 'passes all arguments to #execute to the task'
29+
it 'passes all arguments to #execute to the task' do
30+
expected = nil
31+
task = proc {|*args| expected = args }
32+
SafeTaskExecutor.new(task).execute(1, 2, 3)
33+
expected.should eq [1, 2, 3]
34+
end
3035

31-
it 'protectes #execute with a mutex'
36+
it 'protectes #execute with a mutex' do
37+
mutex = double(:mutex)
38+
Mutex.should_receive(:new).with(no_args).and_return(mutex)
39+
mutex.should_receive(:synchronize).with(no_args)
40+
subject.execute
41+
end
3242
end
3343

3444
context 'failing execution' do
3545

3646
let(:task) { Proc.new { raise StandardError.new('an error') } }
37-
let(:executor) { SafeTaskExecutor.new(task) }
47+
subject { SafeTaskExecutor.new(task) }
3848

3949
it 'should return false success' do
40-
success, value, reason = executor.execute
50+
success, value, reason = subject.execute
4151
success.should be_false
4252
end
4353

4454
it 'should return a nil value' do
45-
success, value, reason = executor.execute
55+
success, value, reason = subject.execute
4656
value.should be_nil
4757
end
4858

4959
it 'should return the reason' do
50-
success, value, reason = executor.execute
60+
success, value, reason = subject.execute
5161
reason.should be_a(StandardError)
5262
reason.message.should eq 'an error'
5363
end
5464

55-
it 'rescues Exception when :rescue_exception is true'
65+
it 'rescues Exception when :rescue_exception is true' do
66+
task = proc { raise Exception }
67+
subject = SafeTaskExecutor.new(task, rescue_exception: true)
68+
expect {
69+
subject.execute
70+
}.to_not raise_error
71+
end
5672

57-
it 'rescues StandardError when :rescue_exception is false'
73+
it 'rescues StandardError when :rescue_exception is false' do
74+
task = proc { raise StandardError }
75+
subject = SafeTaskExecutor.new(task, rescue_exception: false)
76+
expect {
77+
subject.execute
78+
}.to_not raise_error
79+
80+
task = proc { raise Exception }
81+
subject = SafeTaskExecutor.new(task, rescue_exception: false)
82+
expect {
83+
subject.execute
84+
}.to raise_error(Exception)
85+
end
5886

59-
it 'rescues StandardError by default'
87+
it 'rescues StandardError by default' do
88+
task = proc { raise StandardError }
89+
subject = SafeTaskExecutor.new(task)
90+
expect {
91+
subject.execute
92+
}.to_not raise_error
93+
94+
task = proc { raise Exception }
95+
subject = SafeTaskExecutor.new(task)
96+
expect {
97+
subject.execute
98+
}.to raise_error(Exception)
99+
end
60100
end
61101
end
62102
end

spec/concurrent/executor/thread_pool_shared.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,6 @@
195195
subject.length.should eq 0
196196
end
197197

198-
it 'returns a non-zero while shutting down' do
199-
pending('intermittently failing on Travis CI')
200-
5.times{ subject.post{ sleep(0.1) } }
201-
subject.shutdown
202-
subject.length.should > 0
203-
end
204-
205198
it 'returns zero once shut down' do
206199
5.times{ subject.post{ sleep(0.1) } }
207200
sleep(0.1)

spec/concurrent/executor/timer_set_spec.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,16 @@ module Concurrent
3535
latch.wait(0.2).should be_true
3636
end
3737

38-
it 'passes all arguments to the task on execution'
38+
it 'passes all arguments to the task on execution' do
39+
expected = nil
40+
latch = CountDownLatch.new(1)
41+
subject.post(0.1, 1, 2, 3) do |*args|
42+
expected = args
43+
latch.count_down
44+
end
45+
latch.wait(0.2).should be_true
46+
expected.should eq [1, 2, 3]
47+
end
3948

4049
it 'immediately posts a task when the delay is zero' do
4150
Thread.should_not_receive(:new).with(any_args)

0 commit comments

Comments
 (0)