1e24691dcSbluhm# The client writes 300 long messages to UDP socket.
2e24691dcSbluhm# The syslogd writes it into a file and through a pipe.
3e24691dcSbluhm# The syslogd does a TCP reconnect and passes it to loghost.
4e24691dcSbluhm# The server blocks the message on its TCP socket.
5e24691dcSbluhm# The server waits until the client has written all messages.
6e24691dcSbluhm# The server closes the TCP connection and accepts a new one.
7e24691dcSbluhm# The server receives the messages on its new accepted TCP socket.
8e24691dcSbluhm# This way the server receives a block of messages that is truncated
9e24691dcSbluhm# at the beginning and at the end.
10e24691dcSbluhm# Find the message in client, file, pipe, syslogd, server log.
11e24691dcSbluhm# Check that the server does not get lines that are cut in the middle.
12e24691dcSbluhm
13e24691dcSbluhmuse strict;
14e24691dcSbluhmuse warnings;
15e24691dcSbluhmuse Socket;
16e24691dcSbluhm
17e24691dcSbluhmour %args = (
18e24691dcSbluhm    client => {
19e24691dcSbluhm	connect => { domain => AF_UNSPEC, addr => "localhost", port => 514 },
20e24691dcSbluhm	func => sub { write_between2logs(shift, sub {
21e24691dcSbluhm	    my $self = shift;
22e24691dcSbluhm	    write_message($self, get_secondlog());
23ac8221f6Sbluhm	    write_lines($self, 300, 2000);
24e24691dcSbluhm	    write_message($self, get_thirdlog());
25e24691dcSbluhm	    ${$self->{server}}->loggrep("Accepted", 5, 2)
26ab4b416dSbluhm		or die ref($self), " server did not accept second connection";
278579df47Sbluhm	    ${$self->{syslogd}}->loggrep(qr/: dropped \d+ messages? to/, 5)
28ab4b416dSbluhm		or die ref($self), " syslogd did not write dropped message";
29e24691dcSbluhm	})},
30e24691dcSbluhm    },
31e24691dcSbluhm    syslogd => {
32e24691dcSbluhm	options => ["-u"],
33e24691dcSbluhm	loghost => '@tcp://127.0.0.1:$connectport',
34e24691dcSbluhm	loggrep => {
35e24691dcSbluhm	    get_between2loggrep(),
36e24691dcSbluhm	    get_charlog() => 300,
3774a2653fSbluhm	    qr/loghost .* dropped partial message/ => 1,
38e24691dcSbluhm	},
39e24691dcSbluhm    },
40e24691dcSbluhm    server => {
41e24691dcSbluhm	listen => { domain => AF_INET, proto => "tcp", addr => "127.0.0.1" },
4291c6fcb1Sbluhm	rcvbuf => 2**12,
43be4712f2Sbluhm	func => sub { accept_between2logs(shift, sub {
44e24691dcSbluhm	    my $self = shift;
45f7c838b2Sbluhm	    # read slowly to get output buffer out of sync
46f7c838b2Sbluhm	    foreach (1..10) {
47f7c838b2Sbluhm		print STDERR ">>> ". scalar <STDIN>;
48f7c838b2Sbluhm		sleep 1;
49f7c838b2Sbluhm		last if ${$self->{syslogd}}->loggrep(get_thirdlog());
50f7c838b2Sbluhm	    }
51f7c838b2Sbluhm	    ${$self->{syslogd}}->loggrep(get_thirdlog(), 30)
52268e7dafSbluhm		or die ref($self), " syslogd did not receive third log";
53e24691dcSbluhm	    shutdown(\*STDOUT, 1)
544dc3bc25Sbluhm		or die ref($self), " shutdown write failed: $!";
55e24691dcSbluhm	})},
56e24691dcSbluhm	loggrep => {
57*a96642fbSanton	    qr/^Accepted$/ => 2,
58e24691dcSbluhm	    get_between2loggrep(),
59e24691dcSbluhm	    get_thirdlog() => 0,
60e24691dcSbluhm	},
61e24691dcSbluhm    },
62e24691dcSbluhm    file => {
63e24691dcSbluhm	loggrep => {
64e24691dcSbluhm	    get_between2loggrep(),
65e24691dcSbluhm	    get_secondlog() => 1,
66e24691dcSbluhm	    get_thirdlog() => 1,
67e24691dcSbluhm	    get_charlog() => 300,
68e24691dcSbluhm	},
69e24691dcSbluhm    },
70e24691dcSbluhm);
71e24691dcSbluhm
72e24691dcSbluhm1;
73