oruborus / harness262

BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Add runtime limit for test cases #30

Open oruborus opened 10 months ago

oruborus commented 10 months ago

Add an option to limit the runtime and mark test cases as timed out (T) after a certain interval

oruborus commented 10 months ago

Snippet for a first cut

// FIXME: Get this value from TestSuiteConfig or cli argument `--timeout`
$timeout = 10;
$start = \time();
$terminated = false;
while (proc_get_status($process)['running']) {
    if (Fiber::getCurrent()) {
        Fiber::suspend();
    }

    if(\time() - $start > $timeout) {
        $terminated = true;
        \proc_terminate($process);
        fclose($pipes[1]);
        fclose($pipes[2]);

        // FIXME: Create this result using `TestResultFactory`
        return new GenericTestResult(TestResultState::Skip, $testCase->path(), [], \time() - $start, new RuntimeException("Skipped for taking longer than {$timeout} seconds."));
    }
}