Skip to content

Commit

Permalink
Merge pull request #30 from ackintosh/fix-interval-half-open-on-rate-…
Browse files Browse the repository at this point in the history
…strategy

Fix intervalToHalfOpen in Redis storage
  • Loading branch information
ackintosh authored Dec 23, 2018
2 parents ea20203 + ab18588 commit eeee5cd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Ganesha/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,12 @@ private function rejectionKey($service)
*/
private function lastFailureKey($service)
{
return $this->prefix($service) . self::KEY_SUFFIX_LAST_FAILURE_TIME;
return $this->supportRollingTimeWindow()
// If the adapter supports RollingTimeWindow use failureKey() instead,
// because Redis doesn't save lastFailureTime.
// @see Ackintosh\Ganesha\Storage\Adapter\Redis#saveLastFailureTime()
? $this->failureKey($service)
: $this->prefix($service) . self::KEY_SUFFIX_LAST_FAILURE_TIME;
}

/**
Expand Down
19 changes: 19 additions & 0 deletions tests/Ackintosh/Ganesha/StorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use Ackintosh\Ganesha;
use Ackintosh\Ganesha\Storage\Adapter\Memcached;
use Ackintosh\Ganesha\Storage\Adapter\Redis;

class StorageTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -23,4 +24,22 @@ public function savesStatus()
$storage->setStatus($service, Ganesha::STATUS_TRIPPED);
$this->assertSame($storage->getStatus($service), Ganesha::STATUS_TRIPPED);
}

/**
* @test
*/
public function getLastFailureTimeWithRollingTimeWindow()
{
$r = new \Redis();
$r->connect(
getenv('GANESHA_EXAMPLE_REDIS') ? getenv('GANESHA_EXAMPLE_REDIS') : 'localhost'
);
$r->flushAll();
$storage = new Storage(new Redis(($r)), null);

$service = 'test';
$storage->incrementFailureCount($service);

$this->assertNotNull($storage->getLastFailureTime($service));
}
}

0 comments on commit eeee5cd

Please sign in to comment.