about summary refs log tree commit homepage
path: root/test
DateCommit message (Collapse)
2024-03-23treewide: future-proof frozen_string_literal changes
Once again Ruby seems ready to introduce more incompatibilities and force busywork upon maintainers[1]. In order to avoid incompatibilities in the future, I used the following Perl script to prepend `frozen_string_literal: false' to every Ruby file: use v5.12; use autodie; my $usage = 'perl /path/to/script <LIST_OF_RB_FILES>'; my $fsl = "# frozen_string_literal: false\n"; for my $f (@ARGV) { open my $fh, '<', $f; my $s = do { local $/; <$fh> } // die "read($f): $!"; next if $s =~ /^#\s*frozen_string_literal:/sm; # fsl must be after encoding: line if it exists: if ($s =~ s/^([ \t]*\#[ \t\-\*\#]+encoding:[^\n]+\n)/$1$fsl/sm # or after the shebang || $s =~ s/^(#![^\n]+\n)/$1$fsl/ # or after embedded switches in rackup files: || ($f =~ /\.ru$/ && $s =~ s/^(#\\[^\n]+\n)/$1$fsl/) # or prepend as a last resort: || (substr($s, 0, 0) = $fsl)) { open $fh, '>', $f; print $fh $s; close $fh; } } Somebody interested will have to go through every Ruby source file and enable frozen_string_literal once they've thoroughly verified it's safe to do so. [1] https://bugs.ruby-lang.org/issues/20205
2024-01-15test/test_last_data_recv: don't require posix_mq
posix_mq is rarely installed, so don't force users to have it in order to test or develop raindrops.
2024-01-15tests: support running tests without rack||aggregate
Diskspace and bandwidth are expensive, and we can make rack+aggregate optional in tests, too.
2023-09-10aggregate/last_data_recv: support Socket#accept{,_nonblock}
Socket#accept and Socket#accept_nonblock return an Addrinfo object in addition to a client socket. This allows web servers to avoid having to make getpeername(2) syscalls to get the same information.
2023-06-26test_linux_reuseport_tcp_listen_stats: skip w/o unicorn
We don't list `unicorn' as a development dependency since unicorn currently depends on this project. While unicorn might drop us as a dependency, don't waste disk space and bandwidth of potential raindrops hackers who don't have unicorn.
2023-02-24Fix off by one error in test
It doesn't affect the test outcome, but it is not the intended behaviour of the test. We listen once to find out what port to use, then should bind with SO_REUSEPORT N-1 times, but we are doing it N times, so we have one extra listener.
2023-02-24Fix queue stats for sockets with SO_REUSEPORT
SO_REUSEPORT was introduced in 2013, see https://lwn.net/Articles/542629/. However, the current logic for calculating socket queue backlog stats is from 2011, predating the advent of SO_REUSEPORT. The current strategy was thus written before the notion that the mapping of INET_ADDR:socket could potentially be 1:N instead of always 1:1. This causes raindrops to provide invalid socket backlog values when SO_REUSEPORT is used, which Unicorn supports since 2013. The current behaviour will set the queue metric to the queue depth of the last inet_diag_msg it processes matching the INET_ADDR. In practice, this will result in the backlog being off by a factor N, assuming relatively even distribution of requests to sockets, which the kernel should guarantee through consistent hashing. The fix here is to accumulate the socket queue depth as we iterate over the the socket diagnostics, rather than reset it each time. I have a provided a test, but it only checks the queues, not the accept metrics, as those are not affected by this bug, and it is not possible to know which of the listeners will be dispatched the request by the kernel, and thus which should call accept.
2021-11-26Allow Raindrops objects to be backed by a file
Currently, all memory used by Raindrops is mapped as MAP_ANONYMOUS. This means that although Raindrops counters can be shared between processes that have forked from each other, it is not possible to share the counter values with another, unrelated process. This patch adds support for backing the Raindrops mapping with a file descriptor obtained from an IO object. The #initialize API has been enhanced with two new keyword options: Raindrops.new(size, io: nil, zero: false) If an instance of IO is provided, then the underlying file descriptor for that IO will be used to back the memory mapping Raindrops creates. An unrelated process can then open the same file, and read the counters; either by mmap'ing the file itself (or using Raindrops to do so), or by making ordinary seek()/read() calls if performance is not a concern. Note that the provided IO object _must_ implement #truncate; this is used to set the size of the file to be right-sized for the memory mapping that is created. If the zero argument is passed as true, then the mapping will be zero'd by Raindrops as part of its initialization. If it's false, then the Raindrops counters existing in the file will be preserved. This allows counter values to be persisted (although note that Raindrops makes no attempt to msync the values, so they are not durable to e.g. system crashes). Counter values can easily be shared between processes in-memory only without touching the disk by passing in a File on a tmpfs as the io object.
2020-01-06fixes for newer rubies
Newer rubies have more warnings
2017-03-17define Raindrops::TCP hash for TCP states freebsd
FreeBSD not only uses different values than Linux for TCP states, but different names, too. To ease writing portable code between the OSes, do more CPP metaprogramming via extconf.rb and define a common hash supported on both OSes. Putting all this in a hash allows for easy dumping and mapping in an OS-neutral way, since the actual TCP states are OS-independent.
2017-03-17tcp_info: support this struct under FreeBSD
Of course these fields are not portable between Linux and FreeBSD, but they should remain ABI-compatible for future versions of each OS. Tested on FreeBSD 10.3-RELEASE i386 TCP state names will be another problem...
2017-03-15test_watcher: disable test correctly when aggregate is missing
While we're at it, improve the description of other skips.
2016-09-27test_inet_diag_socket: fix Fixnum deprecation warning
Ruby 2.4 will unify Fixnum and Bignum.
2016-02-25linux: tcp_listener_stats drops "true" placeholders
With invalid addresses specified which give no currently-bound address, we must avoid leaving placeholders ('true' objects) in our results. Clean up some shadowing "cur" while we're at it.
2014-11-14Add setup and teardown for ipv6 tests
Signed-off-by: Eric Wong <normalperson@yhbt.net>
2013-09-02test_watcher: fix for Ruby trunk r40195 and later
assert_raises doesn't capture exceptions the same way rescue works.
2013-04-11Linux::TCP_Info: implement #get! instance method
This allows reusing existing Linux::TCP_Info objects to avoid generating garbage.
2012-06-18test_watcher: fix incorrect request/date comparison
It makes no sense to compare peak times of different queues (active vs queued) against each other.
2012-06-12unix: show zero-value stats for idle listeners
When unix_listener_stats is called without arguments, it should still match the behavior of tcp_listener_stats and return ListenerStats object with zero values. This allows callers to iterate through the results to find the pathnames of all the Unix domain sockets in in listen mode.
2012-06-05unix_listener_stats follows and remembers symlinks
Teach unix_listener_stats to remember the symlink path it followed and have it point to the same object as the resolved (real) socket path. This allows the case where looking up stats by symlinks works if the symlink is given to unix_listener_stats: File.symlink("/real/path/of.sock", "/path/to/link.sock") stats = unix_listener_stats(["/path/to/link.sock"]) stats["/path/to/link.sock"] => # same as stats["/real/path/of.sock"]
2012-06-05resolve symlinks to Unix domain sockets
Raindrops currently fails when provided a symlink to a socket. As this is a common practice for many deployment tools (Vlad, etc.) this patch adds support for finding the realpath prior to looking the socket up in /proc/net/unix [ew: commit message subject] [ew: fixed test to pass under 1.9.3 and 1.8.7: * Tempfile#unlink is unsafe to call if we want to reuse the path, use File.unlink(tmp.path) instead * The return value of File.symlink is zero (or it raises), so it's unusable. * File.symlink will not call #to_path under 1.8.7, so it's necessary to pass pathnames to it, not Tempfile objects. ] Signed-off-by: Eric Wong <normalperson@yhbt.net>
2012-05-18Add method_missing to Raindrops::Middleware::Proxy
This enables it to behave more like a Rack BodyProxy would, delegating methods to its body object when it does not implement them itself. (Also includes a minor grammar fix to a comment.) [ew: minor comment/whitespace fix] Signed-off-by: Eric Wong <normalperson@yhbt.net>
2011-11-14Test suite fix for non-linux users
Most other linux-specific test files have this, but test_linux_tcp_info.rb does not. With this patch, gmake test passes on OpenBSD.
2011-10-12avoid inadvertant object creation with invalid addresses
Just in case somebody tries to scan all addresses, we won't run out of memory as easily.
2011-10-03watcher: add peak times for statistics
It could be useful to know when the first and last peak time of a maximum was.
2011-09-27test: updates for newer Unicorn API
Unicorn.run no longer exists
2011-09-27watcher: add X-Current header to headers
It can be useful to some to see that info all at once without hitting the HTML index page.
2011-06-27Fix bad rescue statements in a couple tests
2011-06-27fix Ruby warnings
Found in the check-warnings target in pkg.mk
2011-06-15test_linux_tcp_info: fix test for higher HZ systems
The last_data_recv field is dependent on the CONFIG_HZ of the kernel, so the stock 250 HZ kernel can change the timing on us.
2011-03-21inet_diag: FD_CLOEXEC for inet_diag sockets by default
Very few programs can take advantage of inheriting FDs across exec() boundaries, and inet_diag sockets have no reason to be used in this way.
2011-03-18watcher: set Expires headers for cache invalidation
We know exactly when to invalidate based on the delay :)
2011-03-16test_raindrops_gc: disable by default
It takes too long
2011-03-16test_linux_all_tcp_listen_stats_leak: fix for 1.8
Apparently 1.8 Test::Unit doesn't like empty test classes
2011-03-16add Watcher Rack application
It does streaming!
2011-03-14linux: unix_listener_stats may scan all paths
This matches behavior of the TCP version.
2011-03-12allow reusing netlink socket for inet_diag
No need to waste resources on creating/destroying a socket.
2011-03-12tests: remove unused_port function
It's not needed since we don't care to rebind sockets
2011-03-12inet_diag: fold all_tcp_listener_stats into tcp_listener_stats
No reason to have an extra method. This also speeds up the multi-listener case for tcp_listener_stats since it avoids expensive sendmsg() syscalls.
2011-03-12inet_diag: stricter IPv6 address parsing
Be stricter about invalid inputs.
2011-03-11linux: method for dumping all TCP listener stats
This is a work-in-progress and will probably be modified before the next release.
2011-03-10tests: only do the GC test on MRI
"Advanced" GCs are typically less aggressive and typically allow much more memory to be used.
2011-03-10tests: ensure munmap() in children don't muck up the parent
Raindrops is designed to work with forking servers after all.
2011-03-11support for Raindrops#size= and Raindrops#evaporate!
This allows limited resizing of the Raindrops memory area since we always over-allocate due to the required page aligment for mmap. It would be nice if mremap() worked with MAP_SHARED, but it does not and triggers a bus error when attempting to access the new area. ref: https://bugzilla.kernel.org/show_bug.cgi?id=8691
2011-03-10test_middleware_unicorn: GC is aggressive!
Oops, don't let GC close our listener before Unicorn can inherit it.
2011-03-09disable aggregate/pmq stuff under 1.8
POSIX message queues needs native threads to function.
2011-03-08preliminary Rack app to track last_data_recv
Seems to basically work
2011-03-04test_linux_tcp_info: add test for last_data_recv
2011-03-04Aggregate support via POSIX message queues
2011-03-01tests: cleaner skipping for missing components