summaryrefslogtreecommitdiff
path: root/regress/usr.sbin
diff options
context:
space:
mode:
authorSebastian Benoit <benno@cvs.openbsd.org>2015-07-18 22:11:35 +0000
committerSebastian Benoit <benno@cvs.openbsd.org>2015-07-18 22:11:35 +0000
commit22b2cfccf1d350df98cf41ef45887b4ad035d551 (patch)
treed71b266a525488e9cfac544c84d749d8bf7d48bd /regress/usr.sbin
parentc547c0fcb6ed385c90692dec2a38a2e8304d6352 (diff)
add relayd regression test args-http-slow-consumer.pl
ok reyk@, bluhm@
Diffstat (limited to 'regress/usr.sbin')
-rw-r--r--regress/usr.sbin/relayd/Client.pm23
-rw-r--r--regress/usr.sbin/relayd/Server.pm22
-rw-r--r--regress/usr.sbin/relayd/args-http-slow-consumer.pl42
-rw-r--r--regress/usr.sbin/relayd/funcs.pl91
4 files changed, 175 insertions, 3 deletions
diff --git a/regress/usr.sbin/relayd/Client.pm b/regress/usr.sbin/relayd/Client.pm
index fd987f93bb1..854b912fe21 100644
--- a/regress/usr.sbin/relayd/Client.pm
+++ b/regress/usr.sbin/relayd/Client.pm
@@ -1,4 +1,4 @@
-# $OpenBSD: Client.pm,v 1.10 2015/05/22 19:09:18 bluhm Exp $
+# $OpenBSD: Client.pm,v 1.11 2015/07/18 22:11:34 benno Exp $
# Copyright (c) 2010-2015 Alexander Bluhm <bluhm@openbsd.org>
#
@@ -58,6 +58,27 @@ sub child {
PeerPort => $self->{connectport},
SSL_verify_mode => SSL_VERIFY_NONE,
) or die ref($self), " $iosocket socket connect failed: $!,$SSL_ERROR";
+ if ($self->{sndbuf}) {
+ setsockopt($cs, SOL_SOCKET, SO_SNDBUF,
+ pack('i', $self->{sndbuf}))
+ or die ref($self), " set sndbuf listen failed: $!";
+ }
+ if ($self->{rcvbuf}) {
+ setsockopt($cs, SOL_SOCKET, SO_RCVBUF,
+ pack('i', $self->{rcvbuf}))
+ or die ref($self), " set rcvbuf listen failed: $!";
+ }
+ if ($self->{sndtimeo}) {
+ setsockopt($cs, SOL_SOCKET, SO_SNDTIMEO,
+ pack('l!l!', $self->{sndtimeo}, 0))
+ or die ref($self), " set SO_SNDTIMEO failed failed: $!";
+ }
+ if ($self->{rcvtimeo}) {
+ setsockopt($cs, SOL_SOCKET, SO_RCVTIMEO,
+ pack('l!l!', $self->{rcvtimeo}, 0))
+ or die ref($self), " set SO_RCVTIMEO failed failed: $!";
+ }
+
print STDERR "connect sock: ",$cs->sockhost()," ",$cs->sockport(),"\n";
print STDERR "connect peer: ",$cs->peerhost()," ",$cs->peerport(),"\n";
if ($self->{ssl}) {
diff --git a/regress/usr.sbin/relayd/Server.pm b/regress/usr.sbin/relayd/Server.pm
index 0ab32b7e5e2..6c403dbc36b 100644
--- a/regress/usr.sbin/relayd/Server.pm
+++ b/regress/usr.sbin/relayd/Server.pm
@@ -1,4 +1,4 @@
-# $OpenBSD: Server.pm,v 1.8 2015/05/22 19:09:18 bluhm Exp $
+# $OpenBSD: Server.pm,v 1.9 2015/07/18 22:11:34 benno Exp $
# Copyright (c) 2010-2015 Alexander Bluhm <bluhm@openbsd.org>
#
@@ -47,6 +47,26 @@ sub new {
SSL_cert_file => "server.crt",
SSL_verify_mode => SSL_VERIFY_NONE,
) or die ref($self), " $iosocket socket listen failed: $!,$SSL_ERROR";
+ if ($self->{sndbuf}) {
+ setsockopt($ls, SOL_SOCKET, SO_SNDBUF,
+ pack('i', $self->{sndbuf}))
+ or die ref($self), " set sndbuf SO_SNDBUF failed: $!";
+ }
+ if ($self->{rcvbuf}) {
+ setsockopt($ls, SOL_SOCKET, SO_RCVBUF,
+ pack('i', $self->{rcvbuf}))
+ or die ref($self), " set rcvbuf SO_RCVBUF failed: $!";
+ }
+ if ($self->{sndtimeo}) {
+ setsockopt($ls, SOL_SOCKET, SO_SNDTIMEO,
+ pack('l!l!', $self->{sndtimeo}, 0))
+ or die ref($self), " set SO_SNDTIMEO failed failed: $!";
+ }
+ if ($self->{rcvtimeo}) {
+ setsockopt($ls, SOL_SOCKET, SO_RCVTIMEO,
+ pack('l!l!', $self->{rcvtimeo}, 0))
+ or die ref($self), " set SO_RCVTIMEO failed failed: $!";
+ }
my $log = $self->{log};
print $log "listen sock: ",$ls->sockhost()," ",$ls->sockport(),"\n";
$self->{listenaddr} = $ls->sockhost() unless $self->{listenaddr};
diff --git a/regress/usr.sbin/relayd/args-http-slow-consumer.pl b/regress/usr.sbin/relayd/args-http-slow-consumer.pl
new file mode 100644
index 00000000000..d411894c3d8
--- /dev/null
+++ b/regress/usr.sbin/relayd/args-http-slow-consumer.pl
@@ -0,0 +1,42 @@
+# test that a slow (in this case sleeping) client causes relayd to slow down
+# reading from the server (instead of balooning its buffers)
+
+use strict;
+use warnings;
+
+my $size = 2**21;
+
+our %args = (
+ client => {
+ fast => 1,
+ max => 100,
+ func => sub {
+ http_request(@_, $size, "1.0", "");
+ http_response(@_, $size);
+ print STDERR "going to sleep\n";
+ sleep 8;
+ read_char(@_, $size);
+ return;
+ },
+ rcvbuf => 2**8,
+ nocheck => 1,
+ },
+ relayd => {
+ protocol => [ "http",
+ "tcp socket buffer 64",
+ "match request header log",
+ "match request path log",
+ ],
+ },
+ server => {
+ fast => 1,
+ func => \&http_server,
+ sndbuf => 2**8,
+ sndtimeo => 2,
+ loggrep => 'short write',
+
+ },
+ lengths => [$size],
+);
+
+1;
diff --git a/regress/usr.sbin/relayd/funcs.pl b/regress/usr.sbin/relayd/funcs.pl
index bd86178098d..ea07527df89 100644
--- a/regress/usr.sbin/relayd/funcs.pl
+++ b/regress/usr.sbin/relayd/funcs.pl
@@ -1,4 +1,4 @@
-# $OpenBSD: funcs.pl,v 1.19 2015/05/17 22:49:03 bluhm Exp $
+# $OpenBSD: funcs.pl,v 1.20 2015/07/18 22:11:34 benno Exp $
# Copyright (c) 2010-2015 Alexander Bluhm <bluhm@openbsd.org>
#
@@ -48,11 +48,67 @@ sub find_ports {
# Client funcs
########################################################################
+sub write_syswrite {
+ my $self = shift;
+ my $buf = shift;
+ my $len = 0;
+ my $size = length($buf);
+ my $r = 0;
+
+ while ($len < $size) {
+ while (($r = syswrite(STDOUT, $buf, $size, $len))) {
+ $len += $r;
+ if ($r != $size) {
+ print STDERR "short write (only $r bytes)\n";
+ }
+ }
+ if ($len != $size) {
+ print STDERR "short write ($!)\n";
+ }
+ }
+ return $len;
+}
+
+sub write_blocks {
+ my $self = shift;
+ my $len = shift;
+
+ my $data;
+ my $outb = 0;
+ my $blocks = int($len / 1000);
+ my $rest = $len % 1000;
+
+ for (my $i = 1; $i <= 100 ; $i++) {
+ $data .= '012345678'."\n";
+ }
+
+ for (my $i = 1; $i <= $blocks; $i++) {
+ $outb += write_syswrite($self,$data);
+ print STDERR ".";
+ }
+
+ if ($rest>0) {
+ for (my $i = 1; $i < $rest-1 ; $i++) {
+ $outb += write_syswrite($self,'r');
+ print STDERR ".";
+ }
+ }
+ print STDERR "\n";
+ $outb += write_syswrite($self,"\n\n");
+ IO::Handle::flush(\*STDOUT);
+ print STDERR "LEN: ", $outb, "\n";
+}
+
sub write_char {
my $self = shift;
my $len = shift // $self->{len} // 251;
my $sleep = $self->{sleep};
+ if ($self->{fast}) {
+ write_blocks($self,$len);
+ return;
+ }
+
my $ctx = Digest::MD5->new();
my $char = '0';
for (my $i = 1; $i < $len; $i++) {
@@ -274,10 +330,43 @@ sub errignore {
# Server funcs
########################################################################
+sub read_char_fast {
+ my $self = shift;
+ my $max = shift // $self->{max};
+
+ my $ctx = Digest::MD5->new();
+ my $len = 0;
+ if (defined($max) && $max == 0) {
+ print STDERR "Max\n";
+ } else {
+ while ((my $r = sysread(STDIN, my $buf, POSIX::BUFSIZ))) {
+ my $pct;
+ $_ = $buf;
+ $len += $r;
+ $ctx->add($_);
+ $pct = ($len / $max) * 100.0;
+ printf(STDERR "%.2f%%\n", $pct);
+ if (defined($max) && $len >= $max) {
+ print STDERR "\nMax";
+ last;
+ }
+ }
+ print STDERR "\n";
+ }
+
+ print STDERR "LEN: ", $len, "\n";
+ print STDERR "MD5: ", $ctx->hexdigest, "\n";
+}
+
sub read_char {
my $self = shift;
my $max = shift // $self->{max};
+ if ($self->{fast}) {
+ read_char_fast($self,$max);
+ return;
+ }
+
my $ctx = Digest::MD5->new();
my $len = 0;
if (defined($max) && $max == 0) {