Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TASK: Concurrency tests #9

Merged
merged 2 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,17 @@
"test:phpstan": "phpstan",
"test:cs": "phpcs --colors src",
"test:cs:fix": "phpcbf --colors src",
"test:integration": "phpunit tests/Integration",
"test:integration": "phpunit tests/Integration --exclude-group=parallel",
"test:consistency": [
"Neos\\EventStore\\DoctrineAdapter\\Tests\\Integration\\DoctrineEventStoreTest::prepare",
"paratest tests/Integration --group=parallel --functional --processes 10",
"Neos\\EventStore\\DoctrineAdapter\\Tests\\Integration\\DoctrineEventStoreTest::consistency_validateEvents"
],
"test": [
"@test:phpstan",
"@test:cs",
"@test:integration"
"@test:integration",
"@test:consistency"
]
}
}
5 changes: 5 additions & 0 deletions src/DoctrineEventStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\Exception as DriverException;
use Doctrine\DBAL\Exception as DbalException;
use Doctrine\DBAL\Exception\DeadlockException;
use Doctrine\DBAL\Exception\LockWaitTimeoutException;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use Doctrine\DBAL\Result;
use Doctrine\DBAL\Schema\Comparator;
Expand Down Expand Up @@ -108,6 +110,9 @@ public function commit(StreamName $streamName, Events $events, ExpectedVersion $
$retryWaitInterval *= 2;
$this->connection->rollBack();
continue;
} catch (DeadlockException | LockWaitTimeoutException $exception) {
$this->connection->rollBack();
throw new ConcurrencyException($exception->getMessage(), 1705330559, $exception);
} catch (DbalException | ConcurrencyException | \JsonException $exception) {
$this->connection->rollBack();
throw $exception;
Expand Down
11 changes: 6 additions & 5 deletions tests/Integration/DoctrineEventStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ final class DoctrineEventStoreTest extends AbstractEventStoreTestBase
{
private static ?Connection $connection = null;

protected function createEventStore(): EventStoreInterface
protected static function createEventStore(): EventStoreInterface
{
$connection = self::connection();
$eventStore = new DoctrineEventStore($connection, self::eventTableName());
$eventStore->setup();
return new DoctrineEventStore(self::connection(), self::eventTableName());
}

protected static function resetEventStore(): void
{
$connection = self::connection();
if ($connection->getDatabasePlatform() instanceof SqlitePlatform) {
$connection->executeStatement('DELETE FROM ' . self::eventTableName());
$connection->executeStatement('UPDATE SQLITE_SEQUENCE SET SEQ=0 WHERE NAME="' . self::eventTableName() . '"');
Expand All @@ -32,7 +34,6 @@ protected function createEventStore(): EventStoreInterface
} else {
$connection->executeStatement('TRUNCATE TABLE ' . self::eventTableName());
}
return $eventStore;
}

public static function connection(): Connection
Expand Down