diff options
author | NARUSE, Yui <naruse@airemix.jp> | 2021-05-22 21:36:27 +0900 |
---|---|---|
committer | NARUSE, Yui <naruse@airemix.jp> | 2021-05-26 15:14:11 +0900 |
commit | 46655156dcc37509dcb69fcd0717c110eb1c624a (patch) | |
tree | e21a75ebde64d8e7f05627fc990b62c47c8099c6 /test/ruby | |
parent | 88e3848fca69915a24657bcc26da1a65b659c6f3 (diff) |
Add Thread#native_thread_id [Feature #17853]
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_thread.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb index 6005e5b001..d87160a2a8 100644 --- a/test/ruby/test_thread.rb +++ b/test/ruby/test_thread.rb @@ -1334,6 +1334,27 @@ q.pop assert_equal("foo", c.new {Thread.current.name}.value, bug12290) end + def test_thread_native_thread_id + skip "don't support native_thread_id" unless (Thread.main.native_thread_id rescue nil) + assert_instance_of Integer, Thread.main.native_thread_id + + th1 = Thread.start{sleep} + + # newly created thread which doesn't run yet returns nil or integer + assert_include [NilClass, Integer], th1.native_thread_id.class + + Thread.pass until th1.stop? + + # After a thread starts (and execute `sleep`), it returns native_thread_id + assert_instance_of Integer, th1.native_thread_id + + th1.wakeup + Thread.pass while th1.alive? + + # dead thread returns nil + assert_nil th1.native_thread_id + end + def test_thread_interrupt_for_killed_thread opts = { timeout: 5, timeout_error: nil } |