Skip to content

Commit b749528

Browse files
committed
added performance test for 50k rows
1 parent cafb5d5 commit b749528

File tree

3 files changed

+82
-1
lines changed

3 files changed

+82
-1
lines changed

src/protocol/V3.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function run(...$args): array
7373
$this->write($this->packer->pack(
7474
0x10,
7575
$args[0],
76-
$args[1] ?? [],
76+
(object)($args[1] ?? []),
7777
(object)($args[2] ?? [])
7878
));
7979
$message = $this->read($signature);
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace Bolt\tests\PackStream\v1\generators;
4+
5+
use Bolt\PackStream\IPackListGenerator;
6+
use function bin2hex;
7+
use function hex2bin;
8+
use function random_bytes;
9+
10+
class RandomDataGenerator implements IPackListGenerator
11+
{
12+
private int $rows;
13+
private int $count = 0;
14+
15+
public function __construct(int $rows)
16+
{
17+
$this->rows = $rows;
18+
}
19+
20+
public function current(): array
21+
{
22+
return [bin2hex(random_bytes(0x20)) => bin2hex(random_bytes(0x800))];
23+
}
24+
25+
public function next(): void
26+
{
27+
++$this->count;
28+
}
29+
30+
public function key(): int
31+
{
32+
return $this->count;
33+
}
34+
35+
public function valid(): bool
36+
{
37+
return $this->count < $this->rows;
38+
}
39+
40+
public function rewind(): void
41+
{
42+
$this->count = 0;
43+
}
44+
45+
public function count(): int
46+
{
47+
return $this->rows;
48+
}
49+
}

tests/PerformanceTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Bolt\tests;
4+
5+
use Bolt\Bolt;
6+
use Bolt\connection\StreamSocket;
7+
use Bolt\helpers\Auth;
8+
use Bolt\tests\PackStream\v1\generators\RandomDataGenerator;
9+
use PHPUnit\Framework\TestCase;
10+
11+
class PerformanceTest extends TestCase
12+
{
13+
public function test50KRecords(): void
14+
{
15+
$amount = 50000;
16+
17+
$conn = new StreamSocket($GLOBALS['NEO_HOST'] ?? 'localhost', $GLOBALS['NEO_PORT'] ?? 7687);
18+
$protocol = (new Bolt($conn))->build();
19+
$this->assertNotEmpty($protocol->init(Auth::basic($GLOBALS['NEO_USER'], $GLOBALS['NEO_PASS'])));
20+
21+
$generator = new RandomDataGenerator($amount);
22+
$protocol->run('UNWIND $x as x RETURN x', ['x' => $generator]);
23+
24+
$count = 0;
25+
while ($count < $amount) {
26+
++$count;
27+
$protocol->pull(['n' => 1]);
28+
}
29+
30+
$this->assertEquals($amount, $count);
31+
}
32+
}

0 commit comments

Comments
 (0)