ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
MigratedLanguageFileSyncLockTestCase Class Reference

Fixture of the MigratedLanguageFileSyncLock*Test classes: a throwaway client data directory and the helpers to run lock scenarios in child PHP processes. More...

+ Inheritance diagram for MigratedLanguageFileSyncLockTestCase:
+ Collaboration diagram for MigratedLanguageFileSyncLockTestCase:

Protected Member Functions

 setUp ()
 
 tearDown ()
 
 lockFile ()
 
 seedLockDirectory ()
 Forces withOverlayLock() to take a real lock without needing a shipped .po: the overlay directory already existing is enough (see withOverlayLock()'s early-return condition). More...
 
 runPhpWithTimeout (string $code, float $timeout_seconds)
 Runs $code in a child PHP process and kills it after $timeout_seconds, so a regression that deadlocks fails the test instead of hanging the suite. More...
 

Protected Attributes

const string MODULE = 'stest'
 
string $client_data_dir
 
LanguageFileDirectory $directory
 
LanguageFileDirectoryManager $manager
 

Detailed Description

Fixture of the MigratedLanguageFileSyncLock*Test classes: a throwaway client data directory and the helpers to run lock scenarios in child PHP processes.

Definition at line 30 of file MigratedLanguageFileSyncLockTestCase.php.

Member Function Documentation

◆ lockFile()

MigratedLanguageFileSyncLockTestCase::lockFile ( )
protected

Definition at line 65 of file MigratedLanguageFileSyncLockTestCase.php.

65 : string
66 {
67 return MigratedPoFixture::overlayLock(MigratedPoFixture::overlayBase($this->client_data_dir, $this->directory, 'de'));
68 }
static overlayLock(string $base_path)
static overlayBase(string $client_data_dir, LanguageFileDirectory $directory, string $lang_key)
The overlay of $directory's module for $lang_key without the .po extension.

References MigratedPoFixture\overlayBase(), and MigratedPoFixture\overlayLock().

Referenced by seedLockDirectory().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ runPhpWithTimeout()

MigratedLanguageFileSyncLockTestCase::runPhpWithTimeout ( string  $code,
float  $timeout_seconds 
)
protected

Runs $code in a child PHP process and kills it after $timeout_seconds, so a regression that deadlocks fails the test instead of hanging the suite.

Returns
array{finished: bool, exit_code: ?int, output: string}

Definition at line 85 of file MigratedLanguageFileSyncLockTestCase.php.

85 : array
86 {
87 $started = ChildPhp::open(['-r', $code]);
88 if ($started === null) {
89 $this->fail('Could not start the child PHP process.');
90 }
91 [$process, $pipes] = $started;
92 stream_set_blocking($pipes[1], false);
93 stream_set_blocking($pipes[2], false);
94
95 $deadline = microtime(true) + $timeout_seconds;
96 $output = '';
97 do {
98 $output .= (string) stream_get_contents($pipes[1]);
99 $output .= (string) stream_get_contents($pipes[2]);
100 $status = proc_get_status($process);
101 if (!$status['running']) {
102 fclose($pipes[1]);
103 fclose($pipes[2]);
104 proc_close($process);
105
106 return ['finished' => true, 'exit_code' => $status['exitcode'], 'output' => $output];
107 }
108 usleep(20_000);
109 } while (microtime(true) < $deadline);
110
111 proc_terminate($process, 9);
112 usleep(100_000);
113 $output .= (string) stream_get_contents($pipes[1]);
114 $output .= (string) stream_get_contents($pipes[2]);
115 fclose($pipes[1]);
116 fclose($pipes[2]);
117 proc_close($process);
118
119 return ['finished' => false, 'exit_code' => null, 'output' => $output];
120 }
static open(array $arguments, ?string $working_directory=null)
Definition: ChildPhp.php:43

References ChildPhp\open().

+ Here is the call graph for this function:

◆ seedLockDirectory()

MigratedLanguageFileSyncLockTestCase::seedLockDirectory ( )
protected

Forces withOverlayLock() to take a real lock without needing a shipped .po: the overlay directory already existing is enough (see withOverlayLock()'s early-return condition).

Definition at line 74 of file MigratedLanguageFileSyncLockTestCase.php.

74 : void
75 {
76 mkdir(dirname($this->lockFile()), 0775, true);
77 }

References lockFile().

+ Here is the call graph for this function:

◆ setUp()

MigratedLanguageFileSyncLockTestCase::setUp ( )
protected

Definition at line 42 of file MigratedLanguageFileSyncLockTestCase.php.

42 : void
43 {
44 // never the build of the installation, see MigratedPoFixture::resetRuntime()
47
48 if (!defined('ILIAS_ABSOLUTE_PATH')) {
49 define('ILIAS_ABSOLUTE_PATH', realpath(__DIR__ . '/../../../../../'));
50 }
51
52 $this->client_data_dir = sys_get_temp_dir() . '/ilias_mlfs_lock_test_' . bin2hex(random_bytes(4));
53 mkdir($this->client_data_dir, 0775, true);
54 $this->directory = MigratedPoFixture::directory(self::MODULE, 'x/');
55 $this->manager = new LanguageFileDirectoryManager(new CustomizingLanguageFileDirectory(), $this->directory);
56 }
static directory(string $prefix, string $path, bool $local=false)
static resetRuntime(?string $artifact_directory=null)
Forgets the static state of the runtime read path and points build and runtime at $artifact_directory...

References MigratedPoFixture\directory(), MigratedPoFixture\resetRuntime(), and setUp().

+ Here is the call graph for this function:

◆ tearDown()

MigratedLanguageFileSyncLockTestCase::tearDown ( )
protected

Definition at line 58 of file MigratedLanguageFileSyncLockTestCase.php.

58 : void
59 {
60 MigratedPoFixture::removeDirectory($this->client_data_dir);
61
63 }
static removeDirectory(string $directory)

References MigratedPoFixture\removeDirectory(), and tearDown().

+ Here is the call graph for this function:

Field Documentation

◆ $client_data_dir

string MigratedLanguageFileSyncLockTestCase::$client_data_dir
protected

Definition at line 36 of file MigratedLanguageFileSyncLockTestCase.php.

◆ $directory

LanguageFileDirectory MigratedLanguageFileSyncLockTestCase::$directory
protected

Definition at line 38 of file MigratedLanguageFileSyncLockTestCase.php.

◆ $manager

LanguageFileDirectoryManager MigratedLanguageFileSyncLockTestCase::$manager
protected

Definition at line 40 of file MigratedLanguageFileSyncLockTestCase.php.

◆ MODULE

const string MigratedLanguageFileSyncLockTestCase::MODULE = 'stest'
protected

Definition at line 34 of file MigratedLanguageFileSyncLockTestCase.php.


The documentation for this class was generated from the following file: