Passed
Pull Request — master (#63)
by Eugene
03:45
created

TcpNoDelayTest::testTcpNoDelayDisabled()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 9
nc 2
nop 0
dl 0
loc 16
rs 9.9666
c 1
b 0
f 1
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\Tests\Integration\ClientBuilder;
17
use Tarantool\Client\Tests\Integration\TestCase;
18
19
/**
20
 * @requires extension sockets
21
 */
22
final class TcpNoDelayTest extends TestCase
23
{
24
    public function testTcpNoDelayEnabled() : void
25
    {
26
        $builder = ClientBuilder::createFromEnv()
27
            ->setConnectionOptions(['tcp_nodelay' => true]);
28
29
        if (!$builder->isTcpConnection()) {
30
            self::markTestSkipped(sprintf('For the tcp connections only (current: "%s")', $builder->getUri()));
31
        }
32
33
        $client = $builder->build();
34
        $client->ping();
35
36
        $connection = $client->getHandler()->getConnection();
37
        $socket = socket_import_stream(self::getRawStream($connection));
38
39
        self::assertSame(1, socket_get_option($socket, SOL_TCP, TCP_NODELAY));
40
    }
41
42
    public function testTcpNoDelayDisabled() : void
43
    {
44
        $builder = ClientBuilder::createFromEnv()
45
            ->setConnectionOptions(['tcp_nodelay' => false]);
46
47
        if (!$builder->isTcpConnection()) {
48
            self::markTestSkipped(sprintf('For the tcp connections only (current: "%s")', $builder->getUri()));
49
        }
50
51
        $client = $builder->build();
52
        $client->ping();
53
54
        $connection = $client->getHandler()->getConnection();
55
        $socket = socket_import_stream(self::getRawStream($connection));
56
57
        self::assertSame(0, socket_get_option($socket, SOL_TCP, TCP_NODELAY));
58
    }
59
}
60