Test help queue runner - run until no more jobs remain.

This commit is contained in:
Jeff Stieler 2019-08-21 16:39:09 -07:00
parent 8f27a374f1
commit 3cb05f13d3
2 changed files with 6 additions and 30 deletions

View File

@ -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' );

View File

@ -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 );
}
}
}
}