55use Bolt \Bolt ;
66use Bolt \connection \StreamSocket ;
77use Bolt \error \ConnectException ;
8+ use Bolt \error \MessageException ;
9+ use Bolt \helpers \Auth ;
10+ use Bolt \protocol \V4 ;
811use Exception ;
912use PHPUnit \Framework \TestCase ;
13+ use function microtime ;
1014
1115final class StreamSocketTest extends TestCase
1216{
@@ -18,7 +22,7 @@ public function testMillisecondTimeout(): void
1822 $ socket = new StreamSocket ($ GLOBALS ['NEO_HOST ' ] ?? '127.0.0.1 ' , (int ) ($ GLOBALS ['NEO_PORT ' ] ?? 7687 ), 1.5 );
1923 $ bolt = new Bolt ($ socket );
2024 $ protocol = $ bolt ->build ();
21- $ protocol ->init (\ Bolt \ helpers \ Auth::basic ($ GLOBALS ['NEO_USER ' ], $ GLOBALS ['NEO_PASS ' ]));
25+ $ protocol ->init (Auth::basic ($ GLOBALS ['NEO_USER ' ], $ GLOBALS ['NEO_PASS ' ]));
2226
2327 $ time = microtime (true );
2428 try {
@@ -42,7 +46,7 @@ public function testSecondsTimeout(): void
4246 $ socket = new StreamSocket ($ GLOBALS ['NEO_HOST ' ] ?? '127.0.0.1 ' , (int ) ($ GLOBALS ['NEO_PORT ' ] ?? 7687 ), 1 );
4347 $ bolt = new Bolt ($ socket );
4448 $ protocol = $ bolt ->build ();
45- $ protocol ->init (\ Bolt \ helpers \ Auth::basic ($ GLOBALS ['NEO_USER ' ], $ GLOBALS ['NEO_PASS ' ]));
49+ $ protocol ->init (Auth::basic ($ GLOBALS ['NEO_USER ' ], $ GLOBALS ['NEO_PASS ' ]));
4650
4751 $ time = microtime (true );
4852 try {
@@ -56,4 +60,48 @@ public function testSecondsTimeout(): void
5660 $ this ->assertEqualsWithDelta (1.0 , $ newTime - $ time , 0.2 );
5761 }
5862 }
63+
64+ public function testTimeoutRecoverAndReset (): void
65+ {
66+ $ streamSocket = new StreamSocket ($ GLOBALS ['NEO_HOST ' ] ?? '127.0.0.1 ' , (int ) ($ GLOBALS ['NEO_PORT ' ] ?? 7687 ), 1 );
67+ /** @var V4 $protocol */
68+ $ protocol = (new Bolt ($ streamSocket ))->build ();
69+ $ protocol ->hello (Auth::basic ($ GLOBALS ['NEO_USER ' ], $ GLOBALS ['NEO_PASS ' ]));
70+
71+ $ time = microtime (true );
72+ try {
73+ $ protocol ->run ('FOREACH ( i IN range(1,10000) |
74+ MERGE (d:Day {day: i})
75+ ) ' );
76+ $ this ->fail ('No timeout error triggered ' );
77+ } catch (ConnectException $ e ) {
78+ $ newTime = microtime (true );
79+
80+ $ this ->assertEqualsWithDelta (1.0 , $ newTime - $ time , 0.2 );
81+ }
82+
83+ $ streamSocket ->setTimeout (100.0 );
84+ try {
85+ $ protocol ->reset ();
86+ } catch (MessageException $ e ) {
87+ echo $ e ->getMessage ();
88+ $ protocol = (new Bolt ($ streamSocket ))->build ();
89+ $ protocol ->hello (Auth::basic ($ GLOBALS ['NEO_USER ' ], $ GLOBALS ['NEO_PASS ' ]));
90+ }
91+ $ this ->assertTrue (true );
92+
93+ $ streamSocket ->setTimeout (1.0 );
94+
95+ $ time = microtime (true );
96+ try {
97+ $ protocol ->run ('FOREACH ( i IN range(1,10000) |
98+ MERGE (d:Day {day: i})
99+ ) ' );
100+ $ this ->fail ('No timeout error triggered ' );
101+ } catch (ConnectException $ e ) {
102+ $ newTime = microtime (true );
103+
104+ $ this ->assertEqualsWithDelta (1.0 , $ newTime - $ time , 0.2 );
105+ }
106+ }
59107}
0 commit comments