Skip to content

Commit c8e0c8e

Browse files
committed
tests: added garbage collector to bootstrap
1 parent 845257f commit c8e0c8e

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

tests/bootstrap.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,22 @@
1616

1717

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

2437

0 commit comments

Comments
 (0)