Skip to content

Commit 5603979

Browse files
authored
Merge pull request #308 from clue-labs/garbage
Update test suite to collect all garbage cycles
2 parents 9f5ac5f + 6017070 commit 5603979

File tree

5 files changed

+57
-23
lines changed

5 files changed

+57
-23
lines changed

tests/DnsConnectorTest.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,9 @@ public function testRejectionDuringDnsLookupShouldNotCreateAnyGarbageReferences(
293293
$this->markTestSkipped('Not supported on legacy Promise v1 API');
294294
}
295295

296-
gc_collect_cycles();
297-
gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on
296+
while (gc_collect_cycles()) {
297+
// collect all garbage cycles
298+
}
298299

299300
$dns = new Deferred();
300301
$this->resolver->expects($this->once())->method('resolve')->with($this->equalTo('example.com'))->willReturn($dns->promise());
@@ -316,7 +317,9 @@ public function testRejectionAfterDnsLookupShouldNotCreateAnyGarbageReferences()
316317
$this->markTestSkipped('Not supported on legacy Promise v1 API');
317318
}
318319

319-
gc_collect_cycles();
320+
while (gc_collect_cycles()) {
321+
// collect all garbage cycles
322+
}
320323

321324
$dns = new Deferred();
322325
$this->resolver->expects($this->once())->method('resolve')->with($this->equalTo('example.com'))->willReturn($dns->promise());
@@ -341,7 +344,9 @@ public function testRejectionAfterDnsLookupShouldNotCreateAnyGarbageReferencesAg
341344
$this->markTestSkipped('Not supported on legacy Promise v1 API');
342345
}
343346

344-
gc_collect_cycles();
347+
while (gc_collect_cycles()) {
348+
// collect all garbage cycles
349+
}
345350

346351
$dns = new Deferred();
347352
$this->resolver->expects($this->once())->method('resolve')->with($this->equalTo('example.com'))->willReturn($dns->promise());
@@ -369,7 +374,9 @@ public function testCancelDuringDnsLookupShouldNotCreateAnyGarbageReferences()
369374
$this->markTestSkipped('Not supported on legacy Promise v1 API');
370375
}
371376

372-
gc_collect_cycles();
377+
while (gc_collect_cycles()) {
378+
// collect all garbage cycles
379+
}
373380

374381
$dns = new Deferred(function () {
375382
throw new \RuntimeException();
@@ -391,7 +398,9 @@ public function testCancelDuringTcpConnectionShouldNotCreateAnyGarbageReferences
391398
$this->markTestSkipped('Not supported on legacy Promise v1 API');
392399
}
393400

394-
gc_collect_cycles();
401+
while (gc_collect_cycles()) {
402+
// collect all garbage cycles
403+
}
395404

396405
$dns = new Deferred();
397406
$this->resolver->expects($this->once())->method('resolve')->with($this->equalTo('example.com'))->willReturn($dns->promise());

tests/IntegrationTest.php

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ public function testCancellingPendingConnectionWithoutTimeoutShouldNotCreateAnyG
126126

127127
$connector = new Connector(array('timeout' => false));
128128

129-
gc_collect_cycles();
130-
gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on
129+
while (gc_collect_cycles()) {
130+
// collect all garbage cycles
131+
}
131132

132133
$promise = $connector->connect('8.8.8.8:80');
133134
$promise->cancel();
@@ -144,7 +145,10 @@ public function testCancellingPendingConnectionShouldNotCreateAnyGarbageReferenc
144145

145146
$connector = new Connector(array());
146147

147-
gc_collect_cycles();
148+
while (gc_collect_cycles()) {
149+
// collect all garbage cycles
150+
}
151+
148152
$promise = $connector->connect('8.8.8.8:80');
149153
$promise->cancel();
150154
unset($promise);
@@ -167,7 +171,9 @@ public function testWaitingForRejectedConnectionShouldNotCreateAnyGarbageReferen
167171

168172
$connector = new Connector(array('timeout' => false));
169173

170-
gc_collect_cycles();
174+
while (gc_collect_cycles()) {
175+
// collect all garbage cycles
176+
}
171177

172178
$wait = true;
173179
$promise = $connector->connect('127.0.0.1:1')->then(
@@ -201,7 +207,9 @@ public function testWaitingForConnectionTimeoutDuringDnsLookupShouldNotCreateAny
201207

202208
$connector = new Connector(array('timeout' => 0.001));
203209

204-
gc_collect_cycles();
210+
while (gc_collect_cycles()) {
211+
// collect all garbage cycles
212+
}
205213

206214
$wait = true;
207215
$promise = $connector->connect('google.com:80')->then(
@@ -232,7 +240,9 @@ public function testWaitingForConnectionTimeoutDuringTcpConnectionShouldNotCreat
232240

233241
$connector = new Connector(array('timeout' => 0.000001));
234242

235-
gc_collect_cycles();
243+
while (gc_collect_cycles()) {
244+
// collect all garbage cycles
245+
}
236246

237247
$wait = true;
238248
$promise = $connector->connect('8.8.8.8:53')->then(
@@ -263,7 +273,9 @@ public function testWaitingForInvalidDnsConnectionShouldNotCreateAnyGarbageRefer
263273

264274
$connector = new Connector(array('timeout' => false));
265275

266-
gc_collect_cycles();
276+
while (gc_collect_cycles()) {
277+
// collect all garbage cycles
278+
}
267279

268280
$wait = true;
269281
$promise = $connector->connect('example.invalid:80')->then(
@@ -304,7 +316,9 @@ public function testWaitingForInvalidTlsConnectionShouldNotCreateAnyGarbageRefer
304316
)
305317
));
306318

307-
gc_collect_cycles();
319+
while (gc_collect_cycles()) {
320+
// collect all garbage cycles
321+
}
308322

309323
$wait = true;
310324
$promise = $connector->connect('tls://self-signed.badssl.com:443')->then(
@@ -338,7 +352,10 @@ public function testWaitingForSuccessfullyClosedConnectionShouldNotCreateAnyGarb
338352

339353
$connector = new Connector(array('timeout' => false));
340354

341-
gc_collect_cycles();
355+
while (gc_collect_cycles()) {
356+
// collect all garbage cycles
357+
}
358+
342359
$promise = $connector->connect('google.com:80')->then(
343360
function ($conn) {
344361
$conn->close();

tests/SecureConnectorTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,15 @@ public function testRejectionDuringConnectionShouldNotCreateAnyGarbageReferences
258258
$this->markTestSkipped('Not supported on legacy Promise v1 API');
259259
}
260260

261-
gc_collect_cycles();
262-
gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on
261+
while (gc_collect_cycles()) {
262+
// collect all garbage cycles
263+
}
263264

264265
$tcp = new Deferred();
265266
$this->tcp->expects($this->once())->method('connect')->willReturn($tcp->promise());
266267

267268
$promise = $this->connector->connect('example.com:80');
268-
269+
269270
$promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection
270271

271272
$tcp->reject(new \RuntimeException());
@@ -280,7 +281,9 @@ public function testRejectionDuringTlsHandshakeShouldNotCreateAnyGarbageReferenc
280281
$this->markTestSkipped('Not supported on legacy Promise v1 API');
281282
}
282283

283-
gc_collect_cycles();
284+
while (gc_collect_cycles()) {
285+
// collect all garbage cycles
286+
}
284287

285288
$connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->getMock();
286289

tests/TcpConnectorTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,9 @@ public function testCancelDuringConnectionShouldNotCreateAnyGarbageReferences()
372372
$this->markTestSkipped('Not supported on legacy Promise v1 API');
373373
}
374374

375-
gc_collect_cycles();
376-
gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on
375+
while (gc_collect_cycles()) {
376+
// collect all garbage cycles
377+
}
377378

378379
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
379380
$connector = new TcpConnector($loop);

tests/TimeoutConnectorTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ public function testRejectionDuringConnectionShouldNotCreateAnyGarbageReferences
199199
$this->markTestSkipped('Not supported on legacy Promise v1 API');
200200
}
201201

202-
gc_collect_cycles();
202+
while (gc_collect_cycles()) {
203+
// collect all garbage cycles
204+
}
203205

204206
$connection = new Deferred();
205207
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
@@ -223,7 +225,9 @@ public function testRejectionDueToTimeoutShouldNotCreateAnyGarbageReferences()
223225
$this->markTestSkipped('Not supported on legacy Promise v1 API');
224226
}
225227

226-
gc_collect_cycles();
228+
while (gc_collect_cycles()) {
229+
// collect all garbage cycles
230+
}
227231

228232
$connection = new Deferred(function () {
229233
throw new \RuntimeException('Connection cancelled');

0 commit comments

Comments
 (0)