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

Backingstore-agnostic property tests using model-based testing #4081

Merged
merged 5 commits into from
Dec 16, 2022

Conversation

jorisdral
Copy link
Contributor

@jorisdral jorisdral commented Oct 17, 2022

Description

Resolves #3954.

Previously, the BackingStore functionality was only being tested through higher-level tests like the OnDisk tests. This PR introduces QSM property tests that exercise the BackingStore API directly. The tests can be reused for any type of backing store that implements the BackingStore API. As a result of these tests a bug was identified in the implementation of range reads for the LMDB backing store. This PR also fixes this bug by re-implementing the range reads using a new LMDB cursor monad that is introduced by a PR in the lmdb-simple package: input-output-hk/lmdb-simple#1

Update 2022-12-05

Since the last review round, the tests have been refactored to use quickcheck-lockstep instead of QSM. Furthermore, the LMDB and InMem backing store have seen some refactoring as well. Changes include:

  1. For both backing store implementations, we improved their behaviour in case of errors.
  2. The LMDB backing store now uses the cursor API to perform range reads.
  3. Communication between the LMDB backing store and LMDB bindings now runs through the LMDB.Bridge module.
  4. We created an alternative to the Transaction type from the LMDB bindings that keeps open a transaction handle for as long as we need it to.

Checklist

  • Branch
    • Commit sequence broadly makes sense
    • Commits have useful messages
    • New tests are added if needed and existing tests are updated
    • If this branch changes Consensus and has any consequences for downstream repositories or end users, said changes must be documented in interface-CHANGELOG.md
    • If this branch changes Network and has any consequences for downstream repositories or end users, said changes must be documented in interface-CHANGELOG.md
    • If serialization changes, user-facing consequences (e.g. replay from genesis) are confirmed to be intentional.
  • Pull Request
    • Self-reviewed the diff
    • Useful pull request description at least containing the following information:
      • What does this PR change?
      • Why these changes were needed?
      • How does this affect downstream repositories and/or end-users?
      • Which ticket does this PR close (if any)? If it does, is it linked?
    • Reviewer requested

@jorisdral jorisdral added consensus issues related to ouroboros-consensus testing UTxO-HD 📒💽 labels Oct 17, 2022
@jorisdral jorisdral self-assigned this Oct 17, 2022
@jorisdral jorisdral force-pushed the jdral/3954-backingstore-property-tests branch 4 times, most recently from d1f7807 to 1fd7c60 Compare October 18, 2022 11:02
cabal.project Outdated Show resolved Hide resolved
@jorisdral jorisdral marked this pull request as ready for review October 18, 2022 11:10
@jorisdral jorisdral requested review from jasagredo and dnadales and removed request for dnadales, coot, nfrisby and bolt12 October 18, 2022 11:11
Copy link
Member

@dnadales dnadales left a comment

Choose a reason for hiding this comment

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

Thank you for adding this test 🙏 Looks great, I left some comments and to merge this I think we should:

  • Address the FIXMEs.
  • Perform coverage testing to make sure we're covering important test cases.

@jorisdral jorisdral force-pushed the jdral/3954-backingstore-property-tests branch 3 times, most recently from 24a9462 to 0560d73 Compare November 15, 2022 10:44
@jasagredo jasagredo requested review from newhoggy and a team as code owners November 17, 2022 13:19
@jorisdral jorisdral removed request for newhoggy and a team November 17, 2022 13:25
@jorisdral
Copy link
Contributor Author

jorisdral commented Dec 5, 2022

The PR is ready for a second review round. See the update Description of this PR for some info on the major changes that this PR makes.

@jorisdral jorisdral requested review from dnadales and jasagredo and removed request for jasagredo December 5, 2022 13:14
@jorisdral jorisdral force-pushed the jdral/3954-backingstore-property-tests branch from 4758336 to 9bda2bc Compare December 5, 2022 15:37
Copy link
Member

@dnadales dnadales left a comment

Choose a reason for hiding this comment

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

We should decide which of the remaining TODOs in the code we should address.

Copy link
Contributor

@jasagredo jasagredo left a comment

Choose a reason for hiding this comment

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

I think it looks good, I do have some comments here and there

@jorisdral jorisdral force-pushed the jdral/3954-backingstore-property-tests branch 3 times, most recently from 1f1ab01 to 2666381 Compare December 15, 2022 13:58
@ghost
Copy link

ghost commented Dec 16, 2022

There's no 0.2.1 version of quickcheck-dynamic that's going to be released, the next version will be 3.0.0 because it's a breaking change from 2.0.0 which is the latest published on hackage.

@ghost
Copy link

ghost commented Dec 16, 2022

Also, I am not too sure what quickcheck-lockstep adds on top of quickcheck-dynamic that could not be written simply using postcondition

@jorisdral jorisdral force-pushed the jdral/3954-backingstore-property-tests branch from 2666381 to 4a439ca Compare December 16, 2022 11:17
* Added an `LMDB.Bridge` module that "bridges the gap" between the
  `Serialise`-based interface of `lmdb-simple`, and the `CodecMK`-based
  interface that we use throughout consensus. I moved some of the
  relevant definitions from the `LMDB` module to this `LMDB.Bridge`
  module.
* Added an `LMDB.PersistentTransaction` module that keeps an internal
  LMDB transaction handle open, such that we can submit regular
  transactions to the same consistent view. This replaces the
  `ValueHandle` that was originally in the `LMDB` module.
* Refactored range reads to use the new cursor API. This solves the bug
  where range reads previously were returning incorrect results.
* Ensured that the LMDB backing store behaves according to the backing
  store specification in case the backing store or its value handles
  have been closed.
Ensured that the InMemory backing store behaves according to the backing
store specification in case the backing store or any of its handles has
been closed.
* Generalise `ioHasFS` to `MonadIO`.
* Give a general `Show` instance `ApplyMapKind'`.
About the new modules:
* `Registry.hs` defines a small utility for handling a resource through
  handles. This simplifies the property tests we define in other
  modules.
* `Mock.hs` defines a mocked version of a `BackingStore` that
  generalises over the types keys, values and diffs we want to use.
* `LockStep.hs` instantiates the Lockstep framework.
* `BackingStore.hs` sets up and runs the Lockstep tests.

Other changes:
* Added a utility module that defines a simple `LedgerState` and
  corresponding `TableStuff` instance.
@jorisdral jorisdral force-pushed the jdral/3954-backingstore-property-tests branch from 4a439ca to 7749863 Compare December 16, 2022 11:24
@jorisdral
Copy link
Contributor Author

There's no 0.2.1 version of quickcheck-dynamic that's going to be released, the next version will be 3.0.0 because it's a breaking change from 2.0.0 which is the latest published on hackage.

Thank you for pointing this out, I've amended this in the code and the corresponding GH issue

@jorisdral jorisdral force-pushed the jdral/3954-backingstore-property-tests branch from 7749863 to f5577ad Compare December 16, 2022 13:14
@jorisdral jorisdral merged commit e677a41 into feature/utxo-hd Dec 16, 2022
@iohk-bors iohk-bors bot deleted the jdral/3954-backingstore-property-tests branch December 16, 2022 15:39
@edsko
Copy link
Contributor

edsko commented Jan 2, 2023

Also, I am not too sure what quickcheck-lockstep adds on top of quickcheck-dynamic that could not be written simply using postcondition

I don't really understand this sentiment. Sure, of course, technically speaking it's true that quickcheck-lockstep just "gives you a postcondition", but only in the same way that quickcheck-dynamic "just gives you a property". The quickcheck-dynamic library gives you event generation, shrinking, variable management, etc., but it gives you no infrastructure for determining if the responses from the system under test are correct or not. In order to know that, typically you need some kind of model; management of that model is what quickcheck-lockstep gives you. Of course, quickcheck-lockstep is less general than quickcheck-dynamic, advocating a specific style of testing; but for that style of testing, it keeps track of the model state, it gives you variable management for model responses (just like quickcheck-dynamic gives you variable management for the system under test), etc. It also gives you a more expressive variable, which support some kind of fmap-like structure. This is extremely useful when you have actions that can fail and therefore return something of type, say, Either Error a, but you want to refer to the result of such an action in later actions -- but not to any error results.

@ghost
Copy link

ghost commented Jan 3, 2023

@edsko I was expressing my sentiment in the context of those tests, not in general. I failed to see the added value in this particular case because it seemed to me the checks could have been equally well, and perhaps more simply (ie. without an additional conceptual layer added), expressed with qc-d. I may be wrong of course.

jasagredo pushed a commit that referenced this pull request Jan 18, 2023
…-property-tests

Backingstore-agnostic property tests using model-based testing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
consensus issues related to ouroboros-consensus testing UTxO-HD 📒💽
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create property tests for the BackingStore type that are implementation-agnostic
4 participants