File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -76,4 +76,37 @@ public function shouldRejectWithoutCreatingGarbageCyclesIfCancellerHoldsReferenc
7676
7777 $ this ->assertSame (0 , gc_collect_cycles ());
7878 }
79+
80+ /** @test */
81+ public function shouldNotLeaveGarbageCyclesWhenRemovingLastReferenceToPendingDeferred ()
82+ {
83+ gc_collect_cycles ();
84+ $ deferred = new Deferred ();
85+ $ deferred ->promise ();
86+ unset($ deferred );
87+
88+ $ this ->assertSame (0 , gc_collect_cycles ());
89+ }
90+
91+ /** @test */
92+ public function shouldNotLeaveGarbageCyclesWhenRemovingLastReferenceToPendingDeferredWithUnusedCanceller ()
93+ {
94+ gc_collect_cycles ();
95+ $ deferred = new Deferred (function () { });
96+ $ deferred ->promise ();
97+ unset($ deferred );
98+
99+ $ this ->assertSame (0 , gc_collect_cycles ());
100+ }
101+
102+ /** @test */
103+ public function shouldNotLeaveGarbageCyclesWhenRemovingLastReferenceToPendingDeferredWithNoopCanceller ()
104+ {
105+ gc_collect_cycles ();
106+ $ deferred = new Deferred (function () { });
107+ $ deferred ->promise ()->cancel ();
108+ unset($ deferred );
109+
110+ $ this ->assertSame (0 , gc_collect_cycles ());
111+ }
79112}
Original file line number Diff line number Diff line change @@ -47,4 +47,30 @@ public function shouldThrowExceptionIfConstructedWithAPromise()
4747
4848 return new FulfilledPromise (new FulfilledPromise ());
4949 }
50+
51+ /** @test */
52+ public function shouldNotLeaveGarbageCyclesWhenRemovingLastReferenceToFulfilledPromiseWithAlwaysFollowers ()
53+ {
54+ gc_collect_cycles ();
55+ $ promise = new FulfilledPromise (1 );
56+ $ promise ->always (function () {
57+ throw new \RuntimeException ();
58+ });
59+ unset($ promise );
60+
61+ $ this ->assertSame (0 , gc_collect_cycles ());
62+ }
63+
64+ /** @test */
65+ public function shouldNotLeaveGarbageCyclesWhenRemovingLastReferenceToFulfilledPromiseWithThenFollowers ()
66+ {
67+ gc_collect_cycles ();
68+ $ promise = new FulfilledPromise (1 );
69+ $ promise = $ promise ->then (function () {
70+ throw new \RuntimeException ();
71+ });
72+ unset($ promise );
73+
74+ $ this ->assertSame (0 , gc_collect_cycles ());
75+ }
5076}
Original file line number Diff line number Diff line change @@ -47,4 +47,30 @@ public function shouldThrowExceptionIfConstructedWithAPromise()
4747
4848 return new RejectedPromise (new RejectedPromise ());
4949 }
50+
51+ /** @test */
52+ public function shouldNotLeaveGarbageCyclesWhenRemovingLastReferenceToRejectedPromiseWithAlwaysFollowers ()
53+ {
54+ gc_collect_cycles ();
55+ $ promise = new RejectedPromise (1 );
56+ $ promise ->always (function () {
57+ throw new \RuntimeException ();
58+ });
59+ unset($ promise );
60+
61+ $ this ->assertSame (0 , gc_collect_cycles ());
62+ }
63+
64+ /** @test */
65+ public function shouldNotLeaveGarbageCyclesWhenRemovingLastReferenceToRejectedPromiseWithThenFollowers ()
66+ {
67+ gc_collect_cycles ();
68+ $ promise = new RejectedPromise (1 );
69+ $ promise = $ promise ->then (null , function () {
70+ throw new \RuntimeException ();
71+ });
72+ unset($ promise );
73+
74+ $ this ->assertSame (0 , gc_collect_cycles ());
75+ }
5076}
You can’t perform that action at this time.
0 commit comments