Skip to content

Commit

Permalink
Fix self-tests timings sometimes being zeroed
Browse files Browse the repository at this point in the history
  • Loading branch information
Luc45 committed Dec 13, 2024
1 parent 246126f commit 19214e7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
14 changes: 13 additions & 1 deletion _tests/managed_tests/ParallelOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function processOutputCallback( $out, Process $process ) {
$this->headers[ $taskId ] = $process->getEnv()['qit_task_id'] . "\n";
$this->outputBuffer[ $taskId ] = "";
$this->nonJsonOutput[ $taskId ] = $process->getEnv()['QIT_NON_JSON_OUTPUT'] ?? '';
$this->startTimes[ $taskId ] = microtime( true );
}

if ( empty( $this->nonJsonOutput[ $taskId ] ) && ! empty( $process->getEnv()['QIT_NON_JSON_OUTPUT'] ) ) {
Expand All @@ -50,6 +49,14 @@ public function processOutputCallback( $out, Process $process ) {
$this->updateProcessStatus( $process, $out );
}

public function registerStartTime( Process $process ) {
$taskId = $process->getEnv()['qit_task_id'];

if ( ! isset( $this->startTimes[ $taskId ] ) ) {
$this->startTimes[ $taskId ] = microtime( true );
}
}

protected function updateProcessStatus( Process $process, $output ) {
$taskId = $process->getEnv()['qit_task_id'];

Expand All @@ -66,6 +73,11 @@ protected function updateProcessStatus( Process $process, $output ) {
}

protected function formatStatusWithTime( $taskId, $status ) {
// If the start time for this task isn't set, default to zero.
if ( ! isset( $this->startTimes[ $taskId ] ) ) {
return "[0:00] $taskId $status";
}

$elapsed = max( 0, intval( microtime( true ) - $this->startTimes[ $taskId ] ) );
$minutes = floor( $elapsed / 60 );
$seconds = str_pad( (int) ceil( $elapsed % 60 ), 2, '0', STR_PAD_LEFT );
Expand Down
3 changes: 1 addition & 2 deletions _tests/managed_tests/QITSelfTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,10 +444,9 @@ function run_test_runs( array $test_runs, $tests_based_on_custom_tests ) {
];

$qit_process->setEnv( $env );

add_task_id_to_process( $qit_process, $t );

$qit_run_processes[] = $qit_process;
$GLOBALS['parallelOutput']->registerStartTime($qit_process);

$t['qit_process'] = $qit_process;
}
Expand Down

0 comments on commit 19214e7

Please sign in to comment.