about summary refs log tree commit homepage
path: root/test/test_posix_mq.rb
DateCommit message (Collapse)
2017-03-18test_posix_mq: get tests passing under FreeBSD 10.3
Apparently POSIX message queues adopted close-on-fork behavior in FreeBSD at some point. Oh well, somebody else who is more interested in FreeBSD than can look into fixing it on their end. Improve exception reporting a bit while we're at it.
2016-02-02support idempotent POSIX_MQ#close
IO#close under Ruby 2.3 is idempotent, we shall follow suit with POSIX_MQ#close
2016-02-02enable frozen_string_literal for Ruby 2.3+
No changes for older Rubies, but this reduces garbage under 2.3
2015-01-16POSIX_MQ#autoclose= propagates to IO
If a corresponding IO object exists or is created later, propagate autoclose to the corresponding IO object to avoid simplify autoclose handling for the user. This hopefully avoids nasty surprises in case users disable autoclose but want to keep the IO object around.
2015-01-09support autoclose= and autoclose?
These are analogous to the identically-named IO methods and useful when we're inheriting descriptors (or writing tests for inheriting descriptors).
2015-01-09test_posix_mq: rewrite test to not depend on DL or alarm
DL is removed and deprecated, and we don't actually need it or alarm to test for EINTR-safety.
2015-01-04Ability to adopt file descriptors
This patch adds support for adopting an existing file descriptor, together with testcases. The need for this comes up when we use systemd with the ListenMessageQueue directive. For socket activation, systemd opens the POSIX message queue and expects user code to begin using the file descriptor without opening it in-process. To support the systemd model in the `posix_mq` gem, this patch suggests imitating the behavior on the Socket class, which uses `#for_fd` to create a socket class from a descriptor. One confounding factor exists. POSIX queues have a name but it is difficult to get access to this name in a safe manner from the file descriptor. One option would be to `readlink(2)` on `/proc/self/fd/N` to get the name[1], but note that if the descriptor is unlinked we wouldn't get anything usable. Rather than risk incorrect behavior and extra complexity, I've decided to just raise an `ArgumentError` if `#name` is called on adopted descriptors. Typically one wouldn't need the actual name in a systemd socket-activated situation, anyway. [1]: http://stackoverflow.com/questions/1188757/getting-filename-from-file-descriptor-in-c [ew: simplified type checks to be consistent with IO.for_fd, fixed test case] Signed-off-by: Eric Wong <normalperson@yhbt.net>
2012-07-12test: relax test timings for timed* tests
On my i386-freebsd9 VM, this takes just longer than the maximum allowable time.
2012-07-12test: disable IO.select test if #to_io is missing
2012-07-05blocking functions do not raise Errno::EINTR
Blocking functions should not raise Errno::EINTR to match existing semantics of Ruby IO methods (e.g. IO.select, IO#read, IO#write). This makes user code easier to read/write. Like th Ruby methods we emulate, we only reacquire the GVL on EINTR to fire signal handlers, but otherwise emulate SA_RESTART semantics. This is a backwards-incompatible API change (but unlikely to break existing code).
2012-07-03Add libc names for Debian GNU/kFreeBSD and FreeBSD in tests.
Signed-off-by: Eric Wong <normalperson@yhbt.net>
2012-07-03Fix call to DL::Function.new in tests
The 3rd argument of DL::Function.new is ABI type, not a return type. Signed-off-by: Eric Wong <normalperson@yhbt.net>
2011-03-01POSIX_MQ#send returns +true+ on success
This is to be consistent with POSIX_MQ#trysend
2011-02-27fix warnings and enable them for tests
Cleaner code anyways.
2011-02-27add trysend, tryreceive, and tryshift interfaces
These are kinder and less exceptional than their non-trying counterparts as generating exceptions is expensive for common EAGAIN errors.
2011-02-27tests: do not require Fiddle for Ruby 1.9
It's only available when compiled with libffi.
2011-02-27Do not trust locally cached mq_flags
These flags can be changed in the parent or child process, so we will always have to run mq_getattr() to check it. This removes the GVL-keeping non-blocking optimizations but we'll gain some soon.
2011-02-23cleanup DL usage for alarm() test
2011-02-23fix test alarm() case for Ruby 1.9
DL in Ruby 1.9 isn't the same
2011-02-23test for alarm() working properly to interrupt
Some systems without mq_timedsend/mq_timedreceive need to use alarm() or similar (setitimer()) to interrupt timed-out mq_send/mq_receive calls, so we need to handle EINTR properly.
2011-02-23test: fix GC test for systems without POSIX_MQ#to_io
Not all systems can convert POSIX_MQ to IO objects.
2011-02-22attempt to support systems w/o mq_timedsend/mq_timedreceive
Some ancient systems don't support mq_timedsend and mq_timedreceive but somehow manage to support other POSIX mq_* functions.
2011-02-22use StringValueCStr for paths
RSTRING_PTR may contain '\0' bytes which makes it unsuitable for mq_unlink() and mq_open()
2010-12-24add Rubinius support
Cleaner code, too, no more direct RSTRUCT usage.
2010-12-24refactor type checks and remove unnecessary guards
StringValuePtr should already be a sufficient guard. There are more tests while we're at it, too, and we'll now raise TypeError instead of ArgumentError when a POSIX_MQ::Attr is not passed properly.
2010-12-24remove rb_time_interval() and gettimeofday() dependency
This function isn't exported in the standard Ruby headers, it returns an aggregate value and isn't available in Rubinius, either, so nuke it. While we're at it, use clock_gettime() instead of gettimeofday() to avoid unnecessary timeval usage since mq_send/mq_receive rely on higher-precision timespecs instead.
2010-08-19tests: use Class#method_defined?
I did not know about this method back in the day...
2010-08-19test: avoid leaving queues behind
We shouldn't unnecessarily hog system resources.
2010-08-19avoid double close() and EBADF
It can be dangerous to hit (and ignore) EBADF errors in multi-threaded applications. Users of POSIX_MQ#to_io have two Ruby objects pointing to the same file descriptor, making things tricky when it comes time to reap resources. We'll always prefer to close the Ruby IO object if it exists (because we have less control over its GC behavior) and ignore the raw descriptor.
2010-08-02open/notify: invoke GC if needed
On ENOMEM, EMFILE, and ENFILE errors, it is customary to invoke the Ruby GC and free up resources and retry the system call.
2010-05-09fix POSIX_MQ#notify(&block) aka SIGEV_THREAD
tests for them were stupidly broken and never executed :x
2010-03-13ensure POSIX_MQ#name is clobber-proof
We don't want folks to accidentally clobber the value for others, so allocate a new string object for it (don't worry, rb_str_dup() is cheap in 1.9).
2010-02-20make POSIX_MQ#dup and POSIX_MQ#clone no-op
It'll cause problems for the automatic mq_close() during GC otherwise, as dup(2) on an mqd_t isn't portable. Of course there's no point in cloning or duping, either, as mq_send/mq_receive operations are always atomic at the kernel level and only one thread can have a notification registered for it.
2010-01-21add #shift test with destination buffer
2010-01-07add POSIX_MQ#shift helper method
This acts like POSIX_MQ#receive but only returns the message without the priority.
2010-01-07POSIX_MQ#notify only works on GNU/Linux for now
SIGEV_THREAD is not easy to implement, so many platforms do not implement it.
2010-01-07POSIX_MQ#notify block execution on message received
This is implementation uses both a short-lived POSIX thread and a pre-spawned Ruby Thread in a manner that works properly under both Ruby 1.8 (green threads) and 1.9 (where Ruby Threads are POSIX threads). The short-lived POSIX thread will write a single "\0" byte to a pipe the Ruby Thread waits on. This operation is atomic on all platforms. Once the Ruby Thread is woken up from the pipe, it will execute th block given to it. This dual-thread implementation is inspired by the way glibc implements mq_notify(3) + SIGEV_THREAD under Linux where the kernel itself cannot directly spawn POSIX threads.
2010-01-02Fix mq.notify = nil to unregister notifications
"mq.notify = false" also works now, doing what "mq.notify = nil" used to do (using SIGEV_NONE). I was confused by SIGEV_NONE usage vs using a NULL pointer for the notification passed mq_notify(3). SIGEV_NONE does not actually unregister, it registers a no-op notification which prevents other processes from taking us. This also fixes the test case to pass under both Linux and FreeBSD.
2010-01-02initial commit v0.1.0