Ejemplo n.º 1
0
 public function returns_immediately_after_having_slept_for_one_second()
 {
     $fixture = new RateLimiting($this->rate, self::$clock);
     $fixture->acquire($this->rate);
     self::$clock->forward(1.0);
     $this->assertDouble(0.0, $fixture->acquire(1));
 }
Ejemplo n.º 2
0
 public function try_acquiring_with_timeout_of_larger_than_unit($unit)
 {
     $fixture = new RateLimiting(new Rate(1, $unit), self::$clock);
     $fixture->acquire();
     $this->assertTrue($fixture->tryAcquiring(1, $unit->seconds() + 0.5));
 }
Ejemplo n.º 3
0
 public function succeeds_trying_to_acquire_one_more_than_permitted_after_longer_timeout($rate)
 {
     $fixture = new RateLimiting($rate, self::$clock);
     $fixture->acquire($rate);
     $this->assertTrue($fixture->tryAcquiring(1, $fixture->rate()->unit()->seconds() + 0.5));
 }
Ejemplo n.º 4
0
 public function increase()
 {
     $fixture = new RateLimiting(self::RATE);
     $fixture->increase(100);
     $this->assertEquals(new Rate(self::RATE + 100, Per::$SECOND), $fixture->rate());
 }