Skip to content

Commit

Permalink
- feat: add callback to get worker info
Browse files Browse the repository at this point in the history
  • Loading branch information
kaleta committed Feb 21, 2024
1 parent 35697bf commit 3f8f866
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/WorkerPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,17 @@ public function addWorker(string $plugin): void
*/
public function countWorkers(string $plugin): int
{
return (int)($this->rpc->call('informer.Workers', $plugin)['workers'] ?? 0);
return count($this->getWorkers($plugin));
}

/**
* Get the info about running workers for a pool.
*
* @param non-empty-string $plugin
*/
public function getWorkers(string $plugin): array
{
return $this->rpc->call('informer.Workers', $plugin)['workers'];
}

/**
Expand Down
9 changes: 8 additions & 1 deletion tests/Unit/WorkerPoolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,18 @@ public function testAddWorker(): void

public function testCountWorkers(): void
{
$this->rpc->expects($this->once())->method('call')->with('informer.Workers', 'test');
$this->rpc->expects($this->once())->method('call')->with('informer.Workers', 'test')->willReturn(['workers' => []]);

$this->workerPool->countWorkers('test');
}

public function testGetWorkers(): void
{
$this->rpc->expects($this->once())->method('call')->with('informer.Workers', 'test')->willReturn(['workers' => []]);

$this->workerPool->getWorkers('test');
}

public function testRemoveWorker(): void
{
$this->rpc->expects($this->once())->method('call')->with('informer.RemoveWorker', 'test');
Expand Down

0 comments on commit 3f8f866

Please sign in to comment.