Skip to content

Commit

Permalink
Server instantiation optimized.
Browse files Browse the repository at this point in the history
  • Loading branch information
ekhvalov committed Jun 22, 2020
1 parent 3a35022 commit f761365
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions test/BeanstalkClientConnectionClosedTest.php
Expand Up @@ -13,15 +13,15 @@
use function Amp\Socket\listen;

class BeanstalkClientConnectionClosedTest extends AsyncTestCase {
const PORT_RANGE_MIN = 50000;
const PORT_RANGE_MAX = 65535;

/** @var Server */
private $server;

/**
* @throws SocketException
*/
public function setUp() {
parent::setUp();
$this->server = $this->initServer();
$this->server = listen("tcp://127.0.0.1:0");
}

public function tearDown() {
Expand Down Expand Up @@ -57,14 +57,4 @@ public function dataProviderReserve(): array {
"one second timeout" => [1, 900, 1100],
];
}

private function initServer(): Server {
for ($port = self::PORT_RANGE_MIN; $port <= self::PORT_RANGE_MAX; $port++) {
try {
return listen("tcp://127.0.0.1:". $port);
} catch (SocketException $e) {
}
}
throw new \RuntimeException("No available port found");
}
}

0 comments on commit f761365

Please sign in to comment.