Skip to content

Instantly share code, notes, and snippets.

@cheald
Created November 6, 2014 05:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cheald/c02e07288e76adcdabba to your computer and use it in GitHub Desktop.
Save cheald/c02e07288e76adcdabba to your computer and use it in GitHub Desktop.
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)
before = q.max
q.max.times { q << 1 }
t1 = Thread.new { q << 1 }
sleep 0.01 until t1.stop?
q.max = q.max + 1
assert_equal before + 1, q.max
ensure
t1.join if t1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment