summaryrefslogtreecommitdiff
path: root/test/scheduler/test_io.rb
diff options
context:
space:
mode:
authorSamuel Williams <samuel.williams@oriontransfer.co.nz>2020-05-14 22:10:55 +1200
committerGitHub <noreply@github.com>2020-05-14 22:10:55 +1200
commit0e3b0fcdba70cf96a8e0654eb8f50aacb8024bd4 (patch)
tree74d381412dfd8ff49dd3039f8aeae09ad9e4e6e3 /test/scheduler/test_io.rb
parent336119dfc5e6baae0a936d6feae780a61975479c (diff)
Thread scheduler for light weight concurrency.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3032 Merged-By: ioquatix <samuel@codeotaku.com>
Diffstat (limited to 'test/scheduler/test_io.rb')
-rw-r--r--test/scheduler/test_io.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/test/scheduler/test_io.rb b/test/scheduler/test_io.rb
new file mode 100644
index 0000000000..ef46d1ac2c
--- /dev/null
+++ b/test/scheduler/test_io.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+require 'test/unit'
+require_relative 'scheduler'
+
+class TestSchedulerIO < Test::Unit::TestCase
+ MESSAGE = "Hello World"
+
+ def test_read
+ skip unless defined?(UNIXSocket)
+
+ i, o = UNIXSocket.pair
+ skip unless i.nonblock? && o.nonblock?
+
+ message = nil
+
+ thread = Thread.new do
+ scheduler = Scheduler.new
+ Thread.current.scheduler = scheduler
+
+ Fiber do
+ message = i.read(20)
+ i.close
+ end
+
+ Fiber do
+ o.write("Hello World")
+ o.close
+ end
+ end
+
+ thread.join
+
+ assert_equal MESSAGE, message
+ end
+end