user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 1/2] tests: replace select/usleep calls with tick()
Date: Mon, 12 Dec 2022 04:22:00 +0000	[thread overview]
Message-ID: <20221212042201.510414-2-e@80x24.org> (raw)
In-Reply-To: <20221212042201.510414-1-e@80x24.org>

This makes it easier to identify places in tests which cause
unnecessary slowdowns doing busy waits.
---
 t/cmd_ipc.t      | 3 +--
 t/httpd-corner.t | 2 +-
 t/httpd-unix.t   | 8 ++++----
 t/nntpd.t        | 6 +++---
 4 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/t/cmd_ipc.t b/t/cmd_ipc.t
index 75697a15..cd76d5e8 100644
--- a/t/cmd_ipc.t
+++ b/t/cmd_ipc.t
@@ -10,7 +10,6 @@ pipe(my ($r, $w)) or BAIL_OUT;
 my ($send, $recv);
 require_ok 'PublicInbox::Spawn';
 my $SOCK_SEQPACKET = eval { Socket::SOCK_SEQPACKET() } // undef;
-use Time::HiRes qw(usleep);
 
 my $do_test = sub { SKIP: {
 	my ($type, $flag, $desc) = @_;
@@ -61,7 +60,7 @@ my $do_test = sub { SKIP: {
 			if ($pid == 0) {
 				# need to loop since Perl signals are racy
 				# (the interpreter doesn't self-pipe)
-				while (usleep(1000)) {
+				while (tick(0.01)) {
 					kill 'ALRM', $tgt;
 				}
 			}
diff --git a/t/httpd-corner.t b/t/httpd-corner.t
index e16e8dc8..88820270 100644
--- a/t/httpd-corner.t
+++ b/t/httpd-corner.t
@@ -320,7 +320,7 @@ sub conn_for {
 	$spawn_httpd->('-W0');
 }
 
-sub delay { select(undef, undef, undef, shift || rand(0.02)) }
+sub delay { tick(shift || rand(0.02)) }
 
 my $str = 'abcdefghijklmnopqrstuvwxyz';
 my $len = length $str;
diff --git a/t/httpd-unix.t b/t/httpd-unix.t
index fe4a2161..e915ea2c 100644
--- a/t/httpd-unix.t
+++ b/t/httpd-unix.t
@@ -1,8 +1,8 @@
-# Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
+#!perl -w
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 # Tests for binding Unix domain sockets
 use strict;
-use warnings;
 use Test::More;
 use PublicInbox::TestCommon;
 use Errno qw(EADDRINUSE);
@@ -36,7 +36,7 @@ $spawn_httpd->("-l$unix", '-W0');
 my %o = (Peer => $unix, Type => SOCK_STREAM);
 for (1..1000) {
 	last if -S $unix && IO::Socket::UNIX->new(%o);
-	select undef, undef, undef, 0.02
+	tick(0.02);
 }
 
 ok(-S $unix, 'UNIX socket was bound by -httpd');
@@ -89,7 +89,7 @@ sub delay_until {
 	my $end = time + 30;
 	do {
 		return if $cond->();
-		select undef, undef, undef, 0.012;
+		tick(0.012);
 	} until (time > $end);
 	Carp::confess('condition failed');
 }
diff --git a/t/nntpd.t b/t/nntpd.t
index 058bd796..30233ce0 100644
--- a/t/nntpd.t
+++ b/t/nntpd.t
@@ -358,7 +358,7 @@ Date: Fri, 02 Oct 1993 00:00:00 +0000
 		}
 		ok(run_script([qw(-index -c -j0 --reindex), $ibx->{inboxdir}],
 				undef, $noerr), '-compacted');
-		select(undef, undef, undef, $fast_idle ? 0.1 : 2.1);
+		tick($fast_idle ? 0.1 : 2.1);
 		$art = $n->article($ex->header('Message-ID'));
 		ok($art, 'new article retrieved after compact');
 		$lsof or skip 'lsof missing', 1;
@@ -372,9 +372,9 @@ Date: Fri, 02 Oct 1993 00:00:00 +0000
 	{
 		setsockopt($s, IPPROTO_TCP, TCP_NODELAY, 1);
 		syswrite($s, 'HDR List-id 1-');
-		select(undef, undef, undef, 0.15);
+		tick(0.15);
 		ok($td->kill, 'killed nntpd');
-		select(undef, undef, undef, 0.15);
+		tick(0.15);
 		syswrite($s, "\r\n");
 		$buf = '';
 		do {

  reply	other threads:[~2022-12-12  4:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-12  4:21 [PATCH 0/2] some sleep elimination Eric Wong
2022-12-12  4:22 ` Eric Wong [this message]
2022-12-12  4:22 ` [PATCH 2/2] t/httpd-unix: eliminate some busy waits Eric Wong

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://public-inbox.org/README

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

  git send-email \
    --in-reply-to=20221212042201.510414-2-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /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://80x24.org/public-inbox.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).