public function testThrottleWithSlaveLag() { $this->storage->expects($this->any())->method('getSecondsBehind')->will($this->returnValue(500)); $usleep = $this->getFunctionMock('\\Phlib\\Db', 'usleep'); $usleep->expects($this->once())->with($this->greaterThan(0)); $slave = $this->getMock(AdapterInterface::class); (new Replication($this->master, [$slave], $this->storage))->throttle(); }
/** * Throttle * * Updates the stored load value if out-of-date, and sleeps for the required * time if throttling is enabled. * * @return $this */ public function throttle() { $currentInterval = time() - $this->loadUpdated; if ($currentInterval > $this->updateInterval) { $this->loadValue = (int) $this->storage->getSecondsBehind($this->host); $this->loadUpdated = time(); } $this->sleep(); return $this; }