From 46655156dcc37509dcb69fcd0717c110eb1c624a Mon Sep 17 00:00:00 2001 From: "NARUSE, Yui" Date: Sat, 22 May 2021 21:36:27 +0900 Subject: Add Thread#native_thread_id [Feature #17853] --- test/ruby/test_thread.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/ruby') 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 } -- cgit v1.2.3