args-sync-tcp.pl revision 1.5
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 receive second log";
27	    ${$self->{syslogd}}->loggrep(qr/dropped \d+ messages/, 5)
28		or die ref($self), " syslogd did not log dropped messages";
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/dropped partial message/ => 1,
38	},
39    },
40    server => {
41	listen => { domain => AF_INET, proto => "tcp", addr => "127.0.0.1" },
42	redo => 0,
43	func => sub { read_between2logs(shift, sub {
44	    my $self = shift;
45	    if ($self->{redo}) {
46		$self->{redo}--;
47		return;
48	    }
49	    ${$self->{syslogd}}->loggrep(get_thirdlog(), 40)
50		or die ref($self), " syslogd did not receive third log";
51	    shutdown(\*STDOUT, 1)
52		or die "shutdown write failed: $!";
53	    $self->{redo}++;
54	})},
55	loggrep => {
56	    qr/Accepted/ => 2,
57	    get_between2loggrep(),
58	    get_secondlog() => 0,
59	    get_thirdlog() => 0,
60	    qr/>>> [0-9A-Za-z]{10}/ => 0,
61	},
62    },
63    file => {
64	loggrep => {
65	    get_between2loggrep(),
66	    get_secondlog() => 1,
67	    get_thirdlog() => 1,
68	    get_charlog() => 300,
69	},
70    },
71);
72
731;
74