aboutsummaryrefslogtreecommitdiffstats
path: root/test/fiber/test_sleep.rb
diff options
context:
space:
mode:
authorSamuel Williams <samuel.williams@oriontransfer.co.nz>2020-05-15 12:23:42 +1200
committerSamuel Williams <samuel.williams@oriontransfer.co.nz>2020-05-15 13:26:23 +1200
commit6fa8455ebbf457e5d8752295a8d6380146636c0c (patch)
treea5c16f9d9e386b78d16986fc00ed31cbc4bf56a7 /test/fiber/test_sleep.rb
parent39365b46e250162f278cb36aa148bc2a92b1b84a (diff)
downloadruby-6fa8455ebbf457e5d8752295a8d6380146636c0c.tar.gz
Move `test/scheduler` -> `test/fiber` [Bug #16892][ruby-core:98366].
Diffstat (limited to 'test/fiber/test_sleep.rb')
-rw-r--r--test/fiber/test_sleep.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/test/fiber/test_sleep.rb b/test/fiber/test_sleep.rb
new file mode 100644
index 0000000000..0be760341e
--- /dev/null
+++ b/test/fiber/test_sleep.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+require 'test/unit'
+require_relative 'scheduler'
+
+class TestSchedulerSleep < Test::Unit::TestCase
+ ITEMS = [0, 1, 2, 3, 4]
+
+ def test_sleep
+ items = []
+
+ thread = Thread.new do
+ scheduler = Scheduler.new
+ Thread.current.scheduler = scheduler
+
+ 5.times do |i|
+ Fiber do
+ sleep(i/100.0)
+ items << i
+ end
+ end
+
+ # Should be 5 fibers waiting:
+ assert_equal scheduler.waiting.size, 5
+ end
+
+ thread.join
+
+ assert_equal ITEMS, items
+ end
+end