@@ -71,10 +71,13 @@ public function testPendingWillRejectOnTimeout()
7171 $ this ->expectPromiseRejected ($ promise );
7272 }
7373
74- public function testPendingCancellableWillBeCancelledOnTimeout ()
74+ public function testPendingCancellableWillBeCancelledThroughFollowerOnTimeout ()
7575 {
76+ $ cancellable = $ this ->getMockBuilder ('React\Promise\CancellablePromiseInterface ' )->getMock ();
77+ $ cancellable ->expects ($ this ->once ())->method ('cancel ' );
78+
7679 $ promise = $ this ->getMockBuilder ('React\Promise\CancellablePromiseInterface ' )->getMock ();
77- $ promise ->expects ($ this ->once ())->method ('cancel ' );
80+ $ promise ->expects ($ this ->once ())->method ('then ' )-> willReturn ( $ cancellable );
7881
7982 Timer \timeout ($ promise , 0.01 , $ this ->loop );
8083
@@ -223,6 +226,44 @@ public function testWaitingForPromiseToTimeoutDoesNotLeaveGarbageCycles()
223226 $ this ->assertEquals (0 , gc_collect_cycles ());
224227 }
225228
229+ public function testWaitingForPromiseToTimeoutWithoutCancellerDoesNotLeaveGarbageCycles ()
230+ {
231+ if (class_exists ('React\Promise\When ' )) {
232+ $ this ->markTestSkipped ('Not supported on legacy Promise v1 API ' );
233+ }
234+
235+ gc_collect_cycles ();
236+
237+ $ promise = new \React \Promise \Promise (function () { });
238+
239+ $ promise = Timer \timeout ($ promise , 0.01 , $ this ->loop );
240+
241+ $ this ->loop ->run ();
242+ unset($ promise );
243+
244+ $ this ->assertEquals (0 , gc_collect_cycles ());
245+ }
246+
247+ public function testWaitingForPromiseToTimeoutWithNoOpCancellerDoesNotLeaveGarbageCycles ()
248+ {
249+ if (class_exists ('React\Promise\When ' )) {
250+ $ this ->markTestSkipped ('Not supported on legacy Promise v1 API ' );
251+ }
252+
253+ gc_collect_cycles ();
254+
255+ $ promise = new \React \Promise \Promise (function () { }, function () {
256+ // no-op
257+ });
258+
259+ $ promise = Timer \timeout ($ promise , 0.01 , $ this ->loop );
260+
261+ $ this ->loop ->run ();
262+ unset($ promise );
263+
264+ $ this ->assertEquals (0 , gc_collect_cycles ());
265+ }
266+
226267 public function testCancellingPromiseDoesNotLeaveGarbageCycles ()
227268 {
228269 if (class_exists ('React\Promise\When ' )) {
0 commit comments