|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Bolt\tests; |
| 4 | + |
| 5 | +use Bolt\Bolt; |
| 6 | +use Bolt\connection\StreamSocket; |
| 7 | +use Bolt\error\ConnectException; |
| 8 | +use Exception; |
| 9 | +use PHPUnit\Framework\TestCase; |
| 10 | + |
| 11 | +final class SocketTest extends TestCase |
| 12 | +{ |
| 13 | + /** |
| 14 | + * @throws Exception |
| 15 | + */ |
| 16 | + public function testMillisecondTimeout(): void |
| 17 | + { |
| 18 | + $socket = new StreamSocket($GLOBALS['NEO_HOST'] ?? '127.0.0.1', (int) ($GLOBALS['NEO_PORT'] ?? 7687), 1.5); |
| 19 | + $bolt = new Bolt($socket); |
| 20 | + |
| 21 | + $bolt->init('Test/1.0', $GLOBALS['NEO_USER'], $GLOBALS['NEO_PASS']); |
| 22 | + |
| 23 | + $time = microtime(true); |
| 24 | + try { |
| 25 | + $bolt->run('FOREACH ( i IN range(1,10000) | |
| 26 | + MERGE (d:Day {day: i}) |
| 27 | +)'); |
| 28 | + } catch (ConnectException $e) { |
| 29 | + $newTime = microtime(true); |
| 30 | + |
| 31 | + $this->assertEqualsWithDelta(1.5, $newTime - $time, 0.2); |
| 32 | + } |
| 33 | + |
| 34 | + self::assertTrue(true); |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * @throws Exception |
| 39 | + */ |
| 40 | + public function testSecondsTimeout(): void |
| 41 | + { |
| 42 | + $socket = new StreamSocket($GLOBALS['NEO_HOST'] ?? '127.0.0.1', (int) ($GLOBALS['NEO_PORT'] ?? 7687), 1); |
| 43 | + $bolt = new Bolt($socket); |
| 44 | + $bolt->init('Test/1.0', $GLOBALS['NEO_USER'], $GLOBALS['NEO_PASS']); |
| 45 | + |
| 46 | + $time = microtime(true); |
| 47 | + try { |
| 48 | + $bolt->run('FOREACH ( i IN range(1,10000) | |
| 49 | + MERGE (d:Day {day: i}) |
| 50 | +)'); |
| 51 | + $this->assertTrue(false, 'No timeout error triggered'); |
| 52 | + } catch (ConnectException $e) { |
| 53 | + $newTime = microtime(true); |
| 54 | + |
| 55 | + $this->assertEqualsWithDelta(1.0, $newTime - $time, 0.2); |
| 56 | + } |
| 57 | + } |
| 58 | +} |
0 commit comments