Created
September 4, 2015 19:32
-
-
Save ravicious/e41b4a4dbea613cc3919 to your computer and use it in GitHub Desktop.
Getting rid of wait_for_it in http://blog.arkency.com/2015/09/testing-race-conditions/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
threads = concurrency_level.times.map { |i| | |
-> { | |
Thread.new do | |
begin | |
customers[i].buy_products([{quantity: 1, product: product}]) | |
rescue Orders::CreateOrderService::Invalid | |
fail_occurred = true | |
end | |
end | |
} | |
}.map(&:call) | |
# We don't even need threads variable now! | |
concurrency_level.times.map { |i| | |
-> { | |
Thread.new do | |
begin | |
customers[i].buy_products([{quantity: 1, product: product}]) | |
rescue Orders::CreateOrderService::Invalid | |
fail_occurred = true | |
end | |
end | |
} | |
}.map(&:call).map(&:join) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment