Skip to content

Commit

Permalink
No need to double tap context close
Browse files Browse the repository at this point in the history
  • Loading branch information
WyriHaximus committed Jan 6, 2025
1 parent b14a920 commit d82b08a
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 93 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"react/async": "^4.3",
"react/event-loop": "^1.5",
"react/promise": "^3.2",
"react/promise-timer": "^1.11",
"roave/better-reflection": "^6.26",
"wyrihaximus/broadcast-contracts": "^1.3",
"wyrihaximus/generative-composer-plugin-tooling": "^1",
Expand Down
160 changes: 80 additions & 80 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions src/Consumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ public function __construct(
public function close(): void
{
$this->running = false;

$this->context->close();
}

/** @return PromiseInterface<mixed> */
Expand Down
7 changes: 6 additions & 1 deletion src/LifeCycle/CloseContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@
use Mammatus\LifeCycleEvents\Shutdown;
use WyriHaximus\Broadcast\Contracts\AsyncListener;

use function React\Async\await;
use function React\Promise\Timer\sleep;

final class CloseContext implements AsyncListener
{
public function __construct(
private readonly Context $context,
) {
}

public function stop(Shutdown $event): void
public function shutdown(Shutdown $event): void
{
await(sleep(0.1));

$this->context->close();
}
}
4 changes: 0 additions & 4 deletions tests/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public function runHappy(): void

$container->expects('get')->with(Noop::class)->once()->andReturn(new Noop());

$context->expects('close')->once();

$logger->expects('info')->with('Starting consumer 0 of 1 for ' . Noop::class)->atLeast()->once();

$exitCode = (new App($consumer, $logger))->run(Noop::class);
Expand All @@ -47,8 +45,6 @@ public function runAngry(): void
$exception = new RuntimeException('Ik ben boos!');
$container->expects('get')->with(Noop::class)->once()->andReturn(new Angry($exception));

$context->expects('close')->once();

$logger->expects('info')->with('Starting consumer 0 of 1 for ' . Noop::class)->atLeast()->once();

$exitCode = (new App($consumer, $logger))->run(Noop::class);
Expand Down
2 changes: 0 additions & 2 deletions tests/ConsumerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public function consumeHappy(): void
{
[$consumer, $container, $context, $internalConsumer, $logger] = ConsumerFactory::create(ConsumerFactory::CREATE_CONSUMER_EXPECTED);
$container->expects('get')->with(Noop::class)->once()->andReturn(new Noop());
$context->expects('close')->once();
$logger->expects('info')->with('Starting consumer 0 of 1 for ' . Noop::class)->atLeast()->once();

$message = new Message();
Expand Down Expand Up @@ -53,7 +52,6 @@ public function invalidJson(): void

[$consumer, $container, $context, $internalConsumer, $logger] = ConsumerFactory::create(ConsumerFactory::CREATE_CONSUMER_EXPECTED);
$container->expects('get')->with(Noop::class)->once()->andReturn(new Noop());
$context->expects('close')->once();
$logger->expects('info')->with('Starting consumer 0 of 1 for ' . Noop::class)->atLeast()->once();

$message = new Message();
Expand Down
4 changes: 0 additions & 4 deletions tests/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ public function runHappy(): void

$container->expects('get')->with(Noop::class)->atLeast()->once()->andReturn(new Noop());

$context->expects('close')->once();

$eventDispatcher = Mockery::mock(EventDispatcherInterface::class);

$logger->expects('debug')->with('Starting queue manager')->once();
Expand All @@ -58,8 +56,6 @@ public function runAngry(): void
[$consumer, $container, $context, $internalConsumer, $logger] = ConsumerFactory::create(ConsumerFactory::CREATE_CONSUMER_EXPECTED);
$internalConsumer->expects('receiveNoWait')->between(0, PHP_INT_MAX);

$context->expects('close')->once();

$eventDispatcher = Mockery::mock(EventDispatcherInterface::class);

$exception = new RuntimeException('Ik ben boos!');
Expand Down

0 comments on commit d82b08a

Please sign in to comment.