summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLars Kanis <lars@greiz-reinsdorf.de>2021-02-28 19:33:12 +0100
committerLars Kanis <lars@greiz-reinsdorf.de>2021-02-28 19:33:12 +0100
commit1cce06db0b774ee46ef98ea9ca6ceec5d21694a4 (patch)
tree2d659f4dccf889247df366c4e4502f4275aee3c4 /spec
parentc48dfe79c772074d6afc9dfa85fbf8f58a27b860 (diff)
parent7099d9594667297baa8fd3a23a5f610649b4a7fc (diff)
downloadffi-1cce06db0b774ee46ef98ea9ca6ceec5d21694a4.tar.gz
Merge branch 'name-dispatcher-thread' of https://github.com/DataDog/ffi into DataDog-name-dispatcher-thread
Diffstat (limited to 'spec')
-rw-r--r--spec/ffi/async_callback_spec.rb11
-rw-r--r--spec/ffi/function_spec.rb9
2 files changed, 20 insertions, 0 deletions
diff --git a/spec/ffi/async_callback_spec.rb b/spec/ffi/async_callback_spec.rb
index 7783a8a..d770355 100644
--- a/spec/ffi/async_callback_spec.rb
+++ b/spec/ffi/async_callback_spec.rb
@@ -39,4 +39,15 @@ describe "async callback" do
expect(th1).to_not eq(th2)
expect(v).to eq(6)
end
+
+ it "sets the name of the thread that runs the callback" do
+ skip "not yet supported on TruffleRuby" if RUBY_ENGINE == "truffleruby"
+ skip "not yet supported on JRuby" if RUBY_ENGINE == "jruby"
+
+ callback_runner_thread = nil
+
+ LibTest.testAsyncCallback(proc { callback_runner_thread = Thread.current }, 0)
+
+ expect(callback_runner_thread.name).to eq("FFI::Function Callback Runner")
+ end
end
diff --git a/spec/ffi/function_spec.rb b/spec/ffi/function_spec.rb
index dd4d2ea..a7d6dc7 100644
--- a/spec/ffi/function_spec.rb
+++ b/spec/ffi/function_spec.rb
@@ -21,6 +21,15 @@ describe FFI::Function do
expect(fn.call).to eql 5
end
+ context 'when called with a block' do
+ it 'creates a thread for dispatching callbacks and sets its name' do
+ skip 'this is MRI-specific' if RUBY_ENGINE == 'truffleruby' || RUBY_ENGINE == 'jruby'
+ FFI::Function.new(:int, []) { 5 } # Trigger initialization
+
+ expect(Thread.list.map(&:name)).to include('FFI::Function Callback Dispatcher')
+ end
+ end
+
it 'raises an error when passing a wrong signature' do
expect { FFI::Function.new([], :int).new { } }.to raise_error TypeError
end