Skip to content

Commit

Permalink
Add tests for missing follower cancellation propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
jsor committed Sep 19, 2017
1 parent 177fe31 commit 5d58c47
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions tests/PromiseTest/CancelTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,72 @@ public function cancelShouldAlwaysTriggerCancellerWhenCalledOnRootPromise()

$adapter->promise()->cancel();
}

/** @test */
public function cancelShouldTriggerCancellerWhenFollowerCancels()
{
$adapter1 = $this->getPromiseTestAdapter($this->expectCallableOnce());

$root = $adapter1->promise();

$adapter2 = $this->getPromiseTestAdapter($this->expectCallableOnce());

$follower = $adapter2->promise();
$adapter2->resolve($root);

$follower->cancel();
}

/** @test */
public function cancelShouldNotTriggerCancellerWhenCancellingOnlyOneFollower()
{
$adapter1 = $this->getPromiseTestAdapter($this->expectCallableNever());

$root = $adapter1->promise();

$adapter2 = $this->getPromiseTestAdapter($this->expectCallableOnce());

$follower1 = $adapter2->promise();
$adapter2->resolve($root);

$adapter3 = $this->getPromiseTestAdapter($this->expectCallableNever());
$adapter3->resolve($root);

$follower1->cancel();
}

/** @test */
public function cancelCalledOnFollowerShouldOnlyCancelWhenAllChildrenAndFollowerCancelled()
{
$adapter1 = $this->getPromiseTestAdapter($this->expectCallableOnce());

$root = $adapter1->promise();

$child = $root->then();

$adapter2 = $this->getPromiseTestAdapter($this->expectCallableOnce());

$follower = $adapter2->promise();
$adapter2->resolve($root);

$follower->cancel();
$child->cancel();
}

/** @test */
public function cancelShouldNotTriggerCancellerWhenCancellingFollowerButNotChildren()
{
$adapter1 = $this->getPromiseTestAdapter($this->expectCallableNever());

$root = $adapter1->promise();

$root->then();

$adapter2 = $this->getPromiseTestAdapter($this->expectCallableOnce());

$follower = $adapter2->promise();
$adapter2->resolve($root);

$follower->cancel();
}
}

0 comments on commit 5d58c47

Please sign in to comment.