From: mental@... Date: 2005-11-09T06:20:39+09:00 Subject: Re: Checking for race conditions with Ruby threads 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