summaryrefslogtreecommitdiff
path: root/test/fiber
diff options
context:
space:
mode:
authorSamuel Williams <samuel.williams@oriontransfer.co.nz>2020-10-16 14:25:58 +1300
committerSamuel Williams <samuel.williams@oriontransfer.co.nz>2020-11-07 23:39:50 +1300
commita08ee8330d3d739467bfa34deeb797d83e59ed3c (patch)
treed14bc8f1417f39f9924b93343ddfd6451b3db8c3 /test/fiber
parent656d4cddaf2debd0c66b9bd980f51bcbf0849bd6 (diff)
Rename to `Fiber#set_scheduler`.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3742
Diffstat (limited to 'test/fiber')
-rw-r--r--test/fiber/http.rb4
-rw-r--r--test/fiber/test_enumerator.rb2
-rw-r--r--test/fiber/test_io.rb4
-rw-r--r--test/fiber/test_mutex.rb20
-rw-r--r--test/fiber/test_scheduler.rb26
-rw-r--r--test/fiber/test_sleep.rb4
6 files changed, 38 insertions, 22 deletions
diff --git a/test/fiber/http.rb b/test/fiber/http.rb
index e2a007bc847..ad51ae3c769 100644
--- a/test/fiber/http.rb
+++ b/test/fiber/http.rb
@@ -19,7 +19,7 @@ def fetch_topics(topics)
end.resume
end
- Thread.scheduler&.run
+ Thread.fiber_scheduler&.run
return responses
end
@@ -32,7 +32,7 @@ def sweep(repeats: 3, **options)
Thread.new do
Benchmark.realtime do
scheduler = Scheduler.new
- Thread.current.scheduler = scheduler
+ Fiber.set_scheduler scheduler
repeats.times do
Fiber.new(**options) do
diff --git a/test/fiber/test_enumerator.rb b/test/fiber/test_enumerator.rb
index 7cd13d7c77a..cd4ccd1de54 100644
--- a/test/fiber/test_enumerator.rb
+++ b/test/fiber/test_enumerator.rb
@@ -20,7 +20,7 @@ class TestFiberEnumerator < Test::Unit::TestCase
thread = Thread.new do
scheduler = Scheduler.new
- Thread.current.scheduler = scheduler
+ Fiber.set_scheduler scheduler
e = i.to_enum(:each_char)
diff --git a/test/fiber/test_io.rb b/test/fiber/test_io.rb
index 19f68eb8c38..f01cc3af1b7 100644
--- a/test/fiber/test_io.rb
+++ b/test/fiber/test_io.rb
@@ -20,7 +20,7 @@ class TestFiberIO < Test::Unit::TestCase
thread = Thread.new do
scheduler = Scheduler.new
- Thread.current.scheduler = scheduler
+ Fiber.set_scheduler scheduler
Fiber.schedule do
message = i.read(20)
@@ -48,7 +48,7 @@ class TestFiberIO < Test::Unit::TestCase
i, o = UNIXSocket.pair
scheduler = Scheduler.new
- Thread.current.scheduler = scheduler
+ Fiber.set_scheduler scheduler
Fiber.schedule do
i.read(20)
diff --git a/test/fiber/test_mutex.rb b/test/fiber/test_mutex.rb
index d1fe78cba3b..30e92b4fd26 100644
--- a/test/fiber/test_mutex.rb
+++ b/test/fiber/test_mutex.rb
@@ -8,13 +8,13 @@ class TestFiberMutex < Test::Unit::TestCase
thread = Thread.new do
scheduler = Scheduler.new
- Thread.current.scheduler = scheduler
+ Fiber.set_scheduler scheduler
Fiber.schedule do
- assert_not_predicate Thread.current, :blocking?
+ assert_not_predicate Fiber, :blocking?
mutex.synchronize do
- assert_not_predicate Thread.current, :blocking?
+ assert_not_predicate Fiber, :blocking?
end
end
end
@@ -27,7 +27,7 @@ class TestFiberMutex < Test::Unit::TestCase
thread = Thread.new do
scheduler = Scheduler.new
- Thread.current.scheduler = scheduler
+ Fiber.set_scheduler scheduler
Fiber.schedule do
mutex.lock
@@ -53,7 +53,7 @@ class TestFiberMutex < Test::Unit::TestCase
thread = Thread.new do
scheduler = Scheduler.new
- Thread.current.scheduler = scheduler
+ Fiber.set_scheduler scheduler
Fiber.schedule do
mutex.lock
@@ -79,7 +79,7 @@ class TestFiberMutex < Test::Unit::TestCase
thread = Thread.new do
scheduler = Scheduler.new
- Thread.current.scheduler = scheduler
+ Fiber.set_scheduler scheduler
f = Fiber.schedule do
assert_raise_with_message(RuntimeError, "bye") do
@@ -110,7 +110,7 @@ class TestFiberMutex < Test::Unit::TestCase
thread = Thread.new do
scheduler = Scheduler.new
- Thread.current.scheduler = scheduler
+ Fiber.set_scheduler scheduler
Fiber.schedule do
mutex.synchronize do
@@ -145,7 +145,7 @@ class TestFiberMutex < Test::Unit::TestCase
thread = Thread.new do
scheduler = Scheduler.new
- Thread.current.scheduler = scheduler
+ Fiber.set_scheduler scheduler
Fiber.schedule do
3.times do |i|
@@ -176,7 +176,7 @@ class TestFiberMutex < Test::Unit::TestCase
thread = Thread.new do
scheduler = Scheduler.new
- Thread.current.scheduler = scheduler
+ Fiber.set_scheduler scheduler
result = nil
Fiber.schedule do
@@ -204,7 +204,7 @@ class TestFiberMutex < Test::Unit::TestCase
thread = Thread.new do
scheduler = Scheduler.new
- Thread.current.scheduler = scheduler
+ Fiber.set_scheduler scheduler
Fiber.schedule do
mutex.synchronize do
diff --git a/test/fiber/test_scheduler.rb b/test/fiber/test_scheduler.rb
index f38b650846b..72bde9fcc3a 100644
--- a/test/fiber/test_scheduler.rb
+++ b/test/fiber/test_scheduler.rb
@@ -11,11 +11,27 @@ class TestFiberScheduler < Test::Unit::TestCase
end
end
+ def test_fiber_new
+ f = Fiber.new{}
+ refute f.blocking?
+ end
+
+ def test_fiber_new_with_options
+ f = Fiber.new(blocking: true){}
+ assert f.blocking?
+
+ f = Fiber.new(blocking: false){}
+ refute f.blocking?
+
+ f = Fiber.new(pool: nil){}
+ refute f.blocking?
+ end
+
def test_closed_at_thread_exit
scheduler = Scheduler.new
thread = Thread.new do
- Thread.current.scheduler = scheduler
+ Fiber.set_scheduler scheduler
end
thread.join
@@ -27,8 +43,8 @@ class TestFiberScheduler < Test::Unit::TestCase
scheduler = Scheduler.new
thread = Thread.new do
- Thread.current.scheduler = scheduler
- Thread.current.scheduler = nil
+ Fiber.set_scheduler scheduler
+ Fiber.set_scheduler nil
assert scheduler.closed?
end
@@ -41,7 +57,7 @@ class TestFiberScheduler < Test::Unit::TestCase
require 'scheduler'
scheduler = Scheduler.new
- Thread.current.scheduler = scheduler
+ Fiber.set_scheduler scheduler
Fiber.schedule do
sleep(0)
@@ -52,7 +68,7 @@ class TestFiberScheduler < Test::Unit::TestCase
def test_optional_close
thread = Thread.new do
- Thread.current.scheduler = Object.new
+ Fiber.set_scheduler Object.new
end
thread.join
diff --git a/test/fiber/test_sleep.rb b/test/fiber/test_sleep.rb
index a15f2f2bcd5..e8827663457 100644
--- a/test/fiber/test_sleep.rb
+++ b/test/fiber/test_sleep.rb
@@ -10,7 +10,7 @@ class TestFiberSleep < Test::Unit::TestCase
thread = Thread.new do
scheduler = Scheduler.new
- Thread.current.scheduler = scheduler
+ Fiber.set_scheduler scheduler
5.times do |i|
Fiber.schedule do
@@ -33,7 +33,7 @@ class TestFiberSleep < Test::Unit::TestCase
thread = Thread.new do
scheduler = Scheduler.new
- Thread.current.scheduler = scheduler
+ Fiber.set_scheduler scheduler
Fiber.schedule do
seconds = sleep(2)
end