diff --git a/ChangeLog b/ChangeLog index 60f9dd762e..fca8af76dc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Sat Sep 3 18:40:57 2011 CHIKANAGA Tomoyuki + + * lib/thread.rb (SizedQueue#max=) raise ArgumentError if max is not + positive number. patch by Masaki Matsushita. + [ruby-dev:44449] [Bug #5259] + + * test/thread/test_queue.rb (test_sized_queue_initialize, + test_sized_queue_assign_max): add tests for it. + Fri Sep 2 21:11:16 2011 Nobuyoshi Nakada * io.c (validate_enc_binmode, prep_stdio): default to text mode on diff --git a/lib/thread.rb b/lib/thread.rb index 09f2d58ecc..524db69a18 100644 --- a/lib/thread.rb +++ b/lib/thread.rb @@ -269,6 +269,7 @@ class SizedQueue < Queue # Sets the maximum size of the queue. # def max=(max) + raise ArgumentError, "queue size must be positive" unless max > 0 diff = nil @mutex.synchronize { if max <= @max diff --git a/test/thread/test_queue.rb b/test/thread/test_queue.rb index b0ffe0866d..685b41a54f 100644 --- a/test/thread/test_queue.rb +++ b/test/thread/test_queue.rb @@ -35,4 +35,22 @@ class TestQueue < Test::Unit::TestCase assert_equal 0, from_workers.size assert_equal 0, to_workers.size end + + def test_sized_queue_initialize + q = SizedQueue.new(1) + assert_equal 1, q.max + assert_raise(ArgumentError) { SizedQueue.new(0) } + assert_raise(ArgumentError) { SizedQueue.new(-1) } + end + + def test_sized_queue_assign_max + q = SizedQueue.new(2) + assert_equal(2, q.max) + q.max = 1 + assert_equal(1, q.max) + assert_raise(ArgumentError) { q.max = 0 } + assert_equal(1, q.max) + assert_raise(ArgumentError) { q.max = -1 } + assert_equal(1, q.max) + end end