summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSamuel Williams <samuel.williams@oriontransfer.co.nz>2022-05-08 10:22:58 +1200
committerGitHub <noreply@github.com>2022-05-08 10:22:58 +1200
commitfd6cef79f54bebab1a49256034687dcc01a09eab (patch)
tree75b35bc5a2260033dcac1bec60822ff0dafda570 /test
parent679b6e43c758bc8a509fc764638e2c30fb7f4279 (diff)
Use a proper mutex for autoloading features. (#5788)
Object#autoload implements a custom per-thread "mutex" for blocking threads waiting on autoloading a feature. This causes problems when used with the fiber scheduler. We swap the implementation to use a Ruby mutex which is fiber aware.
Notes
Notes: Merged-By: ioquatix <samuel@codeotaku.com>
Diffstat (limited to 'test')
-rw-r--r--test/fiber/autoload.rb3
-rw-r--r--test/fiber/test_scheduler.rb19
2 files changed, 22 insertions, 0 deletions
diff --git a/test/fiber/autoload.rb b/test/fiber/autoload.rb
new file mode 100644
index 0000000000..dcb27164a7
--- /dev/null
+++ b/test/fiber/autoload.rb
@@ -0,0 +1,3 @@
+sleep 0.01
+module TestFiberSchedulerAutoload
+end
diff --git a/test/fiber/test_scheduler.rb b/test/fiber/test_scheduler.rb
index 1870ab1c33..08ac386c29 100644
--- a/test/fiber/test_scheduler.rb
+++ b/test/fiber/test_scheduler.rb
@@ -104,4 +104,23 @@ class TestFiberScheduler < Test::Unit::TestCase
thread.join
end
+
+ def test_autoload
+ Object.autoload(:TestFiberSchedulerAutoload, File.expand_path("autoload.rb", __dir__))
+
+ thread = Thread.new do
+ scheduler = Scheduler.new
+ Fiber.set_scheduler scheduler
+
+ 10.times do
+ Fiber.schedule do
+ Object.const_get(:TestFiberSchedulerAutoload)
+ end
+ end
+ end
+
+ thread.join
+ ensure
+ Object.send(:remove_const, :TestFiberSchedulerAutoload)
+ end
end