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

testing with mocked db or store / store functions #1110

Open
jchappelow opened this issue Dec 4, 2024 · 0 comments
Open

testing with mocked db or store / store functions #1110

jchappelow opened this issue Dec 4, 2024 · 0 comments

Comments

@jchappelow
Copy link
Member

jchappelow commented Dec 4, 2024

Presently a number of unit tests rely on a functional postgresql database. This OK for tests that mean to provide a quick test of well-integrated high level types (or are actually testing SQL functionality like the pg package or engine integration tests), but for packages like consensus engine, we need to find an approach that can satisfy the test without the actual DB.

approaches

  • for dependencies that necessitate a SQL DB: (1) if there is a package like voting store or chain meta store that requires a DB instance in its function args, define overrides for these functions, (2) if there is a stateful type that requires a DB instance in its constructor or methods, mock the type to satisfy the interface
  • As our stores need to become more stateful anyway for efficiency reasons, start moving toward types that can be mocked more easily as in (2) above.
  • very hard, mock the sql DB/Tx interfaces. This is hard or even impractical since it tightly couples with consumer because the sql statement is a string that the mock would have to recognize. This is unlikely to be a good approach as a result. Only in some very narrow cases would this be good.

This is less important for the kinds of tests in node_live_test.go where we are actually trying to make a fast integration test within the go test framework. However, even in TestDualNodeMockNet it would be nice to have a way to test the combined node/p2p+CE functionality with two in-memory node instances that don't need postgres. For example, we have an in memory block store (node/store/memstore) but we do not have similar for the types that use postgres.

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

No branches or pull requests

1 participant