Skip to content

Commit

Permalink
TASK speedup behavioral test by ninety-three percent
Browse files Browse the repository at this point in the history
With this change we setup the content repository only once for all tests `$contentRepository->setUp();`.
The projections contents are cleared in each iteration via `$contentRepository->resetProjectionStates();` and this works quite well for the escr core tests.
For tests using the `@flowEntities` annotation and database reset we must avoid to drop all the escr tables as otherwise we would need to setup the cr again. This will be fixed in neos/behat#37.

Why are we going through so much hassle to (hackily) setup the cr only once? Because each projection calls `$schemaManager->createSchema()` twice when being setup and this slows down test enormously by 80%
  • Loading branch information
mhsdesign committed Nov 17, 2023
1 parent a439234 commit 7f319fc
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ trait CRBehavioralTestsSubjectProvider
* A runtime cache of all content repositories already set up, represented by their ID
* @var array<ContentRepositoryId>
*/
protected array $alreadySetUpContentRepositories = [];
protected static array $alreadySetUpContentRepositories = [];

protected ?ContentRepository $currentContentRepository = null;

Expand Down Expand Up @@ -169,8 +169,9 @@ protected function setUpContentRepository(ContentRepositoryId $contentRepository
* Catch Up process and the testcase reset.
*/
$contentRepository = $this->createContentRepository($contentRepositoryId);
if (!in_array($contentRepository->id, $this->alreadySetUpContentRepositories)) {
if (!in_array($contentRepository->id, self::$alreadySetUpContentRepositories)) {
$contentRepository->setUp();
self::$alreadySetUpContentRepositories[] = $contentRepository->id;
}
/** @var EventStoreInterface $eventStore */
$eventStore = (new \ReflectionClass($contentRepository))->getProperty('eventStore')->getValue($contentRepository);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,13 @@ trait CRTestSuiteTrait
use WorkspaceDiscarding;
use WorkspacePublishing;

protected function setupCRTestSuiteTrait(bool $alwaysRunCrSetup = false): void
protected function setupCRTestSuiteTrait(): void
{
if (getenv('CATCHUPTRIGGER_ENABLE_SYNCHRONOUS_OPTION')) {
CatchUpTriggerWithSynchronousOption::enableSynchronicityForSpeedingUpTesting();
}
}

private static bool $wasContentRepositorySetupCalled = false;

/**
* @BeforeScenario
* @throws \Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ trait CRRegistrySubjectProvider
/**
* @var array<ContentRepositoryId>
*/
protected array $alreadySetUpContentRepositories = [];
protected static array $alreadySetUpContentRepositories = [];

/**
* @template T of object
Expand Down Expand Up @@ -62,8 +62,9 @@ public function iInitializeContentRepository(string $contentRepositoryId): void
$eventTableName = sprintf('cr_%s_events', $contentRepositoryId);
$databaseConnection->executeStatement('TRUNCATE ' . $eventTableName);

if (!in_array($contentRepository->id, $this->alreadySetUpContentRepositories)) {
if (!in_array($contentRepository->id, self::$alreadySetUpContentRepositories)) {
$contentRepository->setUp();
self::$alreadySetUpContentRepositories[] = $contentRepository->id;
}
$contentRepository->resetProjectionStates();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*/

use Behat\Behat\Context\Context as BehatContext;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Neos\Behat\FlowBootstrapTrait;
use Neos\Behat\FlowEntitiesTrait;
use Neos\ContentRepository\BehavioralTests\TestSuite\Behavior\CRBehavioralTestsSubjectProvider;
Expand Down Expand Up @@ -50,7 +49,7 @@ public function __construct()
$this->environment = $this->getObject(Environment::class);
$this->contentRepositoryRegistry = $this->getObject(ContentRepositoryRegistry::class);

$this->setupCRTestSuiteTrait(true);
$this->setupCRTestSuiteTrait();
}

/*
Expand All @@ -63,7 +62,7 @@ public function __construct()
/**
* @BeforeScenario
*/
public function resetContentRepositoryComponents(BeforeScenarioScope $scope): void
public function resetContentRepositoryComponents(): void
{
GherkinTableNodeBasedContentDimensionSourceFactory::reset();
GherkinPyStringNodeBasedNodeTypeManagerFactory::reset();
Expand Down

0 comments on commit 7f319fc

Please sign in to comment.