New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve remote specifications transient handling and error management #44384
Conversation
b50ab27
to
d824646
Compare
Test Results SummaryCommit SHA: 0ae2595
To view the full API test report, click here. To view the full E2E test report, click here. To view all test reports, visit the WooCommerce Test Reports Dashboard. |
@@ -133,7 +133,8 @@ public function read_specs_from_data_sources() { | |||
$this->merge_specs( $specs_from_data_source, $specs, $url ); | |||
} | |||
|
|||
$specs_group = get_transient( $this->args['transient_name'] ) ?? array(); | |||
$specs_group = get_transient( $this->args['transient_name'] ); | |||
$specs_group = is_array( $specs_group ) ? $specs_group : array(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix PHP 8.1+ Automatic conversion of false to array is deprecated
Hi @adrianduffell, @rjchow, Apart from reviewing the code changes, please make sure to review the testing instructions as well. You can follow this guide to find out what good testing instructions should look like: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies can I change my mind, it seems like the solution is a bit weird since we return $suggestions
in the first attempt, but after that we'll return the defaults for 3 hours 😅
Perhaps instead, could we do this instead?
- When
$suggestions
is empty, replace it with defaults and save for 3 hours - When
$suggestions
is not empty but has errors, save it for 3 hours
} | ||
} | ||
|
||
if ( $has_error ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about moving this code into the catch block? I don't think we need $has_error if it's only used once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally wanted to do that too, but because it's a loop, we might end up calling set_specs_transient
many times. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh my bad 🤦 I did not see the loop.
Co-authored-by: Ilyas Foo <foo.ilyas@gmail.com>
Sure! I will update my PR. |
9b220f7
to
9199e6a
Compare
@ilyasfoo I've made the changes. Could you please review this PR when you get a chance? Thanks. 🙏 I think we could create a parent |
c5b8bee
to
b088329
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, tested well!
Minor comments, pre-approving 🚢
plugins/woocommerce/src/Admin/Features/PaymentGatewaySuggestions/EvaluateSuggestion.php
Show resolved
Hide resolved
$this->assertEquals( count( $stored_transients['en_US'] ), count( DefaultPaymentGateways::get_all() ) ); | ||
|
||
$expires = (int) get_transient( '_transient_timeout_woocommerce_admin_' . PaymentGatewaySuggestionsDataSourcePoller::ID . '_specs' ); | ||
$this->assertTrue( ( $expires - time() ) < 3 * HOUR_IN_SECONDS ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think changing it to <=
might be safer to accommodate for supercomputers running unit tests 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed in 0ae2595. Thanks! 😆
…ns/EvaluateSuggestion.php Co-authored-by: Ilyas Foo <foo.ilyas@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One question and one minor nit - would it be possible to add a test case for the error flow?
@@ -183,7 +197,7 @@ protected static function read_data_source( $url ) { | |||
// phpcs:ignore | |||
$logger->error( print_r( $response, true ), $logger_context ); | |||
|
|||
return []; | |||
return array(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't quite figure out the intent of changing [] for array(), is it a lint issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's a lint issue.
Short array syntax is not allowedPHP_CodeSniffer(Generic.Arrays.DisallowShortArraySyntax.Found)
@rjchow I wanted to add unit tests for that too, but since it's a static method, I can't mock it to return errors. 😞 I've tried different approaches, but none of them seem to work. There are also many discussions on Slack about this, but still couldn't find any solutions. A related issue: |
Submission Review Guidelines:
Changes proposed in this Pull Request:
Closes #44261.
For PaymentGatewaySuggestions and RemoteFreeExtensions,
For WCPayPromotion:
How to test the changes in this Pull Request:
Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:
Testing
Test remote specs still work as expected
If using an existing site, clear transients by running
wp transient delete --all
Ensure WooCommerce > Settings > Advanced > Woo.com >
Display suggestions within WooCommerce
is checkedGo to Setup Wizard,
/wp-admin/admin.php?page=wc-admin&path=/setup-wizard
Click continue
In
the Which one of these best describes you?
step, selectI'm already selling
andI'm selling both online and offline
Select
Australia — Australian Capital Territory
and continueSkip plugin installation
Observe no fatal when loading homescreen
Go to
Tools > WCA Test Helper > Tools
, Runwc_admin_daily
jobEnsure the job is run successfully
Go to
/wp-admin/admin.php?page=wc-admin&task=payments
Confirm it displays the gateways like below
wp transient get timeout_woocommerce_admin_payment_gateway_suggestions_specs
wp transient get timeout_woocommerce_admin_remote_free_extensions_specs
wp transient get timeout_woocommerce_admin_payment_method_promotion_specs
Has errors
Setup:
wp transient delete --all
Display suggestions within WooCommerce
is checkedTools > WCA Test Helper > Tools
, Runwc_admin_daily
job/wp-admin/admin.php?page=wc-admin&task=payments
Airwallex Payments
gateway/wp-admin/admin.php?page=wc-admin&task=marketing
Google Listings & Ads
,Pinterest for WooCommerce
, andTikTok for WooCommerce
in GROW YOUR STOR section.wp transient get woocommerce_admin_payment_gateway_suggestions_specs --format=json
wp transient get timeout_woocommerce_admin_payment_gateway_suggestions_specs
wp transient get woocommerce_admin_remote_free_extensions_specs --format=json
wp transient get timeout_woocommerce_admin_remote_free_extensions_specs
wp transient get woocommerce_admin_payment_method_promotion_specs --format=json
wp transient get timeout_woocommerce_admin_payment_method_promotion_specs
Test
Changelog entry
Significance
Type
Message
Comment