tarantool-php /
client
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | /** |
||||||
| 4 | * This file is part of the tarantool/client package. |
||||||
| 5 | * |
||||||
| 6 | * (c) Eugene Leonovich <[email protected]> |
||||||
| 7 | * |
||||||
| 8 | * For the full copyright and license information, please view the LICENSE |
||||||
| 9 | * file that was distributed with this source code. |
||||||
| 10 | */ |
||||||
| 11 | |||||||
| 12 | declare(strict_types=1); |
||||||
| 13 | |||||||
| 14 | namespace Tarantool\Client\Tests\Integration\Connection; |
||||||
| 15 | |||||||
| 16 | use Tarantool\Client\Exception\CommunicationFailed; |
||||||
| 17 | use Tarantool\Client\Packer\PacketLength; |
||||||
| 18 | use Tarantool\Client\Tests\GreetingDataProvider; |
||||||
| 19 | use Tarantool\Client\Tests\Integration\ClientBuilder; |
||||||
| 20 | use Tarantool\Client\Tests\Integration\FakeServer\FakeServerBuilder; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 21 | use Tarantool\Client\Tests\Integration\FakeServer\Handler\SleepHandler; |
||||||
| 22 | use Tarantool\Client\Tests\Integration\FakeServer\Handler\WriteHandler; |
||||||
| 23 | use Tarantool\Client\Tests\Integration\TestCase; |
||||||
| 24 | |||||||
| 25 | final class ReadTest extends TestCase |
||||||
| 26 | { |
||||||
| 27 | public function testReadLargeResponse() : void |
||||||
| 28 | { |
||||||
| 29 | $str = str_repeat('x', 1024 * 1024); |
||||||
| 30 | $result = $this->client->evaluate('return ...', $str); |
||||||
|
0 ignored issues
–
show
The method
evaluate() does not exist on null.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||
| 31 | |||||||
| 32 | self::assertSame([$str], $result); |
||||||
| 33 | } |
||||||
| 34 | |||||||
| 35 | public function testReadEmptyGreeting() : void |
||||||
| 36 | { |
||||||
| 37 | $clientBuilder = ClientBuilder::createForFakeServer(); |
||||||
| 38 | |||||||
| 39 | FakeServerBuilder::create() |
||||||
| 40 | ->setUri($clientBuilder->getUri()) |
||||||
| 41 | ->start(); |
||||||
| 42 | |||||||
| 43 | $client = $clientBuilder->build(); |
||||||
| 44 | |||||||
| 45 | $this->expectException(CommunicationFailed::class); |
||||||
| 46 | $this->expectExceptionMessageMatches('/Error reading greeting:.+Unable to connect/i'); |
||||||
| 47 | |||||||
| 48 | $client->ping(); |
||||||
| 49 | } |
||||||
| 50 | |||||||
| 51 | public function testUnableToReadResponseLength() : void |
||||||
| 52 | { |
||||||
| 53 | $clientBuilder = ClientBuilder::createForFakeServer(); |
||||||
| 54 | |||||||
| 55 | FakeServerBuilder::create( |
||||||
| 56 | new WriteHandler(GreetingDataProvider::generateGreeting()), |
||||||
| 57 | new SleepHandler(1) |
||||||
| 58 | ) |
||||||
| 59 | ->setUri($clientBuilder->getUri()) |
||||||
| 60 | ->start(); |
||||||
| 61 | |||||||
| 62 | $client = $clientBuilder->build(); |
||||||
| 63 | |||||||
| 64 | $this->expectException(CommunicationFailed::class); |
||||||
| 65 | $this->expectExceptionMessageMatches('/Error reading response length:.+Unable to connect/i'); |
||||||
| 66 | |||||||
| 67 | $client->ping(); |
||||||
| 68 | } |
||||||
| 69 | |||||||
| 70 | public function testReadResponseLengthTimedOut() : void |
||||||
| 71 | { |
||||||
| 72 | $clientBuilder = ClientBuilder::createForFakeServer(); |
||||||
| 73 | $clientBuilder->setConnectionOptions(['socket_timeout' => 1]); |
||||||
| 74 | |||||||
| 75 | FakeServerBuilder::create( |
||||||
| 76 | new WriteHandler(GreetingDataProvider::generateGreeting()), |
||||||
| 77 | new SleepHandler(2) |
||||||
| 78 | ) |
||||||
| 79 | ->setUri($clientBuilder->getUri()) |
||||||
| 80 | ->start(); |
||||||
| 81 | |||||||
| 82 | $client = $clientBuilder->build(); |
||||||
| 83 | |||||||
| 84 | $this->expectException(CommunicationFailed::class); |
||||||
| 85 | $this->expectExceptionMessage('Read timed out'); |
||||||
| 86 | |||||||
| 87 | $client->ping(); |
||||||
| 88 | } |
||||||
| 89 | |||||||
| 90 | public function testUnableToReadResponse() : void |
||||||
| 91 | { |
||||||
| 92 | $clientBuilder = ClientBuilder::createForFakeServer(); |
||||||
| 93 | |||||||
| 94 | FakeServerBuilder::create( |
||||||
| 95 | new WriteHandler(GreetingDataProvider::generateGreeting()), |
||||||
| 96 | new WriteHandler(PacketLength::pack(42)), |
||||||
| 97 | new SleepHandler(1) |
||||||
| 98 | ) |
||||||
| 99 | ->setUri($clientBuilder->getUri()) |
||||||
| 100 | ->start(); |
||||||
| 101 | |||||||
| 102 | $client = $clientBuilder->build(); |
||||||
| 103 | |||||||
| 104 | $this->expectException(CommunicationFailed::class); |
||||||
| 105 | $this->expectExceptionMessageMatches('/Error reading response:.+Unable to connect/i'); |
||||||
| 106 | |||||||
| 107 | $client->ping(); |
||||||
| 108 | } |
||||||
| 109 | |||||||
| 110 | public function testSocketReadTimedOut() : void |
||||||
| 111 | { |
||||||
| 112 | $socketTimeout = 1.125; |
||||||
| 113 | |||||||
| 114 | $client = ClientBuilder::createFromEnv() |
||||||
| 115 | ->setConnectionOptions(['socket_timeout' => $socketTimeout]) |
||||||
| 116 | ->build(); |
||||||
| 117 | |||||||
| 118 | $start = microtime(true); |
||||||
| 119 | |||||||
| 120 | try { |
||||||
| 121 | $client->evaluate('require("fiber").sleep(2)'); |
||||||
| 122 | } catch (CommunicationFailed $e) { |
||||||
| 123 | $time = microtime(true) - $start; |
||||||
| 124 | self::assertSame('Read timed out', $e->getMessage()); |
||||||
| 125 | self::assertGreaterThanOrEqual($socketTimeout, $time); |
||||||
| 126 | self::assertLessThan($socketTimeout + 0.01, $time); |
||||||
| 127 | |||||||
| 128 | return; |
||||||
| 129 | } |
||||||
| 130 | |||||||
| 131 | self::fail(); |
||||||
| 132 | } |
||||||
| 133 | } |
||||||
| 134 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths