args-sync-tcp.pl revision 1.9
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/syslogd: dropped \d+ messages?/, 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 redo => 0, 44 func => sub { read_between2logs(shift, sub { 45 my $self = shift; 46 if ($self->{redo}) { 47 $self->{redo}--; 48 return; 49 } 50 # read slowly to get output buffer out of sync 51 foreach (1..10) { 52 print STDERR ">>> ". scalar <STDIN>; 53 sleep 1; 54 last if ${$self->{syslogd}}->loggrep(get_thirdlog()); 55 } 56 ${$self->{syslogd}}->loggrep(get_thirdlog(), 30) 57 or die ref($self), " syslogd did not receive third log"; 58 shutdown(\*STDOUT, 1) 59 or die "shutdown write failed: $!"; 60 $self->{redo}++; 61 })}, 62 loggrep => { 63 qr/Accepted/ => 2, 64 get_between2loggrep(), 65 get_thirdlog() => 0, 66 }, 67 }, 68 file => { 69 loggrep => { 70 get_between2loggrep(), 71 get_secondlog() => 1, 72 get_thirdlog() => 1, 73 get_charlog() => 300, 74 }, 75 }, 76); 77 781; 79