Skip to content

Commit

Permalink
Fixed hung component tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyKleyman committed Mar 8, 2023
1 parent 791876a commit a6c4aa7
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,18 @@ final class ComponentTestsPhpUnitExtension extends PhpUnitExtensionBase implemen
/** @var Logger */
private $logger;

/** @var ?GlobalTestInfra */
/** @var GlobalTestInfra */
private static $globalTestInfra = null;

public function __construct()
{
parent::__construct(self::DBG_PROCESS_NAME);

// We spin off test infrastructure servers here and not on demand
// in self::getGlobalTestInfra() because PHPUnit might fork to run individual tests
// and ResourcesCleaner would track the PHPUnit child process as its master which would be wrong
self::$globalTestInfra = new GlobalTestInfra();

GlobalTracerHolder::setValue(NoopTracer::singletonInstance());

$this->logger = AmbientContextForTests::loggerFactory()->loggerForClass(
Expand All @@ -80,11 +85,16 @@ public function __construct()
)->addContext('appCodeHostKind', AmbientContextForTests::testConfig()->appCodeHostKind());
}

public function __destruct()
{
($loggerProxy = $this->logger->ifDebugLevelEnabled(__LINE__, __FUNCTION__))
&& $loggerProxy->log('Destroying...');

self::$globalTestInfra->getResourcesCleaner()->signalAndWaitForItToExit();
}

public static function getGlobalTestInfra(): GlobalTestInfra
{
if (self::$globalTestInfra === null) {
self::$globalTestInfra = new GlobalTestInfra();
}
return self::$globalTestInfra;
}

Expand Down

0 comments on commit a6c4aa7

Please sign in to comment.