Skip to content

Commit

Permalink
Merge pull request #5344 from mhsdesign/task/fix-test-parallel
Browse files Browse the repository at this point in the history
TASK: Fix test parallel
  • Loading branch information
kitsunet authored Nov 8, 2024
2 parents 39266c8 + 702f69a commit 2a3e484
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 106 deletions.
2 changes: 0 additions & 2 deletions .composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
"../../bin/phpunit --colors --stop-on-failure -c ../../Build/BuildEssentials/PhpUnit/UnitTests.xml Neos.ContentRepositoryRegistry/Tests/Unit"
],
"test:parallel": [
"FLOW_CONTEXT=Testing/Behat ../../bin/paratest --debug -v --functional --group parallel --processes 2 --colors --stop-on-failure -c ../../Build/BuildEssentials/PhpUnit/FunctionalTests.xml Neos.ContentRepository.BehavioralTests/Tests/Functional/Feature/WorkspacePublication/WorkspaceWritingDuringPublication.php",
"FLOW_CONTEXT=Testing/Behat ../../bin/paratest --debug -v --functional --group parallel --processes 2 --colors --stop-on-failure -c ../../Build/BuildEssentials/PhpUnit/FunctionalTests.xml Neos.ContentRepository.BehavioralTests/Tests/Functional/Feature/WorkspacePublication/WorkspaceWritingDuringPublication.php",
"FLOW_CONTEXT=Testing/Behat ../../bin/paratest --debug -v --functional --group parallel --processes 2 --colors --stop-on-failure -c ../../Build/BuildEssentials/PhpUnit/FunctionalTests.xml Neos.ContentRepository.BehavioralTests/Tests/Functional/Feature/WorkspacePublication/WorkspaceWritingDuringPublication.php"
],
"test:behat-cli": "../../bin/behat -f progress --strict --no-interaction",
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,14 @@ jobs:
FLOW_CONTEXT=Testing ./flow doctrine:migrate --quiet
bin/phpunit --colors --stop-on-failure -c Build/BuildEssentials/PhpUnit/FunctionalTests.xml --testsuite "Neos tests" --verbose
- name: Run Parallel Tests for the ES CR
if: matrix.parallel-parts == 'escr-behavioral'
run: |
cd Packages/Neos
hasFailure=0
composer test:parallel || hasFailure=1
cat Neos.ContentRepository.BehavioralTests/Tests/Parallel/log.txt
exit $hasFailure
- name: Run Behavioral Tests (ES CR && Neos.Neos)
id: escrtests
if: matrix.parallel-parts == 'escr-behavioral'
Expand Down
17 changes: 17 additions & 0 deletions Neos.ContentRepository.BehavioralTests/Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@ Neos:
host: 127.0.0.1
port: 6379

ContentRepositoryRegistry:
contentRepositories:
test_parallel:
eventStore:
factoryObjectName: Neos\ContentRepositoryRegistry\Factory\EventStore\DoctrineEventStoreFactory
nodeTypeManager:
factoryObjectName: Neos\ContentRepository\BehavioralTests\TestSuite\Behavior\GherkinPyStringNodeBasedNodeTypeManagerFactory
contentDimensionSource:
factoryObjectName: Neos\ContentRepository\BehavioralTests\TestSuite\Behavior\GherkinTableNodeBasedContentDimensionSourceFactory
userIdProvider:
factoryObjectName: Neos\ContentRepositoryRegistry\Factory\UserIdProvider\StaticUserIdProviderFactory
clock:
factoryObjectName: Neos\ContentRepositoryRegistry\Factory\Clock\SystemClockFactory
propertyConverters: {}
contentGraphProjection:
factoryObjectName: Neos\ContentGraph\DoctrineDbalAdapter\DoctrineDbalContentGraphProjectionFactory

Flow:
object:
includeClasses:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*
!*/
!*.php
!.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

/*
* This file is part of the Neos.ContentRepository.BehavioralTests package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/

declare(strict_types=1);

namespace Neos\ContentRepository\BehavioralTests\Tests\Parallel;

use Doctrine\DBAL\Connection;
use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Core\Bootstrap;
use Neos\Flow\ObjectManagement\ObjectManagerInterface;
use PHPUnit\Framework\TestCase;

/**
* Abstract parallel test cases
*/
abstract class AbstractParallelTestCase extends TestCase // we don't use Flows functional test case as it would reset the database afterwards (see FlowEntitiesTrait)
{
private const LOGGING_PATH = __DIR__ . '/log.txt';

protected ContentRepositoryRegistry $contentRepositoryRegistry;

protected ObjectManagerInterface $objectManager;

public function setUp(): void
{
$this->objectManager = Bootstrap::$staticObjectManager;
$this->contentRepositoryRegistry = $this->objectManager->get(ContentRepositoryRegistry::class);
}

final protected function awaitFile(string $filename): void
{
$waiting = 0;
while (!is_file($filename)) {
usleep(1000);
$waiting++;
clearstatcache(true, $filename);
if ($waiting > 60000) {
throw new \Exception('timeout while waiting on file ' . $filename);
}
}
}

final protected function awaitSharedLock($resource, int $maximumCycles = 2000): void
{
$waiting = 0;
while (!flock($resource, LOCK_SH)) {
usleep(10000);
$waiting++;
if ($waiting > $maximumCycles) {
throw new \Exception('timeout while waiting on shared lock');
}
}
}

final protected function setUpContentRepository(
ContentRepositoryId $contentRepositoryId
): ContentRepository {
$contentRepository = $this->contentRepositoryRegistry->get($contentRepositoryId);
$contentRepository->setUp();

$connection = $this->objectManager->get(Connection::class);

// reset events and projections
$eventTableName = sprintf('cr_%s_events', $contentRepositoryId->value);
$connection->executeStatement('TRUNCATE ' . $eventTableName);
$contentRepository->resetProjectionStates();

return $contentRepository;
}

final protected function log(string $message): void
{
file_put_contents(self::LOGGING_PATH, substr($this::class, strrpos($this::class, '\\') + 1) . ': ' . getmypid() . ': ' . $message . PHP_EOL, FILE_APPEND);
}
}
Loading

0 comments on commit 2a3e484

Please sign in to comment.