Skip to content

Commit

Permalink
Update ThrottleTest to accept $tokenTime of value 1 or greater.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammed Karim committed Jun 24, 2019
1 parent 50fbc8a commit 1eac5c1
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions tests/system/Throttle/ThrottleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,19 @@ public function testTokenTime()
{
$throttler = new Throttler($this->cache);

// token time should be zero to start
// tokenTime should be 0 to start
$this->assertEquals(0, $throttler->getTokenTime());

// as soon as we try a rate check, token time affected
$rate = 1; // allow 1 per minute
$cost = 1;
// set $rate
$rate = 1; // allow 1 request per minute

// after using one slot, still good
$throttler->check('127.0.0.1', $rate, MINUTE, $cost);
// first check just creates a bucket, so tokenTime should be 0
$throttler->check('127.0.0.1', $rate, MINUTE);
$this->assertEquals(0, $throttler->getTokenTime());

// after consuming a second, we have to wait
$throttler->check('127.0.0.1', $rate, MINUTE, $cost);
$this->assertEquals(1, $throttler->getTokenTime());
// additional check affects tokenTime, so tokenTime should be 1 or greater
$throttler->check('127.0.0.1', $rate, MINUTE);
$this->assertGreaterThanOrEqual(1, $throttler->getTokenTime());
}

public function testIPSavesBucket()
Expand Down

0 comments on commit 1eac5c1

Please sign in to comment.