Skip to content

Commit

Permalink
Debugging leaky queue test failure (#503)
Browse files Browse the repository at this point in the history
* Debug message to help with testing

* Fixing one-off issue with tests

* Use the term attribute to save the terms, remove date for leaky tests

* Fix deprecated error
  • Loading branch information
srtfisher committed Mar 2, 2024
1 parent a4a5d66 commit a7a9ce9
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/mantle/application/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
*/
function app( string $abstract = null, array $parameters = [] ) {
if ( empty( $abstract ) ) {
return Application::getInstance();
return Application::get_instance();
}

return Application::getInstance()->make( $abstract, $parameters );
return Application::get_instance()->make( $abstract, $parameters );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static function register_meta( string $meta_key, array $args = [] ): bool
* @return string|null
*/
public static function get_object_type(): ?string {
$parent = get_parent_class();
$parent = get_parent_class( static::class );

if ( Model\Post::class === $parent ) {
return 'post';
Expand Down
13 changes: 3 additions & 10 deletions src/mantle/queue/providers/wordpress/class-provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,10 @@ public function push( mixed $job ): bool {
$object->post_date = Carbon::createFromTimestamp( $delay, wp_timezone() )->toDateTimeString();
}

$object->save();
// Set the queue term for the job.
$object->terms->{static::OBJECT_NAME} = static::get_queue_term_id( $queue );

// TODO: Convert this to a queued term setter like we do with meta.
$object->set_terms(
[
static::OBJECT_NAME => static::get_queue_term_id( $queue ),
]
);

return true;
return $object->save();
}

/**
Expand Down Expand Up @@ -224,7 +218,6 @@ protected function query( string $queue = null ): Post_Query_Builder {
*/
public function in_queue( mixed $job, string $queue = null ): bool {
return Queue_Record::where( 'post_status', Post_Status::PENDING->value )
->whereDate( now()->toDateTimeString(), '>=' )
->whereTerm( static::get_queue_term_id( $queue ), static::OBJECT_NAME )
->whereMeta( Meta_Key::JOB->value, maybe_serialize( $job ) )
->exists();
Expand Down
2 changes: 1 addition & 1 deletion src/mantle/testing/concerns/trait-interacts-with-cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function assertJobQueued( $job, array $args = [], string $queue = null ):

PHPUnit::assertTrue(
$provider->in_queue( $job, $queue ),
"Job [{$job_name}] is not in the queue.",
"Job [{$job_name}] is not in the queue [{$queue}] for " . $provider::class,
);
}

Expand Down
6 changes: 6 additions & 0 deletions tests/Events/EventDispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
* @group events
*/
class EventDispatcherTest extends \Mockery\Adapter\Phpunit\MockeryTestCase {
public function setUp(): void {
parent::setUp();

app()->singleton_if( 'events', fn ( $app ) => new Dispatcher( $app ) );
}

public function testBasicEventExecution() {
unset( $_SERVER['__event.test'] );
$d = new Dispatcher();
Expand Down

0 comments on commit a7a9ce9

Please sign in to comment.