Skip to content

Commit

Permalink
Merge pull request #660 from ianks/promise-zip-ordering
Browse files Browse the repository at this point in the history
Add specs for Promise#zip/Promise.zip ordering
  • Loading branch information
pitr-ch committed Feb 24, 2018
2 parents 705325e + 8720d17 commit 952f56b
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions spec/concurrent/promise_spec.rb
Expand Up @@ -394,6 +394,24 @@ def get_ivar_from_args(opts)

expect(composite).to be_rejected
end

it 'preserves ordering of the executed promises' do
10.times do
latch1 = CountDownLatch.new
latch2 = CountDownLatch.new
executor = SimpleExecutorService.new

p1 = Concurrent::Promise.execute(executor: executor) { latch1.wait; 'one' }
p2 = Concurrent::Promise.execute(executor: executor) { latch2.wait; 'two' }
p3 = Concurrent::Promise.execute(executor: executor) { 'three' }

latch1.count_down
latch2.count_down

result = Concurrent::Promise.zip(p1, p2, p3).value!
expect(result).to eq(['one', 'two', 'three'])
end
end
end

describe '.zip' do
Expand Down Expand Up @@ -438,6 +456,27 @@ def get_ivar_from_args(opts)

expect(composite).to be_rejected
end

it 'preserves ordering of the executed promises' do
promise1 = Promise.execute do
# resolves after the second promise
sleep 0.2
'one'
end

promise2 = Promise.execute do
sleep 0.1
'two'
end

promise3 = Promise.execute do
'three'
end

result = Promise.zip(promise1, promise2, promise3).value

expect(result).to eql(['one', 'two', 'three'])
end
end

describe 'aggregators' do
Expand Down

0 comments on commit 952f56b

Please sign in to comment.