@@ -71,10 +71,13 @@ public function testPendingWillRejectOnTimeout()
71
71
$ this ->expectPromiseRejected ($ promise );
72
72
}
73
73
74
- public function testPendingCancellableWillBeCancelledOnTimeout ()
74
+ public function testPendingCancellableWillBeCancelledThroughFollowerOnTimeout ()
75
75
{
76
+ $ cancellable = $ this ->getMockBuilder ('React\Promise\CancellablePromiseInterface ' )->getMock ();
77
+ $ cancellable ->expects ($ this ->once ())->method ('cancel ' );
78
+
76
79
$ promise = $ this ->getMockBuilder ('React\Promise\CancellablePromiseInterface ' )->getMock ();
77
- $ promise ->expects ($ this ->once ())->method ('cancel ' );
80
+ $ promise ->expects ($ this ->once ())->method ('then ' )-> willReturn ( $ cancellable );
78
81
79
82
Timer \timeout ($ promise , 0.01 , $ this ->loop );
80
83
@@ -223,6 +226,44 @@ public function testWaitingForPromiseToTimeoutDoesNotLeaveGarbageCycles()
223
226
$ this ->assertEquals (0 , gc_collect_cycles ());
224
227
}
225
228
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
+
226
267
public function testCancellingPromiseDoesNotLeaveGarbageCycles ()
227
268
{
228
269
if (class_exists ('React\Promise\When ' )) {
0 commit comments