Skip to content

Commit 1bc5337

Browse files
authored
Merge pull request #301 from clue-labs/sock
Improve test suite, clean up leftover `.sock` files
2 parents 8397f22 + 4daf962 commit 1bc5337

File tree

4 files changed

+55
-8
lines changed

4 files changed

+55
-8
lines changed

tests/FdServerTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ public function testGetAddressReturnsSameAddressAsOriginalSocketForUnixDomainSoc
192192
$this->markTestSkipped('Listening on Unix domain socket (UDS) not supported');
193193
}
194194

195+
assert(is_resource($socket));
196+
unlink(str_replace('unix://', '', stream_socket_get_name($socket, false)));
197+
195198
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
196199

197200
$server = new FdServer($fd, $loop);

tests/ServerTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public function testConstructorCreatesExpectedUnixServer()
7676
->then($this->expectCallableOnce(), $this->expectCallableNever());
7777

7878
$connection = \React\Async\await(\React\Promise\Timer\timeout($connector->connect($server->getAddress()), self::TIMEOUT));
79+
assert($connection instanceof ConnectionInterface);
80+
81+
unlink(str_replace('unix://', '', $connection->getRemoteAddress()));
7982

8083
$connection->close();
8184
$server->close();

tests/SocketServerTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ public function testConstructorCreatesExpectedUnixServer()
9797
->then($this->expectCallableOnce(), $this->expectCallableNever());
9898

9999
$connection = \React\Async\await(\React\Promise\Timer\timeout($connector->connect($socket->getAddress()), self::TIMEOUT));
100+
assert($connection instanceof ConnectionInterface);
100101

102+
unlink(str_replace('unix://', '', $connection->getRemoteAddress()));
103+
104+
$connection->close();
101105
$socket->close();
102106
}
103107

tests/UnixServerTest.php

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88

99
class UnixServerTest extends TestCase
1010
{
11+
/** @var ?UnixServer */
1112
private $server;
13+
14+
/** @var ?string */
1215
private $uds;
1316

1417
/**
@@ -28,7 +31,10 @@ public function setUpServer()
2831

2932
public function testConstructWithoutLoopAssignsLoopAutomatically()
3033
{
31-
$server = new UnixServer($this->getRandomSocketUri());
34+
unlink(str_replace('unix://', '', $this->uds));
35+
$this->uds = $this->getRandomSocketUri();
36+
37+
$server = new UnixServer($this->uds);
3238

3339
$ref = new \ReflectionProperty($server, 'loop');
3440
$ref->setAccessible(true);
@@ -45,9 +51,11 @@ public function testConstructWithoutLoopAssignsLoopAutomatically()
4551
public function testConnection()
4652
{
4753
$client = stream_socket_client($this->uds);
54+
assert(is_resource($client));
4855

4956
$this->server->on('connection', $this->expectCallableOnce());
5057
$this->tick();
58+
$this->tick();
5159
}
5260

5361
/**
@@ -56,8 +64,11 @@ public function testConnection()
5664
public function testConnectionWithManyClients()
5765
{
5866
$client1 = stream_socket_client($this->uds);
67+
assert(is_resource($client1));
5968
$client2 = stream_socket_client($this->uds);
69+
assert(is_resource($client2));
6070
$client3 = stream_socket_client($this->uds);
71+
assert(is_resource($client3));
6172

6273
$this->server->on('connection', $this->expectCallableExactly(3));
6374
$this->tick();
@@ -68,6 +79,7 @@ public function testConnectionWithManyClients()
6879
public function testDataEventWillNotBeEmittedWhenClientSendsNoData()
6980
{
7081
$client = stream_socket_client($this->uds);
82+
assert(is_resource($client));
7183

7284
$mock = $this->expectCallableNever();
7385

@@ -81,6 +93,7 @@ public function testDataEventWillNotBeEmittedWhenClientSendsNoData()
8193
public function testDataWillBeEmittedWithDataClientSends()
8294
{
8395
$client = stream_socket_client($this->uds);
96+
assert(is_resource($client));
8497

8598
fwrite($client, "foo\n");
8699

@@ -138,6 +151,7 @@ public function testGetAddressAfterCloseReturnsNull()
138151
public function testLoopWillEndWhenServerIsClosedAfterSingleConnection()
139152
{
140153
$client = stream_socket_client($this->uds);
154+
assert(is_resource($client));
141155

142156
// explicitly unset server because we only accept a single connection
143157
// and then already call close()
@@ -191,6 +205,7 @@ public function testDataWillBeEmittedInMultipleChunksWhenClientSendsExcessiveAmo
191205
public function testConnectionDoesNotEndWhenClientDoesNotClose()
192206
{
193207
$client = stream_socket_client($this->uds);
208+
assert(is_resource($client));
194209

195210
$mock = $this->expectCallableNever();
196211

@@ -221,10 +236,13 @@ public function testConnectionDoesEndWhenClientCloses()
221236

222237
public function testCtorAddsResourceToLoop()
223238
{
239+
unlink(str_replace('unix://', '', $this->uds));
240+
$this->uds = $this->getRandomSocketUri();
241+
224242
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
225243
$loop->expects($this->once())->method('addReadStream');
226244

227-
$server = new UnixServer($this->getRandomSocketUri(), $loop);
245+
new UnixServer($this->uds, $loop);
228246
}
229247

230248
public function testCtorThrowsForInvalidAddressScheme()
@@ -264,51 +282,66 @@ public function testCtorThrowsWhenPathIsNotWritableWithoutCallingCustomErrorHand
264282

265283
public function testResumeWithoutPauseIsNoOp()
266284
{
285+
unlink(str_replace('unix://', '', $this->uds));
286+
$this->uds = $this->getRandomSocketUri();
287+
267288
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
268289
$loop->expects($this->once())->method('addReadStream');
269290

270-
$server = new UnixServer($this->getRandomSocketUri(), $loop);
291+
$server = new UnixServer($this->uds, $loop);
271292
$server->resume();
272293
}
273294

274295
public function testPauseRemovesResourceFromLoop()
275296
{
297+
unlink(str_replace('unix://', '', $this->uds));
298+
$this->uds = $this->getRandomSocketUri();
299+
276300
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
277301
$loop->expects($this->once())->method('removeReadStream');
278302

279-
$server = new UnixServer($this->getRandomSocketUri(), $loop);
303+
$server = new UnixServer($this->uds, $loop);
280304
$server->pause();
281305
}
282306

283307
public function testPauseAfterPauseIsNoOp()
284308
{
309+
unlink(str_replace('unix://', '', $this->uds));
310+
$this->uds = $this->getRandomSocketUri();
311+
285312
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
286313
$loop->expects($this->once())->method('removeReadStream');
287314

288-
$server = new UnixServer($this->getRandomSocketUri(), $loop);
315+
$server = new UnixServer($this->uds, $loop);
289316
$server->pause();
290317
$server->pause();
291318
}
292319

293320
public function testCloseRemovesResourceFromLoop()
294321
{
322+
unlink(str_replace('unix://', '', $this->uds));
323+
$this->uds = $this->getRandomSocketUri();
324+
295325
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
296326
$loop->expects($this->once())->method('removeReadStream');
297327

298-
$server = new UnixServer($this->getRandomSocketUri(), $loop);
328+
$server = new UnixServer($this->uds, $loop);
299329
$server->close();
300330
}
301331

302332
public function testEmitsErrorWhenAcceptListenerFailsWithoutCallingCustomErrorHandler()
303333
{
334+
unlink(str_replace('unix://', '', $this->uds));
335+
$this->uds = $this->getRandomSocketUri();
336+
304337
$listener = null;
305338
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
306339
$loop->expects($this->once())->method('addReadStream')->with($this->anything(), $this->callback(function ($cb) use (&$listener) {
307340
$listener = $cb;
308341
return true;
309342
}));
310343

311-
$server = new UnixServer($this->getRandomSocketUri(), $loop);
344+
$server = new UnixServer($this->uds, $loop);
312345

313346
$exception = null;
314347
$server->on('error', function ($e) use (&$exception) {
@@ -361,7 +394,7 @@ public function testListenOnBusyPortThrows()
361394
}
362395

363396
$this->setExpectedException('RuntimeException');
364-
$another = new UnixServer($this->uds);
397+
new UnixServer($this->uds);
365398
}
366399

367400
/**
@@ -372,7 +405,11 @@ public function tearDownServer()
372405
{
373406
if ($this->server) {
374407
$this->server->close();
408+
$this->server = null;
375409
}
410+
411+
assert(is_string($this->uds));
412+
unlink(str_replace('unix://', '', $this->uds));
376413
}
377414

378415
private function getRandomSocketUri()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy