Skip to content

Commit

Permalink
Allow to define parallel-limit option to run command (fixes #210)
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraM committed Oct 26, 2018
1 parent ed5ca33 commit 09b2702
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## Unreleased
### Added
- Detect readiness state of new Selenium servers (v3.5.3+ running in W3C-protocol mode) during startup, so that eg. no available Selenium server nodes are reported before attempting to start any test.
- `--parallel-limit` (`-l`) option of `run` command to allow limiting maximum number of tests being run simultaneously.

### Changed
- Require PHP 7.1+ and Symfony 4 components.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ There is also a bunch of useful options for the `run` command:
- `--server-url` - set different url of selenium server than the default (which is `http://localhost:4444/wd/hub`)
- `--xdebug` - start Xdebug debugger on your tests. Allows you to debug tests from your IDE ([learn more about tests debugging][wiki-debugging] in our Wiki)
- `--capability` - directly pass any extra capability to the Selenium WebDriver server ([see wiki][wiki-capabilities] for more information and examples)
- `--parallel-limit` - limit number of testcases being executed in a parallel (default is 50)
- `--help` - see all other options and default values
- **adjust output levels:** by default, only the test results summary is printed to the output; the verbosity could be changed by the following:
- `-v` - to instantly output name of failed test(s)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Browser: chrome
Environment: staging
Path to logs: %s/logs
Ignore delays: no
Parallel limit: 50
Selenium server (hub) url: %s, trying connection...OK
Searching for testcases:
- in directory %s/src-tests/Console/Command/Fixtures/FailingTests"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Browser: chrome
Environment: staging
Path to logs: %s/logs
Ignore delays: no
Parallel limit: 50
Selenium server (hub) url: %s, trying connection...OK
Searching for testcases:
- in directory "%s/src-tests/Console/Command/Fixtures/SimpleTests"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Browser: chrome
Environment: staging
Path to logs: %s/logs
Ignore delays: no
Parallel limit: 50
Selenium server (hub) url: %s, trying connection...OK
Searching for testcases:
- in directory "%s/src-tests/Console/Command/Fixtures/SimpleTests"
Expand Down
22 changes: 21 additions & 1 deletion src/Console/Command/RunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class RunCommand extends Command
public const OPTION_FILTER = 'filter';
public const OPTION_NO_EXIT = 'no-exit';
public const OPTION_IGNORE_DELAYS = 'ignore-delays';
public const OPTION_PARALLEL_LIMIT = 'parallel-limit';

/**
* @internal
Expand Down Expand Up @@ -148,6 +149,13 @@ protected function configure(): void
'i',
InputOption::VALUE_NONE,
'Ignore delays defined between testcases'
)
->addOption(
self::OPTION_PARALLEL_LIMIT,
'l',
InputOption::VALUE_REQUIRED,
'Number of maximum testcases being executed in a parallel',
50
);

$this->addUsage('staging firefox');
Expand Down Expand Up @@ -204,6 +212,13 @@ protected function initialize(InputInterface $input, OutputInterface $output): v
$seleniumAdapter = $this->getSeleniumAdapter($input->getOption(self::OPTION_SERVER_URL));
$input->setOption(self::OPTION_SERVER_URL, $seleniumAdapter->getServerUrl());

// Make sure parallel-limit is greater than 0
$parallelLimit = (int) $input->getOption(self::OPTION_PARALLEL_LIMIT);
if ($parallelLimit === 0) {
throw new \RuntimeException('Parallel limit must be a whole number greater than 0');
}
$input->setOption(self::OPTION_PARALLEL_LIMIT, $parallelLimit);

$this->getDispatcher()->dispatch(
CommandEvents::RUN_TESTS_INIT,
new ExtendedConsoleEvent($this, $input, $output)
Expand All @@ -216,6 +231,9 @@ protected function initialize(InputInterface $input, OutputInterface $output): v
$output->writeln(
sprintf('Ignore delays: %s', ($input->getOption(self::OPTION_IGNORE_DELAYS)) ? 'yes' : 'no')
);
$output->writeln(
sprintf('Parallel limit: %d', $input->getOption(self::OPTION_PARALLEL_LIMIT))
);
}
}

Expand Down Expand Up @@ -263,7 +281,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 1;
}

$executionLoop = new ExecutionLoop($processSet, $this->io, new MaxTotalDelayStrategy());
$maxParallelLimit = $input->getOption(self::OPTION_PARALLEL_LIMIT);

$executionLoop = new ExecutionLoop($processSet, $this->io, new MaxTotalDelayStrategy(), $maxParallelLimit);

$allTestsPassed = $executionLoop->start();

Expand Down

0 comments on commit 09b2702

Please sign in to comment.