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

Fix slow ApiSharedWallet unit tests #2664

Merged
merged 2 commits into from
May 25, 2021
Merged

Conversation

rvl
Copy link
Contributor

@rvl rvl commented May 24, 2021

Issue Number

Found during ADP-902

Overview

The Cardano.Wallet.Api.Types tests are running very slowly. Also the unit tests were sometimes timing out in CI.

Profiling showed that the Arbitrary instance of ApiSharedWallet was the slowest part.
This change improves the speed of this generator.
Now it is the OpenAPI validation which is the slowest part.

Comments

We may also be able to reduce the size of arbitrary ApiSharedWallet values, so that validation gets faster. Because it's still not especially quick. Something like the instance Arbitrary WalletName change in this PR could probably be applied.

rvl added 2 commits May 24, 2021 12:18
The generators were doing crypto operations - which are really slow
and generally not required for test cases.
It was ignoring the scale parameter and therefore generating
excessively long names.
@rvl rvl self-assigned this May 24, 2021
nameLength <- choose (walletNameMinLength, walletNameMaxLength)
WalletName . T.pack <$> replicateM nameLength arbitraryPrintableChar
len <- Test.QuickCheck.scale (min walletNameMaxLength) $ sized $ \n ->
chooseInt (walletNameMinLength, walletNameMinLength `max` n)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

genMockXPub = fromMaybe impossible . xpubFromBytes . BS.pack <$> genBytes
where
genBytes = vectorOf 64 arbitrary
impossible = error "incorrect length in genMockXPub"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, we can generate here random bytes 💯

Copy link
Contributor

@paweljakubas paweljakubas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great catches!

@paweljakubas
Copy link
Contributor

bors r+

iohk-bors bot added a commit that referenced this pull request May 24, 2021
2664: Fix slow ApiSharedWallet unit tests r=paweljakubas a=rvl

### Issue Number

Found during ADP-902

### Overview

The `Cardano.Wallet.Api.Types` tests are running very slowly. Also the unit tests were sometimes timing out in CI.

Profiling showed that the `Arbitrary` instance of `ApiSharedWallet` was the slowest part.
This change improves the speed of this generator.
Now it is the OpenAPI validation which is the slowest part.

### Comments

We may also be able to reduce the size of arbitrary `ApiSharedWallet` values, so that validation gets faster. Because it's still not especially quick. Something like the `instance Arbitrary WalletName` change in this PR could probably be applied.


Co-authored-by: Rodney Lorrimar <rodney.lorrimar@iohk.io>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented May 24, 2021

Build failed:

Failures:

  src/Test/Integration/Scenario/CLI/Shelley/Wallets.hs:752:9:
  1) CLI Specifications, SHELLEY_CLI_WALLETS, WALLETS_UTXO_02 - Utxo statistics works properly
       expected: ApiUtxoStatistics {total = Quantity {getQuantity = 0}, scale = ApiT {getApiT = Log10}, distribution = fromList [(10,0),(100,0),(1000,0),(10000,0),(100000,0),(1000000,0),(10000000,0),(100000000,0),(1000000000,0),(10000000000,0),(100000000000,0),(1000000000000,0),(10000000000000,0),(100000000000000,0),(1000000000000000,0),(10000000000000000,0),(45000000000000000,0)]}
        but got: ApiUtxoStatistics {total = Quantity {getQuantity = 1562000000}, scale = ApiT {getApiT = Log10}, distribution = fromList [(10,0),(100,0),(1000,0),(10000,0),(100000,0),(1000000,0),(10000000,0),(100000000,3),(1000000000,1),(10000000000,1),(100000000000,0),(1000000000000,0),(10000000000000,0),(100000000000000,0),(1000000000000000,0),(10000000000000000,0),(45000000000000000,0)]}

  To rerun use: --match "/CLI Specifications/SHELLEY_CLI_WALLETS/WALLETS_UTXO_02 - Utxo statistics works properly/"

Randomized with seed 823600705

Finished in 1628.1795 seconds
790 examples, 1 failure, 15 pending
builder for '/nix/store/9lmwmyznbs3vz38bjrg5wxpm646p4b2a-cardano-wallet-test-integration-2021.4.28-check.drv' failed with exit code 1

#2429

@rvl
Copy link
Contributor Author

rvl commented May 25, 2021

bors r+

@iohk-bors
Copy link
Contributor

iohk-bors bot commented May 25, 2021

Build succeeded:

@iohk-bors iohk-bors bot merged commit 667037b into master May 25, 2021
@iohk-bors iohk-bors bot deleted the rvl/adp-902/fix-qc-generators branch May 25, 2021 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants