summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-09-24 09:50:01 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-09-24 09:50:01 +0900
commit94d7c7080191b0ee3b4a8247788208aa732ce810 (patch)
treea751388f0dd718f53fed037a8a7bbdb0d6fe85ef
parentf38f8d4f4ab5db40eb8a4f6d21b1b73e72b344f4 (diff)
Fix test thread leakage
-rw-r--r--test/socket/test_socket.rb16
1 files changed, 10 insertions, 6 deletions
diff --git a/test/socket/test_socket.rb b/test/socket/test_socket.rb
index ab4563dce2..5645723558 100644
--- a/test/socket/test_socket.rb
+++ b/test/socket/test_socket.rb
@@ -447,13 +447,12 @@ class TestSocket < Test::Unit::TestCase
omit "UDP server is no response: #{$!}"
ensure
if th
- if skipped
- Thread.kill th unless th.join(10)
- else
+ unless skipped
Addrinfo.udp("127.0.0.1", port).connect {|s| s.sendmsg "exit" }
- unless th.join(10)
- Thread.kill th
- th.join(10)
+ end
+ unless th.join(10)
+ th.kill.join(10)
+ unless skipped
raise "thread killed"
end
end
@@ -497,6 +496,7 @@ class TestSocket < Test::Unit::TestCase
assert(stamp.cmsg_is?(:SOCKET, type))
w.close # stop th
n = th.value
+ th = nil
n > 1 and
warn "UDP packet loss for #{type} over loopback, #{n} tries needed"
t2 = Time.now.strftime("%Y-%m-%d")
@@ -505,6 +505,10 @@ class TestSocket < Test::Unit::TestCase
t = stamp.timestamp
assert_match(pat, t.strftime("%Y-%m-%d"))
stamp
+ ensure
+ if th and !th.join(10)
+ th.kill.join(10)
+ end
end
end