Skip to content

Commit 48ec92f

Browse files
committed
Merge branch 'main' into transaction-commit-bug
2 parents 573a689 + 4856902 commit 48ec92f

File tree

6 files changed

+97
-4
lines changed

6 files changed

+97
-4
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
"vlucas/phpdotenv": "^5.0",
5454
"psr/container": "^1.1",
5555
"lctrs/psalm-psr-container-plugin": "^1.3",
56-
"symfony/uid": "^5.0"
56+
"symfony/uid": "^5.0",
57+
"symfony/var-dumper": "^5.0"
5758
},
5859
"autoload": {
5960
"psr-4": {

src/Bolt/Session.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ private function beginInstantTransaction(
160160
private function acquireConnection(TransactionConfiguration $config, SessionConfiguration $sessionConfig): BoltConnection
161161
{
162162
$connection = $this->pool->acquire($this->uri, $this->auth, $sessionConfig);
163-
$connection->setTimeout($config->getTimeout());
163+
// We try and let the server do the timeout management.
164+
// Since the client should not run indefinitely, we just multiply the client side by two, just in case
165+
$connection->setTimeout($config->getTimeout() * 2);
164166

165167
return $connection;
166168
}

src/Types/AbstractCypherSequence.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
use function array_key_exists;
1717
use function array_reverse;
1818
use ArrayAccess;
19+
use ArrayIterator;
1920
use BadMethodCallException;
2021
use function call_user_func;
2122
use function count;
2223
use Countable;
24+
use function get_object_vars;
2325
use function implode;
2426
use const INF;
2527
use function is_array;
@@ -533,4 +535,16 @@ protected function isStringable($key): bool
533535
{
534536
return is_string($key) || is_numeric($key) || (is_object($key) && method_exists($key, '__toString'));
535537
}
538+
539+
public function __serialize(): array
540+
{
541+
$this->preload();
542+
543+
$tbr = get_object_vars($this);
544+
$tbr['generator'] = new ArrayIterator($this->cache);
545+
$tbr['currentPosition'] = 0;
546+
$tbr['generatorPosition'] = 0;
547+
548+
return $tbr;
549+
}
536550
}

tests/Integration/ComplexQueryTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,52 @@ public function testLongQueryUnmanaged(string $alias): void
376376
$tsx->run('CALL apoc.util.sleep(10000)');
377377
}
378378

379+
/**
380+
* @dataProvider connectionAliases
381+
*/
382+
public function testSimpleTimeout(string $alias): void
383+
{
384+
if (str_starts_with($alias, 'http')) {
385+
self::markTestSkipped('Http does not support timeouts at the moment');
386+
}
387+
388+
try {
389+
$this->getClient()
390+
->getDriver($alias)
391+
->createSession()
392+
->run(
393+
"MATCH (n:Node) SET n.testing = 'hello' WITH * CALL apoc.util.sleep(2000000)",
394+
[],
395+
TransactionConfiguration::default()->withTimeout(10)
396+
);
397+
} catch (Neo4jException $e) {
398+
self::assertEquals('Neo.ClientError.Transaction.TransactionTimedOut', $e->getNeo4jCode());
399+
}
400+
}
401+
402+
/**
403+
* @dataProvider connectionAliases
404+
*/
405+
public function testDiscardAfterTimeout(string $alias): void
406+
{
407+
if (str_starts_with($alias, 'http')) {
408+
self::markTestSkipped('Http does not support timeouts at the moment');
409+
}
410+
411+
$this->expectException(Neo4jException::class);
412+
413+
$result = $this->getClient()
414+
->getDriver($alias)
415+
->createSession()
416+
->run(
417+
"MATCH (n:Node) SET n.testing = 'hello' WITH * CALL apoc.util.sleep(2000000)",
418+
[],
419+
TransactionConfiguration::default()->withTimeout(150)
420+
);
421+
422+
unset($result);
423+
}
424+
379425
/**
380426
* @dataProvider connectionAliases
381427
*/

tests/Integration/SummarizedResultFormatterTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace Laudis\Neo4j\Tests\Integration;
1515

1616
use function bin2hex;
17+
use function dump;
1718
use Exception;
1819
use Laudis\Neo4j\Contracts\FormatterInterface;
1920
use Laudis\Neo4j\Contracts\TransactionInterface;
@@ -23,6 +24,8 @@
2324
use Laudis\Neo4j\Types\CypherList;
2425
use Laudis\Neo4j\Types\CypherMap;
2526
use function random_bytes;
27+
use function serialize;
28+
use function unserialize;
2629

2730
/**
2831
* @psalm-import-type OGMTypes from \Laudis\Neo4j\Formatter\OGMFormatter
@@ -82,4 +85,30 @@ public function testGetResults(string $alias): void
8285
self::assertInstanceOf(CypherMap::class, $first);
8386
self::assertEquals(1, $first->get('one'));
8487
}
88+
89+
/**
90+
* @dataProvider connectionAliases
91+
*/
92+
public function testSerialize(string $alias): void
93+
{
94+
$results = $this->getClient()->run('RETURN 1 AS one', [], $alias);
95+
96+
$serialise = serialize($results);
97+
$resultHasBeenSerialized = unserialize($serialise);
98+
99+
self::assertInstanceOf(SummarizedResult::class, $resultHasBeenSerialized);
100+
self::assertEquals($results->toRecursiveArray(), $resultHasBeenSerialized->toRecursiveArray());
101+
}
102+
103+
/**
104+
* @dataProvider connectionAliases
105+
*
106+
* @doesNotPerformAssertions
107+
*/
108+
public function testDump(string $alias): void
109+
{
110+
$results = $this->getClient()->run('RETURN 1 AS one', [], $alias);
111+
112+
dump($results);
113+
}
85114
}

tests/Integration/TransactionIntegrationTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Laudis\Neo4j\Formatter\BasicFormatter;
2222
use ReflectionClass;
2323
use function str_starts_with;
24+
use Throwable;
2425

2526
/**
2627
* @psalm-import-type BasicResults from \Laudis\Neo4j\Formatter\BasicFormatter
@@ -308,7 +309,7 @@ public function testCommitInvalid(string $alias): void
308309
$exception = false;
309310
try {
310311
$tsx->commit();
311-
} catch (Neo4jException $e) {
312+
} catch (Throwable $e) {
312313
$exception = true;
313314
}
314315
self::assertTrue($exception);
@@ -354,7 +355,7 @@ public function testRollbackInvalid(string $alias): void
354355
$exception = false;
355356
try {
356357
$tsx->rollback();
357-
} catch (Neo4jException $e) {
358+
} catch (Throwable $e) {
358359
$exception = true;
359360
}
360361
self::assertTrue($exception);

0 commit comments

Comments
 (0)