posix_mq RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
* [PATCH] test_posix_mq: rewrite test to not depend on DL or alarm
@ 2015-01-09  7:35 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2015-01-09  7:35 UTC (permalink / raw)
  To: ruby.posix.mq

DL is removed and deprecated, and we don't actually need
it or alarm to test for EINTR-safety.
---
 test/test_posix_mq.rb | 27 ++++++++-------------------
 1 file changed, 8 insertions(+), 19 deletions(-)

diff --git a/test/test_posix_mq.rb b/test/test_posix_mq.rb
index 54c7223..3583022 100644
--- a/test/test_posix_mq.rb
+++ b/test/test_posix_mq.rb
@@ -3,11 +3,6 @@ require 'test/unit'
 require 'thread'
 require 'fcntl'
 $stderr.sync = $stdout.sync = true
-require "dl"
-begin
-  require "dl/func"
-rescue LoadError
-end
 $-w = true
 require 'posix_mq'
 
@@ -104,23 +99,15 @@ class Test_POSIX_MQ < Test::Unit::TestCase
     assert elapsed < 1.10, elapsed.inspect
   end
 
-  def test_alarm_signal_safe
-    libc = alarm = nil
-    libcs = %w(libc.so.6 libc.so.0.1 libc.so.7 /usr/lib/libc.sl)
-    libcs.each do |name|
-      libc = DL::Handle.new(name) rescue next
-      if defined?(DL::Function)
-        alarm = libc["alarm"]
-        alarm = DL::CFunc.new(alarm, DL::TYPE_INT, "alarm")
-        alarm = DL::Function.new(alarm, [DL::TYPE_INT])
-      else
-        alarm = libc["alarm", "II"]
+  def test_signal_safe
+    alarm = lambda do |x|
+      Thread.new(x) do |time|
+        sleep(time)
+        Process.kill(:USR1, $$)
       end
-      break
     end
-    alarm or return warn "alarm() not found in #{libcs.inspect}"
     alarms = 0
-    trap("ALRM") do
+    sig = trap(:USR1) do
       alarms += 1
       Thread.new { @mq.send("HI") }
     end
@@ -135,6 +122,8 @@ class Test_POSIX_MQ < Test::Unit::TestCase
     assert elapsed >= interval, elapsed.inspect
     assert elapsed < 1.10, elapsed.inspect
     assert_equal 1, alarms
+  ensure
+    trap(:USR1, sig) if sig
   end
 
   def test_timed_send
-- 
EW



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2015-01-09  7:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-09  7:35 [PATCH] test_posix_mq: rewrite test to not depend on DL or alarm Eric Wong

Code repositories for project(s) associated with this public inbox

	https://yhbt.net/ruby_posix_mq.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).