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