Skip to content

Commit

Permalink
Read before closing socket to prevent potential RST
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed Nov 29, 2020
1 parent 44225d5 commit 00c610a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions test/ConnectionPoolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ class ConnectionPoolTest extends AsyncTestCase
public function testConnectionCloseWhileIdle(): \Generator
{
/** @var Response $response */
$response = yield $this->executeRequest($this->createRequest());
$response = yield $this->executeRequest($this->createRequest(1));
self::assertSame("hello", yield $response->getBody()->buffer());

yield delay(1000);

/** @var Response $response */
$response = yield $this->executeRequest($this->createRequest());
$response = yield $this->executeRequest($this->createRequest(2));
self::assertSame("hello", yield $response->getBody()->buffer());
}

Expand All @@ -45,6 +45,7 @@ protected function setUp(): void
/** @var Socket\EncryptableSocket $client */
$client = yield $this->socket->accept();

yield $client->read();
yield $client->write("HTTP/1.1 200 OK\r\nconnection: keep-alive\r\ncontent-length: 5\r\n\r\nhello");

yield delay(500);
Expand All @@ -56,9 +57,8 @@ protected function setUp(): void
/** @var Socket\EncryptableSocket $client */
$client = yield $this->socket->accept();

yield $client->write("HTTP/1.1 200 OK\r\nconnection: keep-alive\r\ncontent-length: 5\r\n\r\nhello");

$client->close();
yield $client->read();
yield $client->end("HTTP/1.1 200 OK\r\nconnection: keep-alive\r\ncontent-length: 5\r\n\r\nhello");

$this->socket->close();
});
Expand All @@ -69,8 +69,8 @@ private function executeRequest(Request $request, ?CancellationToken $cancellati
return $this->client->request($request, $cancellationToken);
}

private function createRequest(): Request
private function createRequest(int $num): Request
{
return new Request('http://' . $this->socket->getAddress());
return new Request('http://' . $this->socket->getAddress() . '/' . $num);
}
}

0 comments on commit 00c610a

Please sign in to comment.