Skip to content

Commit

Permalink
Refactor code have single place for an SVN command Idle timeout chang…
Browse files Browse the repository at this point in the history
…ing (if needed)
  • Loading branch information
aik099 committed Jan 15, 2025
1 parent 7ecc0dd commit 5cdab4a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/SVNBuddy/Repository/Connector/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
class Command
{

const IDLE_TIMEOUT = 180; // 3 minutes.

/**
* Process factory.
*
Expand Down Expand Up @@ -213,7 +215,7 @@ private function _getCacheKey()
*/
private function _doRun($callback = null)
{
$process = $this->_processFactory->createProcess($this->_commandLine, 180); // Idle timeout: 3 minutes.
$process = $this->_processFactory->createProcess($this->_commandLine, self::IDLE_TIMEOUT);
$command_string = (string)$this;

try {
Expand Down
11 changes: 8 additions & 3 deletions tests/SVNBuddy/Repository/Connector/CommandFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use ConsoleHelpers\SVNBuddy\Cache\CacheManager;
use ConsoleHelpers\SVNBuddy\Exception\RepositoryCommandException;
use ConsoleHelpers\SVNBuddy\Process\IProcessFactory;
use ConsoleHelpers\SVNBuddy\Repository\Connector\Command;
use ConsoleHelpers\SVNBuddy\Repository\Connector\CommandFactory;
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
Expand Down Expand Up @@ -73,9 +74,13 @@ protected function setupTest()

// To get nice exception back when unexpected command is executed.
$this->_processFactory
->createProcess(Argument::any(), 180)
->createProcess(Argument::any(), Command::IDLE_TIMEOUT)
->will(function (array $args) {
throw new \LogicException('The createProcess("' . implode(' ', $args[0]) . '", 180) call wasn\'t expected.');
throw new \LogicException(sprintf(
'The createProcess("%s", %s) call wasn\'t expected.',
implode(' ', $args[0]),
Command::IDLE_TIMEOUT
));
});

$this->_commandFactory = $this->_createCommandFactory('', '');
Expand Down Expand Up @@ -176,7 +181,7 @@ private function _expectCommand(array $command, $output, $error_msg = null, $err
$this->_io->isVerbose()->willReturn(false);
$this->_io->isDebug()->willReturn(false);

$this->_processFactory->createProcess($command, 180)->willReturn($process)->shouldBeCalled();
$this->_processFactory->createProcess($command, Command::IDLE_TIMEOUT)->willReturn($process)->shouldBeCalled();
}

/**
Expand Down
4 changes: 3 additions & 1 deletion tests/SVNBuddy/Repository/Connector/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,9 @@ public static function cacheKeyFormingDataProvider()
private function _createCommand(array $command_line, $use_process = true)
{
if ( $use_process ) {
$this->_processFactory->createProcess($command_line, 180)->willReturn($this->_process)->shouldBeCalled();
$this->_processFactory->createProcess($command_line, Command::IDLE_TIMEOUT)
->willReturn($this->_process)
->shouldBeCalled();
}

return new Command(
Expand Down

0 comments on commit 5cdab4a

Please sign in to comment.