Skip to content

Commit 8fd8bf2

Browse files
committed
Stabilize tests
1 parent 29d0380 commit 8fd8bf2

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

lib/concurrent/edge/future.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def ns_initialize(promise, default_executor = :fast)
201201
@state = :pending
202202
@callbacks = []
203203
@default_executor = default_executor
204-
@touched = false
204+
@touched = false # TODO use atom to avoid locking
205205
end
206206

207207
def ns_wait_until_complete(timeout = nil)
@@ -639,7 +639,6 @@ def pr_evaluate_to(future, *args, &block)
639639
end
640640

641641
class CompletableEvent < AbstractPromise
642-
# @api private
643642
public :complete
644643

645644
private
@@ -861,7 +860,7 @@ class FlattingPromise < BlockedPromise
861860
private
862861

863862
def ns_done(future)
864-
value = future.value
863+
value = future.value # TODO get the value as argument
865864
if @levels > 0
866865
case value
867866
when Future
@@ -885,8 +884,8 @@ def ns_initialize(blocked_by_future, levels = 1, default_executor = :fast)
885884
@levels = levels
886885
end
887886

888-
def pr_completable(done_future, _, future)
889-
pr_complete future, *done_future.result
887+
def pr_completable(_, blocked_by, future)
888+
pr_complete future, *blocked_by.last.result
890889
end
891890
end
892891

spec/concurrent/edge/future_spec.rb

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'concurrent'
2+
require 'thread'
23

34
logger = Logger.new($stderr)
45
logger.level = Logger::DEBUG
@@ -12,8 +13,8 @@
1213
it 'executes tasks asynchronously' do
1314
queue = Queue.new
1415
value = 12
15-
Concurrent.post { queue << value }
16-
Concurrent.post(:io) { queue << value }
16+
Concurrent.post { queue.push(value) }
17+
Concurrent.post(:io) { queue.push(value) }
1718
expect(queue.pop).to eq value
1819
expect(queue.pop).to eq value
1920
end
@@ -38,11 +39,11 @@
3839
it 'scheduled execution' do
3940
start = Time.now.to_f
4041
queue = Queue.new
41-
future = Concurrent.schedule(0.1) { 1 + 1 }.then { |v| queue << v << Time.now.to_f - start }
42+
future = Concurrent.schedule(0.1) { 1 + 1 }.then { |v| queue.push(v); queue.push(Time.now.to_f - start); queue }
4243

4344
expect(future.value).to eq queue
4445
expect(queue.pop).to eq 2
45-
expect(queue.pop).to be_between(0.1, 0.15)
46+
expect(queue.pop).to be_between(0.1, 0.2)
4647
end
4748

4849
it 'scheduled execution in graph' do
@@ -52,12 +53,12 @@
5253
future { sleep 0.1; 1 }.
5354
schedule(0.1).
5455
then { |v| v + 1 }.
55-
then { |v| queue << v << Time.now.to_f - start }
56+
then { |v| queue.push(v); queue.push(Time.now.to_f - start); queue }
5657

5758
future.wait!
5859
expect(future.value).to eq queue
5960
expect(queue.pop).to eq 2
60-
expect(queue.pop).to be_between(0.2, 0.25)
61+
expect(queue.pop).to be_between(0.2, 0.3)
6162
end
6263
end
6364

@@ -79,7 +80,8 @@
7980
f1 = Concurrent.future(:io) { queue.pop }
8081
f2 = Concurrent.future(:io) { queue.pop }
8182

82-
queue << 1 << 2
83+
queue.push(1)
84+
queue.push(2)
8385

8486
anys = [Concurrent.any(f1, f2),
8587
f1 | f2,
@@ -96,12 +98,11 @@
9698
it 'has sync and async callbacks' do
9799
queue = Queue.new
98100
future = Concurrent.future { :value } # executed on FAST_EXECUTOR pool by default
99-
future.on_completion(:io) { queue << :async } # async callback overridden to execute on IO_EXECUTOR pool
100-
future.on_completion! { queue << :sync } # sync callback executed right after completion in the same thread-pool
101+
future.on_completion(:io) { queue.push(:async) } # async callback overridden to execute on IO_EXECUTOR pool
102+
future.on_completion! { queue.push(:sync) } # sync callback executed right after completion in the same thread-pool
101103

102104
expect(future.value).to eq :value
103-
expect(queue.pop).to eq :sync
104-
expect(queue.pop).to eq :async
105+
expect([queue.pop, queue.pop].sort).to eq [:async, :sync]
105106
end
106107

107108
it 'chains' do
@@ -178,7 +179,7 @@
178179

179180
it 'has flat map' do
180181
f = Concurrent.future { Concurrent.future { 1 } }.flat.then(&:succ)
181-
expect(f.value).to eq 2
182+
expect(f.value!).to eq 2
182183
end
183184
end
184185

0 commit comments

Comments
 (0)