forked from woocommerce/woocommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request woocommerce#26878 from woocommerce/fix/26787
Moved synchronous webhook execution into a shutdown function
- Loading branch information
Showing
2 changed files
with
50 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -238,6 +238,29 @@ public function test_woocommerce_webhook_is_delivered_only_once() { | |
remove_action( 'woocommerce_webhook_process_delivery', array( $this, 'woocommerce_webhook_process_delivery' ), 1, 2 ); | ||
} | ||
|
||
/** | ||
* Verify that a webhook is queued when intended to be delivered synchronously. This allows us to then execute them | ||
* all in a `register_shutdown_function` after the request has processed. Since async jobs are handled in | ||
* this way, we can be more confident that it is consistent. | ||
*/ | ||
public function test_woocommerce_webhook_synchronous_is_queued() { | ||
add_filter( 'woocommerce_webhook_deliver_async', '__return_false' ); | ||
$webhook = wc_get_webhook( $this->create_webhook( 'customer.created' )->get_id() ); | ||
wc_load_webhooks( 'active' ); | ||
add_action( 'woocommerce_webhook_process_delivery', array( $this, 'woocommerce_webhook_process_delivery' ), 1, 2 ); | ||
$customer = WC_Helper_Customer::create_customer( 'test1', 'pw1', '[email protected]' ); | ||
|
||
global $wc_queued_sync_webhooks; | ||
$this->assertCount( 1, $wc_queued_sync_webhooks ); | ||
$this->assertEquals( $webhook->get_id(), $wc_queued_sync_webhooks[0]['webhook']->get_id() ); | ||
$this->assertEquals( $customer->get_id(), $wc_queued_sync_webhooks[0]['arg'] ); | ||
|
||
$wc_queued_sync_webhooks = null; | ||
remove_filter( 'woocommerce_webhook_deliver_async', '__return_false' ); | ||
$webhook->delete( true ); | ||
$customer->delete( true ); | ||
} | ||
|
||
/** | ||
* Helper function to keep track of which webhook (and corresponding arg) has been delivered | ||
* within the current request. | ||
|