posix_mq RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: ruby.posix.mq@librelist.com
Subject: [PATCH] test_posix_mq: rewrite test to not depend on DL or alarm
Date: Fri,  9 Jan 2015 07:35:23 +0000	[thread overview]
Message-ID: <1420788923-23815-1-git-send-email-normalperson@yhbt.net> (raw)
In-Reply-To: <1420788923-23815-1-git-send-email-normalperson@yhbt.net>

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



           reply	other threads:[~2015-01-09  7:35 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <1420788923-23815-1-git-send-email-normalperson@yhbt.net>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/ruby_posix_mq/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1420788923-23815-1-git-send-email-normalperson@yhbt.net \
    --to=normalperson@yhbt.net \
    --cc=ruby.posix.mq@librelist.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).