about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2015-01-09 07:28:21 +0000
committerEric Wong <normalperson@yhbt.net>2015-01-09 07:34:06 +0000
commit8d10e4aa66f32abd16d9b6ac0049f777be495d6b (patch)
tree47b696413fe9f72621551936078beffbc686dc68
parentf0f0cb23acc155e24a70a718801e807c80349e13 (diff)
downloadruby_posix_mq-8d10e4aa66f32abd16d9b6ac0049f777be495d6b.tar.gz
DL is removed and deprecated, and we don't actually need
it or alarm to test for EINTR-safety.
-rw-r--r--test/test_posix_mq.rb27
1 files 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