args-client-tcp-deferred.pl revision 1.2
1# The syslogd listens on 127.0.0.1 TCP socket.
2# The client creates connections to syslogd TCP socket until it blocks.
3# The client writes to all sockets and closes them.
4# Wait until syslogd has slots to accept all sockets.
5# Find the message in client, file, pipe, syslogd, server log.
6# Check the messages end up in the log file.
7
8use strict;
9use warnings;
10use IO::Socket::INET6;
11
12our %args = (
13    client => {
14	connect => { domain => AF_INET, proto => "tcp", addr => "127.0.0.1",
15	    port => 514 },
16	func => sub {
17	    my $self = shift;
18	    local $| = 1;
19	    my @s;
20	    $s[0] = \*STDOUT;
21	    # open additional connections until syslogd deferres
22	    for (my $i = 1; $i <= 30; $i++) {
23		$s[$i] = IO::Socket::INET6->new(
24		    Domain              => AF_INET,
25		    Proto               => "tcp",
26		    PeerAddr            => "127.0.0.1",
27		    PeerPort            => 514,
28		) or die ref($self), " id $i tcp socket connect failed: $!";
29		print STDERR "<<< id $i tcp connected\n";
30		${$self->{syslogd}}->loggrep("tcp logger .* accepted", 1, $i);
31		${$self->{syslogd}}->loggrep("accept deferred")
32		    and last;
33	    }
34	    write_tcp($self, \*STDOUT, 0);
35	    for (my $i = 1; $i < @s; $i++) {
36		my $fh = $s[$i];
37		write_tcp($self, $fh, $i);
38		# close connection so that others can be accepted
39		close($fh);
40	    }
41	    ${$self->{syslogd}}->loggrep(qr/tcp logger .* use \d+ bytes/, 10,
42		scalar @s)
43		or die ref($self), " syslogd did not use connections";
44	    write_shutdown($self);
45	},
46    },
47    syslogd => {
48	options => ["-T", "127.0.0.1:514"],
49	rlimit => {
50	    RLIMIT_NOFILE => 30,
51	},
52	loggrep => {
53	    qr/tcp logger .* accepted/ => '>=10',
54	    qr/tcp logger .* use \d+ bytes/ => '>=10',
55	    qr/tcp logger .* connection close/ => '>=10',
56	},
57    },
58    file => {
59	loggrep => {
60	    get_testgrep() => '>=10',
61	},
62    },
63);
64
651;
66