Skip to content

Commit

Permalink
Merge pull request #641 from patchlevel/fix-subscription-remove
Browse files Browse the repository at this point in the history
dont teardown new subscriptions
  • Loading branch information
DavidBadura authored Oct 17, 2024
2 parents 24213f7 + 6826d53 commit eb6fde7
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Subscription/Engine/DefaultSubscriptionEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,19 @@ function (array $subscriptions): Result {
$errors = [];

foreach ($subscriptions as $subscription) {
if ($subscription->isNew()) {
$this->subscriptionManager->remove($subscription);

$this->logger?->info(
sprintf(
'Subscription Engine: Subscription "%s" removed.',
$subscription->id(),
),
);

continue;
}

$subscriber = $this->subscriber($subscription->id());

if (!$subscriber) {
Expand Down
41 changes: 41 additions & 0 deletions tests/Unit/Subscription/Engine/DefaultSubscriptionEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2530,6 +2530,47 @@ public function drop(): void
self::assertEquals([$subscription], $subscriptionStore->removedSubscriptions);
}

public function testRemoveNewSubscriber(): void
{
$subscriptionId = 'test';
$subscriber = new #[Subscriber('test', RunMode::FromBeginning)]
class {
public bool $dropped = false;

#[Teardown]
public function drop(): void
{
$this->dropped = true;
}
};

$subscription = new Subscription(
$subscriptionId,
Subscription::DEFAULT_GROUP,
RunMode::FromBeginning,
Status::New,
);

$subscriptionStore = new DummySubscriptionStore([$subscription]);

$streamableStore = $this->prophesize(Store::class);

$engine = new DefaultSubscriptionEngine(
$streamableStore->reveal(),
$subscriptionStore,
new MetadataSubscriberAccessorRepository([$subscriber]),
logger: new NullLogger(),
);

$result = $engine->remove();

self::assertEquals([], $result->errors);

self::assertEquals([], $subscriptionStore->updatedSubscriptions);
self::assertEquals([$subscription], $subscriptionStore->removedSubscriptions);
self::assertFalse($subscriber->dropped);
}

public function testRemoveWithoutSubscriber(): void
{
$subscriberId = 'test';
Expand Down

0 comments on commit eb6fde7

Please sign in to comment.