Skip to content

Commit

Permalink
tests: added garbage collector to bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 23, 2018
1 parent c5a2dc8 commit da4f888
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,20 @@


// create temporary directory
define('TEMP_DIR', __DIR__ . '/tmp/' . getmypid());
@mkdir(dirname(TEMP_DIR)); // @ - directory may already exist
Tester\Helpers::purge(TEMP_DIR);
(function () {
define('TEMP_DIR', __DIR__ . '/tmp/' . getmypid());

// garbage collector
$GLOBALS['\\lock'] = $lock = fopen(__DIR__ . '/lock', 'w');
if (rand(0, 100)) {
flock($lock, LOCK_SH);
@mkdir(dirname(TEMP_DIR));
} elseif (flock($lock, LOCK_EX)) {
Tester\Helpers::purge(dirname(TEMP_DIR));
}

@mkdir(TEMP_DIR);
})();


function test(\Closure $function): void
Expand Down

0 comments on commit da4f888

Please sign in to comment.