Skip to content
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

Performance improvement of unit tests: Remove delays and inject dependencies #14822

Open
wants to merge 24 commits into
base: trunk
Choose a base branch
from

Conversation

staskus
Copy link
Collaborator

@staskus staskus commented Jan 8, 2025

Closes: #11228
Context: pdfdoF-64g-p2#comment-7238

Description

This is a continuation of #14802 to investigate the reasons of slow unit tests and look for solutions.

I haven't found more all-encompassing widely applied solutions. Therefore this PR has a moderate average speed execution improvement from around 50ms to 40ms..

Jetpack Setup ViewModel Enhancements:

  • Added a new property delayBeforeRetry to the JetpackSetupViewModel and updated its initialization to include this property. This change allows for configurable retry delays during Jetpack setup. [1] [2] [3] [4]
  • Updated JetpackSetupViewModelTests to include the new delayBeforeRetry parameter in the test cases. [1] [2] [3] [4] [5] [6]

Push Notification Background Synchronizer Refactoring:

  • Introduced PushNotificationBackgroundSynchronizerProtocol and updated PushNotificationBackgroundSynchronizer to conform to this protocol.
  • Created PushNotificationBackgroundSynchronizerFactory and its corresponding protocol to handle the creation of synchronizer instances.
  • Updated PushNotificationsManager to use the new factory for creating background synchronizers. [1] [2]

Hub Menu ViewModel Enhancements:

  • Refactored HubMenuViewModel to make viewDidAppear, refreshGoogleAdsCampaignCheck, and refreshBlazeEligibilityCheck asynchronous functions. Added a helper extension to handle these asynchronous calls. [1] [2] [3]

Remote Order Synchronizer Enhancements:

  • Added a debounceDuration property to RemoteOrderSynchronizer to allow configurable debounce intervals for sync requests. [1] [2]

Steps to reproduce

Testing information

⚠️ There has been flakiness with ConfigurableBundleProductViewModelTests test_bundleItemViewModels_have_correct_quantity_when_parent_order_item_quantity_is_more_than_one in CI runs that I cannot quite figure out. It runs super-fast locally but slows down significantly on the CI. I will make sure this branch is stable and has a few consecutive successful runs on CI before merging.

Screenshots


  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

Reviewer (or Author, in the case of optional code reviews):

Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement:

  • The PR is small and has a clear, single focus, or a valid explanation is provided in the description. If needed, please request to split it into smaller PRs.
  • Ensure Adequate Unit Test Coverage: The changes are reasonably covered by unit tests or an explanation is provided in the PR description.
  • Manual Testing: The author listed all the tests they ran, including smoke tests when needed (e.g., for refactorings). The reviewer confirmed that the PR works as expected on all devices (phone/tablet) and no regressions are added.

@staskus staskus added status: do not merge Dependent on another PR, ready for review but not ready for merge. status: draft This is a draft, still need more work but can be reviewed and commented if asked. labels Jan 8, 2025
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Jan 8, 2025

WooCommerce iOS📲 You can test the changes from this Pull Request in WooCommerce iOS by scanning the QR code below to install the corresponding build.

App NameWooCommerce iOS WooCommerce iOS
Build Numberpr14822-9d9221c
Version21.4
Bundle IDcom.automattic.alpha.woocommerce
Commit9d9221c
App Center BuildWooCommerce - Prototype Builds #12493
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

Make viewDidAppear of HubMenuViewModel async which allows the tests to avoid timeouts and more importantly isInverted calls to assert that somehow is not called. It improves the speed of the tests dramatically.
@staskus staskus force-pushed the fix/11228-performance-improvement-of-slow-tests-2 branch from eb19e33 to e25dedd Compare January 9, 2025 07:39
@staskus staskus changed the title Fix/11228 performance improvement of slow tests 2 Performance improvement of unit tests: Remove delays and inject dependencies Jan 10, 2025
@staskus staskus force-pushed the fix/11228-performance-improvement-of-slow-tests-2 branch from e1c7e04 to f245506 Compare January 10, 2025 10:58
@staskus staskus force-pushed the fix/11228-performance-improvement-of-slow-tests-2 branch from 152c872 to 9b372f0 Compare January 10, 2025 16:58
@staskus staskus force-pushed the fix/11228-performance-improvement-of-slow-tests-2 branch from c1793ce to ba142d2 Compare January 10, 2025 18:19
@staskus staskus added type: task An internally driven task. category: unit tests Related to unit testing. and removed status: do not merge Dependent on another PR, ready for review but not ready for merge. status: draft This is a draft, still need more work but can be reviewed and commented if asked. labels Jan 10, 2025
@staskus staskus added this to the 21.5 milestone Jan 10, 2025
@staskus staskus marked this pull request as ready for review January 10, 2025 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: unit tests Related to unit testing. type: task An internally driven task.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Unit Tests] Performance improvements for slow tests
2 participants