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