Skip to content

Commit 7f2525f

Browse files
Transport.php fix backported into 6.8.x (#1109)
* Update Transport.php * Fix 6.8.0 release adding missing class alises (#1114) * Fix for #1112 issue. Adding endpoint aliases + IndicesNamespace::getAliases() * Reverted array alias to class in src/autoload.php + added unit tests for missing class aliases in 6.8 * Fixed indentation in src/ autoload.php * Added TransportTest Co-authored-by: Enrico Zimuel <[email protected]>
1 parent 285ed33 commit 7f2525f

File tree

2 files changed

+86
-1
lines changed

2 files changed

+86
-1
lines changed

src/Elasticsearch/Transport.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ function ($response) {
129129
},
130130
//onFailure
131131
function ($response) {
132+
$code = $response->getCode();
132133
// Ignore 400 level errors, as that means the server responded just fine
133-
if (!(isset($response['code']) && $response['code'] >=400 && $response['code'] < 500)) {
134+
if ($code < 400 || $code >= 500) {
134135
// Otherwise schedule a check
135136
$this->connectionPool->scheduleCheck();
136137
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
/**
3+
* Elasticsearch PHP client
4+
*
5+
* @link https://github.com/elastic/elasticsearch-php/
6+
* @copyright Copyright (c) Elasticsearch B.V (https://www.elastic.co)
7+
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
8+
* @license https://www.gnu.org/licenses/lgpl-2.1.html GNU Lesser General Public License, Version 2.1
9+
*
10+
* Licensed to Elasticsearch B.V under one or more agreements.
11+
* Elasticsearch B.V licenses this file to you under the Apache 2.0 License or
12+
* the GNU Lesser General Public License, Version 2.1, at your option.
13+
* See the LICENSE file in the project root for more information.
14+
*/
15+
16+
17+
declare(strict_types = 1);
18+
19+
namespace Elasticsearch\Tests;
20+
21+
use Elasticsearch\Common\Exceptions\ServerErrorResponseException;
22+
use Elasticsearch\ConnectionPool\AbstractConnectionPool;
23+
use Elasticsearch\Connections\Connection;
24+
use Elasticsearch\Serializers\SerializerInterface;
25+
use Elasticsearch\Transport;
26+
use GuzzleHttp\Ring\Future\FutureArray;
27+
use GuzzleHttp\Ring\Future\FutureArrayInterface;
28+
use PHPUnit\Framework\TestCase;
29+
use Psr\Log\LoggerInterface;
30+
use React\Promise\Deferred;
31+
32+
class TransportTest extends TestCase
33+
{
34+
public function setUp(): void
35+
{
36+
$this->logger = $this->createMock(LoggerInterface::class);
37+
$this->trace = $this->createMock(LoggerInterface::class);
38+
$this->serializer = $this->createMock(SerializerInterface::class);
39+
$this->connectionPool = $this->createMock(AbstractConnectionPool::class);
40+
$this->connection = $this->createMock(Connection::class);
41+
}
42+
43+
public function testPerformRequestWithServerErrorResponseException404Result()
44+
{
45+
$deferred = new Deferred();
46+
$deferred->reject(new ServerErrorResponseException('foo', 404));
47+
$future = new FutureArray($deferred->promise());
48+
49+
$this->connection->method('performRequest')
50+
->willReturn($future);
51+
52+
$this->connectionPool->method('nextConnection')
53+
->willReturn($this->connection);
54+
55+
$this->connectionPool->expects($this->never())
56+
->method('scheduleCheck');
57+
58+
$transport = new Transport(1, $this->connectionPool, $this->logger);
59+
60+
$result = $transport->performRequest('GET', '/');
61+
$this->assertInstanceOf(FutureArrayInterface::class, $result);
62+
}
63+
64+
public function testPerformRequestWithServerErrorResponseException500Result()
65+
{
66+
$deferred = new Deferred();
67+
$deferred->reject(new ServerErrorResponseException('foo', 500));
68+
$future = new FutureArray($deferred->promise());
69+
70+
$this->connection->method('performRequest')
71+
->willReturn($future);
72+
73+
$this->connectionPool->method('nextConnection')
74+
->willReturn($this->connection);
75+
76+
$this->connectionPool->expects($this->once())
77+
->method('scheduleCheck');
78+
79+
$transport = new Transport(1, $this->connectionPool, $this->logger);
80+
81+
$result = $transport->performRequest('GET', '/');
82+
$this->assertInstanceOf(FutureArrayInterface::class, $result);
83+
}
84+
}

0 commit comments

Comments
 (0)