Skip to content
Snippets Groups Projects
Commit db8be604 authored by Matthew Laird's avatar Matthew Laird
Browse files

Change Retry-After resolution to round up to the nearest second, accuracy on...

Change Retry-After resolution to round up to the nearest second, accuracy on some platforms is not sufficient for this to work reliably on some tests. Also, sub-second resolution for a header like this just doesn't feel very HTTPy.
Remove the skip for the ratelimit test in travis
parent 689d2343
No related branches found
No related tags found
No related merge requests found
......@@ -248,6 +248,9 @@ sub _add_throttle_headers {
Plack::Util::header_set( $headers, 'X-RateLimit-Remaining', $remaining_requests );
if($retry_after) {
my $retry_after_addition = $self->retry_after_addition() || $RETRY_AFTER_ADDITION;
# Do a ceiling on the reset time to give second resolution, going so high resolution
# in exact reset times causes potential breakage depending on the platform's timer resolution
$reset_time = ($reset_time == int $reset_time) ? $reset_time : int($reset_time + 1);
Plack::Util::header_set( $headers, 'Retry-After', $reset_time+$retry_after_addition );
}
return $res;
......@@ -290,4 +293,4 @@ sub _populate_cidr {
return $cidr;
}
1;
\ No newline at end of file
1;
......@@ -108,7 +108,7 @@ assert_basic_rate_limit('EnsThrottle::Second', 1, 'second', 'You have done too m
cmp_ok($res->header('X-RateLimit-Remaining'), '==', 0, 'Remaining header is 0');
$res = $cb->(GET '/');
is($res->code(), 429, 'Checking for a 429 (more than 1 request per second I hope)');
cmp_ok($res->header('Retry-After'), '<', 1.0, 'Retry-After header must be less than a second');
cmp_ok($res->header('Retry-After'), '<=', 1.0, 'Retry-After header must be less than or equal to a second');
cmp_ok($res->header('Retry-After'), '>', 0, 'Retry-After header must be greater than zero seconds');
cmp_ok($res->header('X-RateLimit-Limit'), '==', 1, 'Limit header must be set to 1');
cmp_ok($res->header('X-RateLimit-Reset'), '<', 1.0, 'Reset header must be less than a second');
......@@ -297,4 +297,4 @@ sub assert_basic_rate_limit {
return;
}
done_testing();
\ No newline at end of file
done_testing();
......@@ -3,7 +3,7 @@
export PERL5LIB=$PWD/bioperl-live-bioperl-release-1-2-3:$PWD/ensembl-test/modules:$PWD/ensembl/modules:$PWD/ensembl-compara/modules:$PWD/ensembl-variation/modules:$PWD/ensembl-funcgen/modules:$PWD/ensembl-io/modules:$PWD/lib
export PATH=$PATH:$PWD/tabix:$PWD/ensembl-variation/C_code
export SKIP_TESTS="--skip $PWD/t/ratelimit.t"
export SKIP_TESTS=""
echo "Running test suite"
if [ "$COVERALLS" = 'true' ]; then
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment