Skip to content

Commit

Permalink
Merge pull request #9 from neos/task/concurrency-tests
Browse files Browse the repository at this point in the history
TASK: Concurrency tests
  • Loading branch information
bwaidelich authored Jan 15, 2024
2 parents 46d74af + 8345fe4 commit b63b32c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
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

0 comments on commit b63b32c

Please sign in to comment.