Skip to content

Commit

Permalink
Add unit tests for the has_pending_actions_due method
Browse files Browse the repository at this point in the history
In #1077 we're making some performance improvements to the
`has_pending_actions_due` method, but there are no unit tests to
protect against regressions, so this is simply adding some. Because
the tests are in the abstract class, they will get run for each
data store type.
  • Loading branch information
coreymckrill committed Sep 5, 2024
1 parent 1896af8 commit e6eadd1
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/phpunit/jobstore/AbstractStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use ActionScheduler_Action;
use ActionScheduler_Callbacks;
use ActionScheduler_IntervalSchedule;
use ActionScheduler_Mocker;
use ActionScheduler_SimpleSchedule;
use ActionScheduler_Store;
use ActionScheduler_UnitTestCase;
Expand Down Expand Up @@ -115,4 +116,49 @@ public function test_query_actions_by_array_status() {

/* End tests for \ActionScheduler_Store::query_actions() */

/**
* The `has_pending_actions_due` method should return a boolean value depending on whether there are
* pending actions.
*
* @return void
*/
public function test_has_pending_actions_due() {
$store = $this->get_store();
$runner = ActionScheduler_Mocker::get_queue_runner( $store );

for ( $i = - 3; $i <= 3; $i ++ ) {
// Some past actions, some future actions.
$time = as_get_datetime_object( $i . ' hours' );
$schedule = new ActionScheduler_SimpleSchedule( $time );
$action = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, [ $i ], $schedule, 'my_group' );

$store->save_action( $action );
}

$this->assertTrue( $store->has_pending_actions_due() );

$runner->run();

$this->assertFalse( $store->has_pending_actions_due() );
}

/**
* The `has_pending_actions_due` method should return false when all pending actions are in the future.
*
* @return void
*/
public function test_has_pending_actions_due_only_future_actions() {
$store = $this->get_store();

for ( $i = 1; $i <= 3; $i ++ ) {
// Only future actions.
$time = as_get_datetime_object( $i . ' hours' );
$schedule = new ActionScheduler_SimpleSchedule( $time );
$action = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, [ $i ], $schedule, 'my_group' );

$store->save_action( $action );
}

$this->assertFalse( $store->has_pending_actions_due() );
}
}

0 comments on commit e6eadd1

Please sign in to comment.