From bcdf13394a3d2ef71efeb6884d55e36e57c7e079 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Mon, 12 Jan 2009 06:23:57 +0000 Subject: [PATCH] - Patch #329407 by dereine, birdmanx35, hswong3i et al: report running time of simpletests. --- includes/batch.inc | 10 +++++++++- includes/form.inc | 7 +++++-- modules/simpletest/simpletest.module | 4 ++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/includes/batch.inc b/includes/batch.inc index de47da2777d..4010acb3644 100644 --- a/includes/batch.inc +++ b/includes/batch.inc @@ -263,6 +263,8 @@ function _batch_process() { // If we are in progressive mode, break processing after 1 second. if ($batch['progressive'] && timer_read('batch_processing') > 1000) { + // Record elapsed wall clock time. + $current_set['elapsed'] = round((microtime(TRUE) - $current_set['start']) * 1000, 2); break; } } @@ -289,11 +291,16 @@ function _batch_process() { $current = $total - $remaining + $finished; $percentage = $total ? floor($current / $total * 100) : 100; + $elapsed = $current_set['elapsed']; + // Estimate remaining with percentage in floating format. + $estimate = $elapsed * ($total - $current) / $current; $values = array( '@remaining' => $remaining, '@total' => $total, '@current' => floor($current), '@percentage' => $percentage, + '@elapsed' => format_interval($elapsed / 1000), + '@estimate' => format_interval($estimate / 1000), ); $message = strtr($progress_message, $values); if (!empty($message)) { @@ -360,7 +367,8 @@ function _batch_finished() { include_once DRUPAL_ROOT . '/' . $batch_set['file']; } if (function_exists($batch_set['finished'])) { - $batch_set['finished']($batch_set['success'], $batch_set['results'], $batch_set['operations']); + // Format the elapsed time when batch complete. + $batch_set['finished']($batch_set['success'], $batch_set['results'], $batch_set['operations'], format_interval($batch_set['elapsed'] / 1000)); } } } diff --git a/includes/form.inc b/includes/form.inc index c59eacb1087..65ea10f4621 100644 --- a/includes/form.inc +++ b/includes/form.inc @@ -2501,8 +2501,9 @@ function form_clean_id($id = NULL, $flush = FALSE) { * 'init_message': message displayed while the processing is initialized. * Defaults to t('Initializing.'). * 'progress_message': message displayed while processing the batch. - * Available placeholders are @current, @remaining, @total and @percent. - * Defaults to t('Remaining @remaining of @total.'). + * Available placeholders are @current, @remaining, @total, @percentage, + * @estimate and @elapsed. + * Defaults to t('Completed @current of @total.'). * 'error_message': message displayed if an error occurred while processing * the batch. * Defaults to t('An error has occurred.'). @@ -2539,6 +2540,8 @@ function batch_set($batch_definition) { 'sandbox' => array(), 'results' => array(), 'success' => FALSE, + 'start' => microtime(TRUE), + 'elapsed' => 0, ); // Use get_t() to allow batches at install time. $t = get_t(); diff --git a/modules/simpletest/simpletest.module b/modules/simpletest/simpletest.module index bb4daf9c737..783371b549c 100644 --- a/modules/simpletest/simpletest.module +++ b/modules/simpletest/simpletest.module @@ -434,12 +434,12 @@ function _simpletest_batch_operation($test_list_init, $test_id, &$context) { $context['finished'] = 1 - $size / $max; } -function _simpletest_batch_finished($success, $results, $operations) { +function _simpletest_batch_finished($success, $results, $operations, $elapsed) { if (isset($results['test_id'])) { $_SESSION['test_id'] = $results['test_id']; } if ($success) { - drupal_set_message(t('The tests have finished running.')); + drupal_set_message(t('The tests finished in @elapsed.', array('@elapsed' => $elapsed))); } else { drupal_set_message(t('The tests did not successfully finish.'), 'error');