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

blockchain: Add UtxoCache Initialize tests. #2599

Merged
merged 4 commits into from Mar 1, 2021

Conversation

rstaudt2
Copy link
Member

This is rebased on #2591.

This adds additional tests around utxo cache initialization to ensure that it recovers in various scenarios that are hard to simulate or hit with manual testing. The changes are as follows:

  • blockchain: Make InitUtxoCache a UtxoCache method.
    • This changes the InitUtxoCache method on the BlockChain type to a Initialize method on the UtxoCache type instead. This simplifies providing alternative implementations for testing since the Initialize method deals with internal fields of the UtxoCache type.
  • blockchain: Add UtxoCacher interface.
    • This adds a UtxoCacher interface so that alternative utxo cache implementations can be provided. In particular, this will be used to provide a mock implementation for testing in order to more easily simulate various scenarios.
    • In addition to introducing the UtxoCacher interface, this updates BlockChain and UtxoViewpoint to use the interface rather than the concrete type.
  • blockchain: Add UtxoCache Initialize tests.
    • This adds tests for the UtxoCache Initialize method. These tests include recovery scenarios that are particularly hard to simulate to ensure that those code paths are not broken in the future.
    • In order to test recovery scenarios, this introduces a test utxo cache that allows for toggling flushing on and off.
    • Additionally, this adds an ExpectUtxoSetState method to chaingenHarness that allows for easily validating the last flushed block for the utxo set.
  • blockchain: Add TestShutdownUtxoCache tests.

@davecgh davecgh added the test coverage Discussion and pull requests for improving test coverage. label Feb 19, 2021
@davecgh davecgh added this to the 1.7.0 milestone Feb 19, 2021
Copy link
Member

@davecgh davecgh left a comment

Choose a reason for hiding this comment

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

It's great to see more tests around this to ensure it's handling the edge cases properly.

I noticed a few minor things that I've noted inline.

blockchain/utxocache.go Show resolved Hide resolved
blockchain/utxocache.go Outdated Show resolved Hide resolved
blockchain/common_test.go Show resolved Hide resolved
blockchain/utxocache_test.go Show resolved Hide resolved
This changes the InitUtxoCache method on the BlockChain type to a
Initialize method on the UtxoCache type instead.  This simplifies
providing alternative implementations for testing since the Initialize
method deals with internal fields of the UtxoCache type.
This adds a UtxoCacher interface so that alternative utxo cache
implementations can be provided.  In particular, this will be used to
provide a mock implementation for testing in order to more easily
simulate various scenarios.

In addition to introducing the UtxoCacher interface, this updates
BlockChain and UtxoViewpoint to use the interface rather than the
concrete type.
This adds tests for the UtxoCache Initialize method.  These tests
include recovery scenarios that are particularly hard to simulate to
ensure that those code paths are not broken in the future.

In order to test recovery scenarios, this introduces a test utxo cache
that allows for toggling flushing on and off.

Additionally, this adds an ExpectUtxoSetState method to chaingenHarness
that allows for easily validating the last flushed block for the utxo
set.
@davecgh davecgh merged commit d85fabb into decred:master Mar 1, 2021
@rstaudt2 rstaudt2 deleted the utxo-cache-init-tests branch March 13, 2021 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test coverage Discussion and pull requests for improving test coverage.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants