return self::LOCK_TIMEOUT_SEC;
}
+ protected function getLockRetrySleepUs(): int
+ {
+ return 500000; // 0.5 sec
+ }
+
private function acquireLock(): void
{
$deadline = time() + $this->getLockTimeoutSec();
+ $sleepUs = $this->getLockRetrySleepUs();
while (time() < $deadline) {
$locked = $this->db->createCommand()
return;
}
- usleep(500000); // 0.5 sec
+ usleep($sleepUs);
}
$msg = 'Failed to acquire advisory lock within ' . $this->getLockTimeoutSec() . ' seconds';
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('advisory lock');
- // Анонимный класс с timeout=1 сек для быстрого теста
+ // Анонимный класс с минимальными таймаутами для быстрого теста
$service = new class($db) extends StockHistoryService {
protected function getLockTimeoutSec(): int { return 1; }
+ protected function getLockRetrySleepUs(): int { return 100000; } // 0.1 sec
};
$service->collect('08:00');
}