diff options
author | Lars Kanis <lars@greiz-reinsdorf.de> | 2021-02-28 19:33:12 +0100 |
---|---|---|
committer | Lars Kanis <lars@greiz-reinsdorf.de> | 2021-02-28 19:33:12 +0100 |
commit | 1cce06db0b774ee46ef98ea9ca6ceec5d21694a4 (patch) | |
tree | 2d659f4dccf889247df366c4e4502f4275aee3c4 /spec | |
parent | c48dfe79c772074d6afc9dfa85fbf8f58a27b860 (diff) | |
parent | 7099d9594667297baa8fd3a23a5f610649b4a7fc (diff) | |
download | ffi-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.rb | 11 | ||||
-rw-r--r-- | spec/ffi/function_spec.rb | 9 |
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 |