Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add specs for Promise#zip/Promise.zip ordering #660

Merged
merged 3 commits into from Feb 24, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 39 additions & 0 deletions spec/concurrent/promise_spec.rb
Expand Up @@ -368,6 +368,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 All @@ -386,6 +404,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