21 my @opt = <<'=back' =~ /B<--(\S+)>/g;
25 Defaults to true. Negate with --nocleanup. If true, all generated
26 files are removed at the end of the test run.
34 Defaults to 0.2. Seconds to sleep between the cration of the initial
39 Defaults to 0.1. Seconds to sleep between the iterations of the second
42 =item B<--iterations=i>
44 Defaults to 30. Number of iterations in the second phase.
50 In the first phase the test creates a couple of files and injects them
51 into the tree, one after the other. There are tunable C<sleep1> pauses
52 between each file creation. In the second phase the test runs
53 alternating C<aggregate> commands on the server and C<rmirror>
54 commands on the client. After each iteration both directories are
55 checksummed and stored in a separate yaml file for later inspection.
57 If you want to inspect the yaml files, be sure to set --nocleanup.
59 =head2 Interpretation of the output
61 Output may look like this:
63 # 17.1575 new state reached in t/serv-5c59696a590715c20f2b7f55c281c667.yaml
64 # 18.0686 new state reached in t/mirr-b9b903e62f31249d2d5836eede1d0420.yaml
65 # 19.2339 new state reached in t/serv-9a9df7f3c8d2fc501c27490696ba1c88.yaml
66 # 33.2662 new state reached in t/serv-7ad22e96a3ecf527e1fa934425ec7516.yaml
67 # 55.2330 new state reached in t/serv-ce628a7ee14eb32054f6744ab9772b2c.yaml
69 This means that the RECENT files on the server have changed 4 times
70 due to calls to C<aggregate> but the RECENT files on the mirror have
77 use lib
"$FindBin::Bin/../lib";
83 use Hash
::Util
qw(lock_keys);
86 lock_keys
%Opt, map { /([^=!]+)/ } @opt;
91 $Opt{cleanup
} = 1 unless defined $Opt{cleanup
};
92 $Opt{sleep1
} = 0.2 unless defined $Opt{sleep1
};
93 $Opt{sleep2
} = 0.1 unless defined $Opt{sleep2
};
94 $Opt{iterations
} = 30 unless defined $Opt{iterations
};
97 use File
::Basename
qw(dirname);
99 use File
::Path
qw(mkpath rmtree);
100 use Time
::HiRes
qw(time sleep);
101 $^T
= time; # force it to float
112 my $root_from = "t/serv";
113 my $root_to = "t/mirr";
114 my $statusfile = "t/recent-rmirror-state.yml";
115 my @unlink = map { "t/$_-ttt.yaml" } qw(serv mirr);
116 rmtree
[$root_from, $root_to];
141 @intervals = qw( 2s 3s 5s 8s 13s 21s 34s 55s Z );
144 my $rf0 = File
::Rsync
::Mirror
::Recentfile
->new
146 aggregator
=> [@intervals[1..$#intervals]],
147 interval
=> $intervals[0],
148 localroot
=> $root_from,
160 my $rrr = File
::Rsync
::Mirror
::Recent
->new
162 ignore_link_stat_errors
=> 1,
163 localroot
=> $root_to,
164 remote
=> "$root_from/RECENT.recent",
169 # not available in rsync 3.0.3: 'omit-dir-times' => 1,
171 'temp-dir' => "$cwd/t/tmp",
174 my $latest_timestamp = 0;
176 for my $r ($root_from,$root_to) {
178 my $tfile = "$r-ttt.yaml";
179 my $ctx = Digest
::MD5
->new;
186 my $content = do { open my $fh, $File::Find
::name
or die "Could not open '$File::Find::name': $!"; local $/; <$fh>};
187 $y->{substr($File::Find
::name
,1+length($r))} = $content;
194 YAML
::Syck
::DumpFile
$tfile, $y;
195 my @stat = stat $tfile;
196 if ($stat[9] == $latest_timestamp) {
197 # for a better overview over the results, never
198 # let two timestamps be the same
201 $latest_timestamp = $stat[9];
205 open my $fh, $tfile or die $!;
207 my $digest = $ctx->hexdigest;
208 my $pfile = "$r-$digest.yaml";
210 my $t = sprintf "%6.4f", time - $^T
;
211 diag
"$t new state reached in $pfile";
212 rename $tfile, $pfile or die $!;
213 push @unlink, $pfile;
217 my($file, $message) = @_;
218 my $t = sprintf "%6.4f", time - $^T
;
219 mkpath dirname
$file;
220 open my $fh, ">", $file or die "Could not open '$file': $!";
221 print $fh "$message\n";
222 $rf0->update($file,"new");
228 for my $i (0..$#cast) {
229 my $actor = $cast[$i];
230 my $file = sprintf "%s/%02d%s", $root_from, $i, $actor;
231 my $message = "$actor $event";
233 sleep $Opt{"sleep1"};
236 # speeding up the process a little bit:
237 superevent
("sleeping");
238 my $rfs = $rrr->recentfiles;
240 $rf->sleep_per_connection(0);
242 $rrr->_rmirror_sleep_per_connection(0.001);
243 for (my $t=0; $t < $Opt{iterations
}; $t++) {
253 rmtree
[$root_from, $root_to, "t/tmp"];
258 if ($ENV{AUTHOR_TEST
}) {
261 plan
( skip_all
=> "test is a tunable author test, set envariable AUTHOR_TEST and tune it" );
262 eval "require POSIX; 1" and POSIX
::_exit
(0);
268 use File
::Rsync
::Mirror
::Recent
;
269 use File
::Rsync
::Mirror
::Recentfile
;
273 # cperl-indent-level: 4