Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SmetDenis committed Nov 12, 2021
1 parent 88f9195 commit c05585a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
32 changes: 31 additions & 1 deletion tests/Cli/CliMultiProcessTest.php
Expand Up @@ -49,6 +49,7 @@ public function testAsRealExecution()
"Started: 4\n{$expectecContent}\nFinished: 4",
"Started: 5\n{$expectecContent}\nFinished: 5",
], $outputAsArray);
isSame('', $result[2]);

isTrue($time < 5, "Total time: {$time}");
}
Expand Down Expand Up @@ -77,6 +78,35 @@ public function testAsVirtalExecution()
"Started: 5\n{$expectecContent}\nFinished: 5",
], $outputAsArray);

isTrue($time < 5);
isTrue($time < 5, "Total time: {$time}");
}

public function testException()
{
$start = microtime(true);
$result = Helper::executeReal('test:sleep-multi 123 456 789', ['sleep' => 2]);
$time = microtime(true) - $start;

$outputAsArray = json($result[1])->getArrayCopy();

$expectecContent = implode("\n", [
'Sleep : 2',
'Arg #1: 123',
'Arg #2: 456',
'Arg #3: 789',
'Env Var: ',
]);

isSame([
"Started: 1\n{$expectecContent}\nFinished: 1",
"",
"Started: 3\n{$expectecContent}\nFinished: 3",
"Started: 4\n{$expectecContent}\nFinished: 4",
"Started: 5\n{$expectecContent}\nFinished: 5",
], $outputAsArray);
isContain('Exception messsage', $result[2]);


isTrue($time < 5, "Total time: {$time}");
}
}
2 changes: 1 addition & 1 deletion tests/Cli/CliProgressTest.php
Expand Up @@ -46,7 +46,7 @@ public function testMinimal()

public function testMinimalVirtual()
{
$output = Helper::executeVirtaul('test:progress', ['case' => 'one-message']);
$output = Helper::executeVirtaul('test:progress', ['case' => 'one-message', 'ansi' => null]);
isContain('Progress of one-message', $output);
isContain('Last Step Message: 1, 1, 1', $output);

Expand Down
6 changes: 6 additions & 0 deletions tests/fake-app/Commands/TestSleepMulti.php
Expand Up @@ -18,6 +18,7 @@
namespace JBZoo\TestApp\Commands;

use JBZoo\Cli\CliCommandMultiProc;
use JBZoo\Cli\Exception;
use JBZoo\Utils\Env;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -50,6 +51,11 @@ protected function configure(): void
*/
protected function executeOneProcessAction(string $pmThreadId): int
{
$sleep = $this->getOptString('sleep');
if ($sleep === '2' && $pmThreadId === '2') {
throw new Exception('Exception messsage');
}

$this->_([
"Started: {$pmThreadId}",
'Sleep : ' . $this->getOptString('sleep'),
Expand Down

0 comments on commit c05585a

Please sign in to comment.