From: Wilson Bilkovich Date: 2005-11-09T04:45:25+09:00 Subject: Re: Checking for race conditions with Ruby threads Thanks. This code exposed the problem successfully. Not sure if it's the cleanest way, though. require 'test/unit' require 'open-uri' class TestStream < Test::Unit::TestCase def test_work_unit_uniqueness ids = [] pipes = [] test_cmd = %q{ ruby -ropen-uri -e"print URI('the_url').read" } 100.times do |i| pipes[i] = IO::popen(test_cmd) end pipes.each do |p| p.each_line {|ln| ids << ln} end assert_equal(ids, ids.uniq) end end On 11/8/05, mental@rydia.net wrote: > Quoting Wilson Bilkovich : > > > I've got an untrustworthy legacy app that seems to have a nasty > > race condition when a certain number of users click on a link at > > just the right time. > > > I'm trying to write a Ruby unit test to trigger this, but I'm a > > bit stumped. > > You cannot test for race conditions, only prove them. > > -mental > >