@@ -103,4 +103,138 @@ public function testAwaitOnceWithTimeoutWillResolvemmediatelyAndCleanUpTimeout()
103103
104104 $ this ->assertLessThan (0.1 , $ time );
105105 }
106+
107+ public function testAwaitOneResolvesShouldNotCreateAnyGarbageReferences ()
108+ {
109+ if (class_exists ('React\Promise\When ' ) && PHP_VERSION_ID >= 50400 ) {
110+ $ this ->markTestSkipped ('Not supported on legacy Promise v1 API with PHP 5.4+ ' );
111+ }
112+
113+ gc_collect_cycles ();
114+
115+ $ promise = Promise \resolve (1 );
116+ Block \await ($ promise , $ this ->loop );
117+ unset($ promise );
118+
119+ $ this ->assertEquals (0 , gc_collect_cycles ());
120+ }
121+
122+ public function testAwaitOneRejectedShouldNotCreateAnyGarbageReferences ()
123+ {
124+ if (class_exists ('React\Promise\When ' ) && PHP_VERSION_ID >= 50400 ) {
125+ $ this ->markTestSkipped ('Not supported on legacy Promise v1 API with PHP 5.4+ ' );
126+ }
127+
128+ gc_collect_cycles ();
129+
130+ $ promise = Promise \reject (new RuntimeException ());
131+ try {
132+ Block \await ($ promise , $ this ->loop );
133+ } catch (Exception $ e ) {
134+ // no-op
135+ }
136+ unset($ promise , $ e );
137+
138+ $ this ->assertEquals (0 , gc_collect_cycles ());
139+ }
140+
141+ public function testAwaitOneRejectedWithTimeoutShouldNotCreateAnyGarbageReferences ()
142+ {
143+ if (class_exists ('React\Promise\When ' ) && PHP_VERSION_ID >= 50400 ) {
144+ $ this ->markTestSkipped ('Not supported on legacy Promise v1 API with PHP 5.4+ ' );
145+ }
146+
147+ gc_collect_cycles ();
148+
149+ $ promise = Promise \reject (new RuntimeException ());
150+ try {
151+ Block \await ($ promise , $ this ->loop , 0.001 );
152+ } catch (Exception $ e ) {
153+ // no-op
154+ }
155+ unset($ promise , $ e );
156+
157+ $ this ->assertEquals (0 , gc_collect_cycles ());
158+ }
159+
160+ public function testAwaitNullValueShouldNotCreateAnyGarbageReferences ()
161+ {
162+ if (class_exists ('React\Promise\When ' ) && PHP_VERSION_ID >= 50400 ) {
163+ $ this ->markTestSkipped ('Not supported on legacy Promise v1 API with PHP 5.4+ ' );
164+ }
165+
166+ gc_collect_cycles ();
167+
168+ $ promise = Promise \reject (null );
169+ try {
170+ Block \await ($ promise , $ this ->loop );
171+ } catch (Exception $ e ) {
172+ // no-op
173+ }
174+ unset($ promise , $ e );
175+
176+ $ this ->assertEquals (0 , gc_collect_cycles ());
177+ }
178+
179+ /**
180+ * @requires PHP 7
181+ */
182+ public function testAwaitPendingPromiseWithTimeoutAndCancellerShouldNotCreateAnyGarbageReferences ()
183+ {
184+ if (class_exists ('React\Promise\When ' )) {
185+ $ this ->markTestSkipped ('Not supported on legacy Promise v1 API ' );
186+ }
187+
188+ gc_collect_cycles ();
189+
190+ $ promise = new \React \Promise \Promise (function () { }, function () {
191+ throw new RuntimeException ();
192+ });
193+ try {
194+ Block \await ($ promise , $ this ->loop , 0.001 );
195+ } catch (Exception $ e ) {
196+ // no-op
197+ }
198+ unset($ promise , $ e );
199+
200+ $ this ->assertEquals (0 , gc_collect_cycles ());
201+ }
202+
203+ /**
204+ * @requires PHP 7
205+ */
206+ public function testAwaitPendingPromiseWithTimeoutAndWithoutCancellerShouldNotCreateAnyGarbageReferences ()
207+ {
208+ gc_collect_cycles ();
209+
210+ $ promise = new \React \Promise \Promise (function () { });
211+ try {
212+ Block \await ($ promise , $ this ->loop , 0.001 );
213+ } catch (Exception $ e ) {
214+ // no-op
215+ }
216+ unset($ promise , $ e );
217+
218+ $ this ->assertEquals (0 , gc_collect_cycles ());
219+ }
220+
221+ /**
222+ * @requires PHP 7
223+ */
224+ public function testAwaitPendingPromiseWithTimeoutAndNoOpCancellerShouldNotCreateAnyGarbageReferences ()
225+ {
226+ gc_collect_cycles ();
227+
228+ $ promise = new \React \Promise \Promise (function () { }, function () {
229+ // no-op
230+ });
231+ try {
232+ Block \await ($ promise , $ this ->loop , 0.001 );
233+ } catch (Exception $ e ) {
234+ // no-op
235+ }
236+ unset($ promise , $ e );
237+
238+ $ this ->assertEquals (0 , gc_collect_cycles ());
239+ }
106240}
0 commit comments