Skip to content

Commit da4f888

Browse files
committed
tests: added garbage collector to bootstrap
1 parent c5a2dc8 commit da4f888

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

tests/bootstrap.php

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

1818

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

2435

2536
function test(\Closure $function): void

0 commit comments

Comments
 (0)