Skip to content

Commit 0ce9e90

Browse files
committed
Chore: Fix and improve coverage
1 parent ca10f78 commit 0ce9e90

File tree

2 files changed

+20
-35
lines changed

2 files changed

+20
-35
lines changed

DEVELOP.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ If the environment is outdated, you can upgrade it::
4848

4949
composer update
5050

51+
If you see messages like ``Warning: No code coverage driver available`` when running
52+
the tests, you will need to install the ``xdebug`` extension::
53+
54+
pecl install xdebug
55+
56+
It may happen that you will have to re-install it, for example after your PHP
57+
version has been upgraded by your package manager.
58+
5159

5260
Running the Tests
5361
=================
@@ -62,6 +70,7 @@ You can run the tests like::
6270

6371
# Output coverage report as HTML
6472
composer run -- test --coverage-html ./report
73+
open report/index.html
6574

6675
# Run specific tests
6776
composer run -- test --filter "testFetchColumn"

src/Crate/PDO/Http/ServerPool.php

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -94,47 +94,23 @@ public function __construct(array $servers, ClientInterface $client = null)
9494
*/
9595
public function execute(string $query, array $parameters): CollectionInterface
9696
{
97-
$numServers = count($this->availableServers) - 1;
98-
99-
for ($i = 0; $i <= $numServers; $i++) {
100-
// always get the first available server
101-
$server = $this->availableServers[0];
102-
103-
// Move the selected server to the end of the stack
104-
$this->availableServers[] = array_shift($this->availableServers);
105-
106-
try {
107-
return $this->sendRequest($server, $query, $parameters, false);
108-
} catch (ConnectException $exception) {
109-
// Catch it before the BadResponseException but do nothing.
110-
continue;
111-
} catch (BadResponseException $exception) {
112-
$body = (string)$exception->getResponse()->getBody();
113-
$json = json_decode($body, true);
114-
115-
if ($json === null && json_last_error() !== JSON_ERROR_NONE) {
116-
throw new RuntimeException(sprintf('Server returned non-JSON response: %s', $body), 0, $exception);
117-
}
118-
119-
$errorCode = $json['error']['code'];
120-
$errorMessage = $json['error']['message'];
121-
122-
throw new RuntimeException($errorMessage, $errorCode, $exception);
123-
}
124-
}
125-
126-
throw new ConnectException(
127-
sprintf('No more servers available, exception from last server: %s', $exception->getMessage()),
128-
$exception->getRequest(),
129-
$exception
130-
);
97+
return $this->executeGeneric($query, $parameters, false);
13198
}
13299

133100
/**
134101
* {@Inheritdoc}
135102
* @throws \GuzzleHttp\Exception\ConnectException
136103
*/
137104
public function executeBulk(string $query, array $parameters): BulkResponseInterface
105+
{
106+
return $this->executeGeneric($query, $parameters, true);
107+
}
108+
109+
/**
110+
* {@Inheritdoc}
111+
* @throws \GuzzleHttp\Exception\ConnectException
112+
*/
113+
private function executeGeneric(string $query, array $parameters, bool $bulk_mode = false)
138114
{
139115
$numServers = count($this->availableServers) - 1;
140116

@@ -146,7 +122,7 @@ public function executeBulk(string $query, array $parameters): BulkResponseInter
146122
$this->availableServers[] = array_shift($this->availableServers);
147123

148124
try {
149-
return $this->sendRequest($server, $query, $parameters, true);
125+
return $this->sendRequest($server, $query, $parameters, $bulk_mode);
150126
} catch (ConnectException $exception) {
151127
// Catch it before the BadResponseException but do nothing.
152128
continue;

0 commit comments

Comments
 (0)