From 3cb05f13d33364e4e12c925f6eb9a145406ab74f Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Wed, 21 Aug 2019 16:39:09 -0700 Subject: [PATCH] Test help queue runner - run until no more jobs remain. --- .../tests/api/reports-import.php | 14 +----------- .../helpers/class-wc-helper-queue.php | 22 +++++-------------- 2 files changed, 6 insertions(+), 30 deletions(-) diff --git a/plugins/woocommerce-admin/tests/api/reports-import.php b/plugins/woocommerce-admin/tests/api/reports-import.php index 5d36abe9234..c6ff1f5607d 100644 --- a/plugins/woocommerce-admin/tests/api/reports-import.php +++ b/plugins/woocommerce-admin/tests/api/reports-import.php @@ -119,9 +119,6 @@ class WC_Tests_API_Reports_Import extends WC_REST_Unit_Test_Case { $this->assertEquals( 200, $response->get_status() ); $this->assertEquals( 'success', $report['status'] ); - // Run pending thrice to process batch and order. - WC_Helper_Queue::run_all_pending(); - WC_Helper_Queue::run_all_pending(); WC_Helper_Queue::run_all_pending(); $request = new WP_REST_Request( 'GET', '/wc/v4/reports/customers' ); @@ -164,9 +161,6 @@ class WC_Tests_API_Reports_Import extends WC_REST_Unit_Test_Case { $this->assertEquals( 200, $response->get_status() ); $this->assertEquals( 'success', $report['status'] ); - // Run pending thrice to process batch and order. - WC_Helper_Queue::run_all_pending(); - WC_Helper_Queue::run_all_pending(); WC_Helper_Queue::run_all_pending(); $request = new WP_REST_Request( 'GET', '/wc/v4/reports/customers' ); @@ -267,9 +261,6 @@ class WC_Tests_API_Reports_Import extends WC_REST_Unit_Test_Case { $this->assertEquals( 200, $response->get_status() ); $this->assertEquals( 'success', $report['status'] ); - // Run pending three times to process batches and dependent actions. - WC_Helper_Queue::run_all_pending(); - WC_Helper_Queue::run_all_pending(); WC_Helper_Queue::run_all_pending(); // Check that stats have been deleted. @@ -377,10 +368,7 @@ class WC_Tests_API_Reports_Import extends WC_REST_Unit_Test_Case { $this->assertEquals( 0, $report['orders_count'] ); $this->assertEquals( 4, $report['orders_total'] ); - // Run pending thrice to process batch and order. - WC_Helper_Queue::process_pending(); - WC_Helper_Queue::process_pending(); - WC_Helper_Queue::process_pending(); + WC_Helper_Queue::run_all_pending(); // Test import status after processing. $request = new WP_REST_Request( 'GET', $this->endpoint . '/status' ); diff --git a/plugins/woocommerce-admin/tests/framework/helpers/class-wc-helper-queue.php b/plugins/woocommerce-admin/tests/framework/helpers/class-wc-helper-queue.php index 02d9d93bab2..045276a2478 100644 --- a/plugins/woocommerce-admin/tests/framework/helpers/class-wc-helper-queue.php +++ b/plugins/woocommerce-admin/tests/framework/helpers/class-wc-helper-queue.php @@ -34,24 +34,12 @@ class WC_Helper_Queue { * @return void */ public static function run_all_pending() { - $jobs = self::get_all_pending(); - - foreach ( $jobs as $job ) { - $job->execute(); - } - } - - /** - * Run all pending queued actions. - * - * @return void - */ - public static function process_pending() { - $jobs = self::get_all_pending(); - $queue_runner = new ActionScheduler_QueueRunner(); - foreach ( $jobs as $job_id => $job ) { - $queue_runner->process_action( $job_id ); + + while ( $jobs = self::get_all_pending() ) { + foreach ( $jobs as $job_id => $job ) { + $queue_runner->process_action( $job_id ); + } } } }