Skip to content

Commit 2472b4f

Browse files
committed
tests: added garbage collector to bootstrap
1 parent 2dc6bbe commit 2472b4f

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

tests/bootstrap.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,20 @@
1818

1919

2020
// create temporary directory
21-
define('TEMP_DIR', __DIR__ . '/tmp/' . getmypid());
22-
@mkdir(dirname(TEMP_DIR)); // @ - directory may already exist
23-
Tester\Helpers::purge(TEMP_DIR);
21+
(function () {
22+
define('TEMP_DIR', __DIR__ . '/tmp/' . getmypid());
23+
24+
// garbage collector
25+
$GLOBALS['\\lock'] = $lock = fopen(__DIR__ . '/lock', 'w');
26+
if (rand(0, 100)) {
27+
flock($lock, LOCK_SH);
28+
@mkdir(dirname(TEMP_DIR));
29+
} elseif (flock($lock, LOCK_EX)) {
30+
Tester\Helpers::purge(dirname(TEMP_DIR));
31+
}
32+
33+
@mkdir(TEMP_DIR);
34+
})();
2435

2536

2637
if (extension_loaded('xdebug')) {

0 commit comments

Comments
 (0)