Compare commits

..

1 Commits

Author SHA1 Message Date
Aleks-Daniel Jakimenko
eb0f3e9908 We should not be relying on real time at all.
Here are some attempts to go into that direction
2015-07-22 14:07:50 +03:00
2 changed files with 16 additions and 18 deletions

View File

@@ -14,9 +14,17 @@
require 't/test.pl';
package OddMuse;
use Test::More tests => 19;
use Test::More tests => 17;
AppendStringToFile($ConfigFile, "\$SurgeProtection = 1;\n");
# TODO move that to test.pl?
# we will be using the same fake time in these tests as well
BEGIN {
sub updateFakeTime { utime($_[0], $_[0], "$DataDir/ts") }
*CORE::GLOBAL::sleep = sub { updateFakeTime((stat("$DataDir/ts"))[9] + $_[0]) };
*CORE::GLOBAL::time = sub { (stat("$DataDir/ts"))[9] };
}
# AppendStringToFile($ConfigFile, "\$SurgeProtection = 1;\n"); # why are we enabling it?
$localhost = 'confusibombus';
$ENV{'REMOTE_ADDR'} = $localhost;
my $lock = $LockDir . 'visitors';
@@ -33,7 +41,7 @@ ok(open(F, '>', $lock), "create bogus ${LockDir}visitors");
my $ts = time - 120;
utime($ts, $ts, $lock); # change mtime of the lockfile
# Getting a time will now time out because no visitor lock can ge aquired.
# Getting a time will now time out because no visitor lock can be acquired.
$ts = time;
get_page('fail-to-get-lock');

View File

@@ -330,26 +330,16 @@ sub write_config_file {
}
sub write_modified_wiki {
my $preamble = <<EOT;
my $preamble = <<'EOT';
BEGIN {
my \$delta = 0;
*CORE::GLOBAL::sleep = sub {
\$delta += shift;
my \$ts = time + \$delta;
utime(\$ts, \$ts, "$DataDir/ts")
};
sub newtime {
return time + \$delta;
};
*CORE::GLOBAL::time = \&newtime;
sub updateFakeTime { utime($_[0], $_[0], "$DataDir/ts") }
*CORE::GLOBAL::sleep = sub { updateFakeTime((stat("$DataDir/ts"))[9] + $_[0]) };
*CORE::GLOBAL::time = sub { (stat("$DataDir/ts"))[9] };
}
EOT
WriteStringToFile("$DataDir/test-wiki.pl", $preamble . ReadFileOrDie('wiki.pl'));
WriteStringToFile("$DataDir/ts", '');
}