Project

General

Profile

Backport #2092 » test_queue.patch

quix (James M. Lawrence), 09/12/2009 09:49 PM

View differences:

test/ruby/test_queue.rb (revision 0)
require 'test/unit'
require 'thread'
class TestQueue < Test::Unit::TestCase
def test_queue
grind(5, 10_000, 15, Queue)
end
def test_sized_queue
grind(5, 10_000, 15, SizedQueue, 10_000)
end
def grind(num_threads, num_objects, num_iterations, klass, *args)
from_workers = klass.new(*args)
to_workers = klass.new(*args)
workers = (1..num_threads).map {
Thread.new {
while object = to_workers.pop
from_workers.push object
end
}
}
Thread.new {
num_iterations.times {
num_objects.times { to_workers.push 99 }
num_objects.times { from_workers.pop }
}
}.join
num_threads.times { to_workers.push nil }
workers.each { |t| t.join }
assert 0, from_workers.size
assert 0, to_workers.size
end
end
(1-1/3)