summaryrefslogtreecommitdiff
path: root/test/ruby/test_fiber.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_fiber.rb')
-rw-r--r--test/ruby/test_fiber.rb43
1 files changed, 42 insertions, 1 deletions
diff --git a/test/ruby/test_fiber.rb b/test/ruby/test_fiber.rb
index 1f78307748..6976bd9742 100644
--- a/test/ruby/test_fiber.rb
+++ b/test/ruby/test_fiber.rb
@@ -498,7 +498,7 @@ class TestFiber < Test::Unit::TestCase
end
def test_machine_stack_gc
- assert_normal_exit <<-RUBY, '[Bug #14561]', timeout: 10
+ assert_normal_exit <<-RUBY, '[Bug #14561]', timeout: 60
enum = Enumerator.new { |y| y << 1 }
thread = Thread.new { enum.peek }
thread.join
@@ -506,4 +506,45 @@ class TestFiber < Test::Unit::TestCase
GC.start
RUBY
end
+
+ def test_fiber_pool_stack_acquire_failure
+ environment = {
+ "RUBY_SHARED_FIBER_POOL_MINIMUM_COUNT" => "0",
+ "RUBY_SHARED_FIBER_POOL_MAXIMUM_COUNT" => "128"
+ }
+
+ # This program requires, effectively, at most one fiber stack, since the fiber immediately becomes unreachable.
+ assert_separately([environment], <<~RUBY, timeout: 30)
+ GC.disable
+ count_before = GC.count
+
+ # Create more fibers than the pool can handle (but they become immediately unreachable):
+ assert_nothing_raised do
+ 256.times do
+ Fiber.new{Fiber.yield}.resume
+ end
+ end
+
+ # Major GC should have happened at least once:
+ assert_operator(GC.count, :>, count_before)
+ RUBY
+ end
+
+ def test_fiber_pool_stack_acquire_failure_at_maximum_count
+ environment = {
+ "RUBY_SHARED_FIBER_POOL_MAXIMUM_COUNT" => "128"
+ }
+
+ assert_separately([environment], <<~RUBY, timeout: 30)
+ GC.disable
+ fibers = []
+ assert_raise(FiberError) do
+ loop do
+ Fiber.new{fibers << Fiber.current; Fiber.yield}.resume
+ raise "expected FiberError before this" if fibers.size > 128
+ end
+ end
+ assert_operator fibers.size, :>=, 128
+ RUBY
+ end
end