From: Wilson Bilkovich Date: 2005-11-09T09:14:12+09:00 Subject: Re: Checking for race conditions with Ruby threads Unfortunately, this is a SQL Server application being used as a 'work queue', and SQL Server 2000 does not allow exclusive locks on rows. Various hoops have been jumped through to try to shoot down the locking problems, but the lack of a test case has made them hard to compare, before today. Luckily, I've rewritten the whole thing in Rails against Oracle, but that system is still a couple of weeks away. Are you saying that race conditions are in general impossible to prove/disprove, or just that my code isn't the way to do it? Heh. Thanks, --Wilson. On 11/8/05, mental@rydia.net wrote: > Quoting Wilson Bilkovich : > > > 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 > > Using Process.fork and IO.pipe might be "cleaner" than this, but > probably isn't necessary here. > > However, be aware that even if this test case passes, it doesn't > reliably demonstrate the absence of a race condition. > > -mental > >