|
3 | 3 | namespace Bolt\tests; |
4 | 4 |
|
5 | 5 | use Bolt\Bolt; |
6 | | -use Bolt\connection\StreamSocket; |
| 6 | +use Bolt\connection\Socket; |
7 | 7 | use Bolt\helpers\Auth; |
8 | 8 | use Bolt\protocol\{ |
9 | 9 | AProtocol, |
| 10 | + Response, |
10 | 11 | V1, |
11 | 12 | V2, |
12 | 13 | V3, |
|
18 | 19 | V5 |
19 | 20 | }; |
20 | 21 | use Bolt\tests\packstream\v1\generators\RandomDataGenerator; |
21 | | -use PHPUnit\Framework\TestCase; |
22 | 22 |
|
23 | 23 | /** |
24 | 24 | * Class PerformanceTest |
25 | 25 | * @author Ghlen Nagels |
26 | 26 | * @link https://github.com/neo4j-php/Bolt |
27 | 27 | * @package Bolt\tests |
28 | 28 | */ |
29 | | -class PerformanceTest extends TestCase |
| 29 | +class PerformanceTest extends ATest |
30 | 30 | { |
31 | 31 | public function test50KRecords(): void |
32 | 32 | { |
33 | 33 | $amount = 50000; |
34 | 34 |
|
35 | | - $conn = new StreamSocket($GLOBALS['NEO_HOST'] ?? 'localhost', $GLOBALS['NEO_PORT'] ?? 7687, 60); |
| 35 | + $conn = new Socket($GLOBALS['NEO_HOST'] ?? 'localhost', $GLOBALS['NEO_PORT'] ?? 7687, 60); |
36 | 36 | /** @var AProtocol|V1|V2|V3|V4|V4_1|V4_2|V4_3|V4_4|V5 $protocol */ |
37 | 37 | $protocol = (new Bolt($conn))->build(); |
38 | 38 | $this->assertEquals(\Bolt\protocol\Response::SIGNATURE_SUCCESS, $protocol->hello(Auth::basic($GLOBALS['NEO_USER'], $GLOBALS['NEO_PASS']))->getSignature()); |
39 | 39 |
|
| 40 | + //prevent multiple runs at once |
| 41 | + while (true) { |
| 42 | + $protocol->run('MATCH (n:Test50k) RETURN count(n)')->getResponse(); |
| 43 | + $response = $protocol->pull()->getResponse(); |
| 44 | + if ($response !== Response::SIGNATURE_RECORD) |
| 45 | + $this->markTestSkipped(); |
| 46 | + $runs = $response->getContent()[0]; |
| 47 | + $protocol->getResponse(); |
| 48 | + if ($runs > 0) { |
| 49 | + sleep(60); |
| 50 | + } else { |
| 51 | + $protocol->run('CREATE (n:Test50k)')->getResponse(); |
| 52 | + break; |
| 53 | + } |
| 54 | + } |
| 55 | + |
40 | 56 | $generator = new RandomDataGenerator($amount); |
41 | 57 | $protocol |
42 | 58 | ->run('UNWIND $x as x RETURN x', ['x' => $generator]) |
43 | 59 | ->getResponse(); |
44 | 60 |
|
45 | | - $count = 0; |
46 | | - while (true) { |
47 | | - $gen = $protocol |
48 | | - ->pull(['n' => 1]) |
49 | | - ->getResponses(); |
50 | | - |
51 | | - if ($gen->current()->getSignature() != \Bolt\protocol\Response::SIGNATURE_RECORD) |
52 | | - $this->markTestIncomplete('Response does not contains record message'); |
53 | | - |
54 | | - $gen->next(); |
55 | | - |
56 | | - if ($gen->current()->getSignature() != \Bolt\protocol\Response::SIGNATURE_SUCCESS) |
57 | | - $this->markTestIncomplete('Response does not contains success message'); |
58 | 61 |
|
59 | | - $count++; |
60 | | - |
61 | | - if ($gen->current()->getContent()['has_more'] ?? false) |
62 | | - continue; |
63 | | - else |
64 | | - break; |
| 62 | + $iterator = $protocol->pull()->getResponses(); |
| 63 | + $count = 0; |
| 64 | + /** @var Response $response */ |
| 65 | + foreach ($iterator as $response) { |
| 66 | + if ($response->getSignature() === Response::SIGNATURE_RECORD) |
| 67 | + $count++; |
65 | 68 | } |
66 | 69 |
|
| 70 | + $protocol->run('MATCH (n:Test50k) DELETE n'); |
67 | 71 | $this->assertEquals($amount, $count); |
68 | 72 | } |
69 | 73 | } |
0 commit comments